\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.markings}
\begin{document}
\tikzset{%
tensionarrowreversed/.tip={%
Triangle[length=2.5mm, width=2.5mm, open, reversed]
},
%
%
tensionarrow/.tip={%
Triangle[length=2.5mm, width=2.5mm, open]
},
%
%
string/.style={%
draw, color=blue,
decoration={markings,
mark= at position 0.75 with {\arrow{tensionarrowreversed}}},
postaction={decorate},
decoration={markings,
mark= at position 0.25 with {\arrow{tensionarrow}}},
postaction={decorate}
},
%
}
\begin{tikzpicture}
\draw[string] (0, 0)--(0, 5);
\end{tikzpicture}
\end{document}
在上面的代码中,如何定位标记并在其旁边放置标签?(图像中的标签是手工放置的。)
答案1
您可以使用pos
关键字将节点定位在路径上某段距离的一小部分处。
reversed
还要注意,箭头尖端规范中的 和 使用之间存在差异\arrowreversed
。前者将后端放置在指定位置,后者将尖端放置在指定位置,如下所示。
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.markings}
\begin{document}
\tikzset{%
tensionarrowreversed/.tip={%
Triangle[length=2.5mm, width=2.5mm, open, reversed, red] % note added red
},
%
%
tensionarrow/.tip={%
Triangle[length=2.5mm, width=2.5mm, open]
},
%
%
string/.style={%
draw, color=blue,
decoration={markings, % you can have multiple arrow tips in one decoration
mark=at position 0.25 with {\arrow{tensionarrow}},
mark=at position 0.75 with {\arrowreversed{tensionarrow}}, % added this
mark=at position 0.75 with {\arrow{tensionarrowreversed}}}, % same position as previous, but different arrow tip
postaction={decorate},
},
%
}
\begin{tikzpicture}
\draw[string] (0, 0)--(0, 5) node[right,pos=0.25] {Text} node[right,pos=0.75] {txeT};
\end{tikzpicture}
\end{document}