人们说一张图片胜过千言万语。
TikZ 绘制的箭头像左图一样倾斜,这有什么充分的理由吗? 有没有简单的方法可以得到像右图一样好看、对称的箭头,而无需手动定位箭头尖端?
笔记:右图中的线条与箭头的细尖重叠。这不是故意的,但添加shorten >=2pt
也会扰乱线条的弯曲。
这是生成上述图像(不带标题)的代码。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[>=latex]
\node[draw,circle] at (0,0) (A) {A};
\node[draw,circle] at (1,0) (B) {B};
\draw[->] (A) to[out=45, in=135] (B);
\draw[->] (B) to[out=-135, in=-45] (A);
\draw[help lines] (0.5,0.5) -- (0.5,-0.5);
\end{tikzpicture}
\begin{tikzpicture}[>=latex]
\node[draw,circle] at (0,0) (A) {A};
\node[draw,circle] at (1,0) (B) {B};
\draw (A) to[out=45, in=135] (B); % Draw nice line
\draw[<-] (B.135) -- ++(-0.1,0.066); % Add arrow tip
\draw (A) to[out=-45, in=-135] (B); % Draw nice line
\draw[<-] (A.-45) -- ++(0.1,-0.066); % Add arrow tip
\draw[help lines] (0.5,0.5) -- (0.5,-0.5);
\end{tikzpicture}
\end{document}
答案1
这个选择latex
是个坏主意,因为不可能得到正确的结果。箭头的尺寸太大了。看看你的“好”尝试的结果
\begin{tikzpicture}[>=to]
\node[draw,circle] at (0,0) (A) {A};
\node[draw,circle] at (1,0) (B) {B};
\draw[->] (A) to[out=45, in=135] (B);
\draw[->] (B) to[out=-135, in=-45] (A);
\draw[help lines] (0.5,0.5) -- (0.5,-0.5);
\end{tikzpicture}
在接下来的代码中outer sep=0pt
是必要的
\begin{tikzpicture}[>=to]
\node[draw,circle,outer sep=0pt] at (0,0) (A) {A};
\node[draw,circle,outer sep=0pt] at (1,0) (B) {B};
\draw (A) to[out=45, in=135] (B);
\draw[<-] (B.135) -- ++(-0.001,0.0009);
\draw (A) to[out=-45, in=-135] (B);
\draw[<-] (A.-45) -- ++(0.001,-0.0009);
\end{tikzpicture}
答案2
一个疯狂的想法:
\usetikzlibrary{decorations.markings}
\begin{tikzpicture}[>=latex, decoration={
markings, mark=at position 1.0 with {\arrow{>}}}
]
\node[draw,circle] at (0,0) (A) {A};
\node[draw,circle] at (1,0) (B) {B};
\draw[postaction={decorate}] (A) to[out=45, in=135] (B);
\draw[postaction={decorate}] (B) to[out=-135, in=-45] (A);
\draw[help lines] (0.5,0.5) -- (0.5,-0.5);
\end{tikzpicture}
现在箭头的角度是错误的,但也许这比原来的不对称弧更好。
还要注意,不对称或倾斜的明显程度取决于所用箭头的种类。使用默认箭头时,它看起来很完美。使用stealth
箭头时,问题会出现,但不如使用latex
箭头时那么严重。
更新 如果允许箭头尖端与目标节点稍微重叠,则结果会更好:
\usetikzlibrary{decorations.markings}
\begin{tikzpicture}[>=latex, decoration={
markings, mark=at position 1 with {\draw[->] (-0.01,0) -- (0.07,0);}}
]
\node[draw,circle] at (0,0) (A) {A};
\node[draw,circle] at (1,0) (B) {B};
\draw[postaction={decorate}] (A) to[out=45, in=135] (B);
\draw[postaction={decorate}] (B) to[out=-135, in=-45] (A);
\draw[help lines] (0.5,0.5) -- (0.5,-0.5);
\end{tikzpicture}