对于箭头,我已经尝试过诸如 ->、->>、<-、<<- 之类的选项,但还没有找到一个可以让箭头出现在曲线中心的选项(类似于 ->-)我如何在 TIkz 中做到这一点?
答案1
也许你更喜欢这种语法:
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\tikzset{->-/.style={decoration={
markings,
mark=at position #1 with {\arrow{>}}},postaction={decorate}}}
\begin{tikzpicture}
\draw[->-=.5] (0,0) to [bend left] (2,4);
\draw[->-=.8] (0,0) to [bend right] (2,4);
\end{tikzpicture}
\end{document}
如果你只想要路径中间的箭头,你可以写
\tikzset{->-/.style={decoration={
markings,
mark=at position .5 with {\arrow{>}}},postaction={decorate}}}
你只需要写:
\draw[->-] (0,0) to [bend left] (2,4);
答案2
您可以定义一种新的线条样式并对其进行装饰。(正如 Altermundus 所评论的,并在这个答案)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\tikzset{middlearrow/.style={
decoration={markings,
mark= at position 0.5 with {\arrow{#1}} ,
},
postaction={decorate}
}
}
\begin{tikzpicture}
\draw[middlearrow={<}] (0,0) -- (20:2);
\draw[middlearrow={>}] (0,0) -- (40:2);
\draw[middlearrow={|}] (0,0) -- (60:2);
\draw[middlearrow={stealth reversed}] (0,0) -- (80:2);
\draw[middlearrow={latex}] (0,0) arc (50:-40:-1.5);
\end{tikzpicture}
\end{document}