垂直 TikZ 箭頭錨定到目標的中心

垂直 TikZ 箭頭錨定到目標的中心

考慮這個例子:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \node[left] at (0,0) (Source) {Source};
    \draw [very thick, ->] (0.15,-0.02) -- (2.5,0.48);
    \node[right] at (2.5,0.5) (Target1) {abcdefgh};
    \node at (Target1) (Target1arrow) {};
    \draw [very thick, ->] (2.35,0.52) -- (0,0.02);
    \node[right] at (2.5,-0.5) (Target2) {abcdefg};
    \node at (Target2) (Target2arrow) {};
    \draw [very thick, ->] (0.15,-0.02) -- (2.5,-0.5);
    \draw [very thick, ->, shorten <= .5ex, shorten >= .5ex] (Target1arrow) -- (Target2arrow);
\end{tikzpicture}
\end{document}

在此輸入影像描述

我知道垂直箭頭從 的中點開始Target1,指向 的中點Target2,但在這種情況下,這兩個目標的長度幾乎相同,如果箭頭是直的,看起來會更好。換句話說,我希望箭頭的起點錨定到 的中心點Target2。我嘗試添加anchor = Target2.base這個箭頭的繪製功能,但沒有效果。

答案1

首先,可以選擇將節點放在另一個節點下方(Pier Paolo 解釋)。

還有(node1 |- node2)垂直畫線的語法。在這種情況下,箭頭的末端寫為(Target1arrow |- Target2arrow.north)

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \node[left] at (0,0) (Source) {Source};
  \draw [very thick, ->] (0.15,-0.02) -- (2.5,0.48);
  \node[right] at (2.5,0.5) (Target1) {abcdefgh};
  \node at (Target1) (Target1arrow) {};
  \draw [very thick, ->] (2.35,0.52) -- (0,0.02);
  \node[right] at (2.5,-0.5) (Target2) {abcdefg};
  \node at (Target2) (Target2arrow) {};
  \draw [very thick, ->] (0.15,-0.02) -- (2.5,-0.5);
  \draw [very thick, ->, shorten <= .5ex, shorten >= .5ex] (Target1arrow) -- (Target1arrow |- Target2arrow.north);
\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容