TikZ-在两个不同的路径上垂直对齐文本

TikZ-在两个不同的路径上垂直对齐文本

在两个不同路径上垂直对齐文本的最佳方法是什么?

我在每个箭头路径上都放置了文字copper。由于它们所在路径的长度不同,因此pos=0.6需要将文字放置在路径上,使它们不会在垂直方向上相互对齐。

铜文本未对齐

我可以调整第二条路径的定位(例如pos=0.65)来获得更对齐的效果,但是有没有更好的方法来做到这一点?

也许是对齐的铜文?

最小工作示例(MWE)

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, calc}

\begin{document}

\begin{tikzpicture}[
    node distance=.25cm,
    block/.style={draw, rectangle, minimum size=1cm, align=center},
    coord/.style={coordinate}
    ]
    
    % Bounding box
    \node[block, minimum size=5cm, thick] (boundingbox) {};

    % External blocks
    \node[coord, right=of boundingbox.east, xshift=3cm] (originright) {};
    \node[block, above=of originright]  (proc1) {Proc1};
    \node[block, below=of originright]  (proc2) {Proc2};

    % Internal blocks
    \node[block, anchor=south]  (interface) at (boundingbox.south)  {Interface};

    % Arrows
    \draw[->]   (proc1) -- +(-1.5cm,0) |- ($ (interface.east)+(0,0.25cm) $) node[fill=white, font=\tiny, pos=0.6] {copper};
    \draw[->]   (proc2) -- +(-1.0cm,0) |- ($ (interface.east)+(0,-.25cm) $) node[fill=white, font=\tiny, pos=0.6] {copper};

\end{tikzpicture}

\end{document}

答案1

对于边缘标签的水平对齐,您需要将其放置在与目的地相同的距离上,例如right=2cm

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,
                positioning}

\begin{document}
    \begin{tikzpicture}[
node distance =.25cm,
 block/.style = {draw, minimum size=1cm},
    coord/.style={coordinate}
    ]

    % Bounding box
 \node[block, minimum size=5cm, thick] (boundingbox) {};

    % External blocks
\node[coord, right=of boundingbox.east, xshift=3cm] (originright) {};
\node[block, above=of originright]  (proc1) {Proc1};
\node[block, below=of originright]  (proc2) {Proc2};

    % Internal blocks
\node[block, anchor=south]  (interface) at (boundingbox.south)  {Interface};

    % Arrows
\draw[->]   (proc1) -- +(-1.5cm,0) |- ($ (interface.east)+(0,0.25cm) $) node (aux) [fill=white, font=\tiny, right=20mm] {copper};
\draw[->]   (proc2) -- +(-1.0cm,0) |- ($ (interface.east)+(0,-.25cm) $) node[fill=white, font=\tiny, right=20mm] {copper};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容