我想自动将文本添加到用创建的水平线的中心|-
,并且我正在努力了解如何在不必指定精确值的情况下做到这一点,这是我的努力right=0.6cm
设置node
:
请问我该如何将failed
水平线对齐到中心?如果这是重复的或极其基础的,我希望您能原谅我,|-
在搜索引擎中搜索相当具有挑战性,我的 TikZ 魔法仍然很基础,我不知道如何在构造中单独定位水平线|-
,如果有重复的建议,我将不胜感激。
梅威瑟:
\documentclass[border=1.414cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\begin{document}
\begin{tikzpicture}
\node[draw] (one) at (0,0) {Random text};
\node[draw] (two) at (0,-1) {Random text};
\node[draw] (three) at (0,-2) {Random text};
\node[draw] (four) at (0,-3) {Random text};
\draw[-stealth] (one.south) -- (two.north);
\foreach \X in {two,three,four}%
{\draw[-stealth,color=red] (\X.east) -- ++ (0.3em, 0) |- ([yshift=.6em]two.north) node[right=0.6cm,above] {\textbf{\tiny failed}};}%
\end{tikzpicture}
\end{document}
答案1
根据@Qrrbrbirlbel 的评论,设置near end
有效:
\documentclass[border=1.414cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\begin{document}
\begin{tikzpicture}
\node[draw] (one) at (0,0) {Random text};
\node[draw] (two) at (0,-1) {Random text};
\node[draw] (three) at (0,-2) {Random text};
\node[draw] (four) at (0,-3) {Random text};
\draw[-stealth] (one.south) -- (two.north);
\foreach \X in {two,three,four}%
{\draw[-stealth,color=red] (\X.east) -- ++ (0.3em, 0) |- ([yshift=.6em]two.north) node[near end,above] {\textbf{\tiny failed}};}%
\end{tikzpicture}
\end{document}