我试图将方形节点定位在弯曲路径的中间,但我注意到我选择的箭头样式会影响定位——如果我使用默认箭头以外的箭头,节点将“偏离中心”定位在路径的法线方向。有没有其他方法可以指定这一点,让节点正确居中,例如使用“latex”样式的箭头?
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[<->,bend angle=90,thick] (-1,-1)
to[bend right]
node[rectangle,sloped,fill=black,minimum size=1mm,inner sep=0pt] {}
(1,0);
\begin{scope}[shift={(2,0)}]
\draw[<->,>=stealth,bend angle=90,thick] (-1,-1) to[bend right]
node[rectangle,sloped,fill=black,minimum size=1mm,inner sep=0pt] {}
(1,0);
\end{scope}
\begin{scope}[shift={(4,0)}]
\draw[<->,>=latex,bend angle=90,thick] (-1,-1) to[bend right]
node[rectangle,sloped,fill=black,minimum size=1mm,inner sep=0pt] {}
(1,0);
\end{scope}
\end{tikzpicture}
\end{document}
答案1
这个问题可以通过使用 TikZ 库来解决bending
。
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{bending}
\tikzset{%
my node/.style={rectangle,sloped,fill=black,minimum size=1mm,inner sep=0pt},
draw my path/.style={draw,bend angle=90,thick,#1},
}
\begin{document}
\begin{tikzpicture}
\draw[draw my path={<->}] (-1,-1) to[bend right] node[my node] {} (1,0);
\begin{scope}[shift={(2,0)}]
\path[draw my path={<->,>=stealth}] (-1,-1) to[bend right] node[my node] {} (1,0);
\end{scope}
\begin{scope}[shift={(4,0)}]
\path[draw my path={<->,>=latex}] (-1,-1) to[bend right] node[my node] {} (1,0);
\end{scope}
\end{tikzpicture}
\end{document}
看来,计算节点位置所用的路径和绘制和添加箭头所用的路径是不同的。我拼凑了以下内容来展示差异:红色是节点路径的颜色。
代码:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
%\usetikzlibrary{bending}
\tikzset{%
my node/.style={rectangle,sloped,fill=black,minimum size=1mm,inner sep=0pt,#1},
draw my path/.style={draw,bend angle=90,thick,#1},
}
\begin{document}
\begin{tikzpicture}
\draw[draw my path={<->}] (-1,-1) to[bend right] node[my node] {} (1,0);
\begin{scope}[shift={(2,0)}]
\path[orange,draw my path,thin] (-1,-1) to[bend right] node[my node] {} (1,0);
\path[draw my path={<->,>=stealth}] (-1,-1) to[bend right] node[my node] {} (1,0);
\end{scope}
\begin{scope}[shift={(4,0)}]
\path[orange,draw my path,thin] (-1,-1) to[bend right] node[my node] {} (1,0);
\path[draw my path={<->,>=latex}] (-1,-1) to[bend right] node[my node] {} (1,0);
\end{scope}
\end{tikzpicture}
\end{document}