指定路径上节点位置的最佳方法是什么?我找到的方法并不相同,这让我很困扰。
为什么below right
不同于below, right
和right, below
? 为什么below right
不同于below=1pt, right=1pt
和right=1pt, below=1pt
?
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) [out=40, in=150] to node [very near end, sloped, below right] {curve1} (20:6);
\draw (0,0) [out=40, in=150] to node [very near end, sloped, right, below] {curve2} (20:6);
\draw (0,0) [out=40, in=150] to node [very near end, sloped, below, right] {curve3} (20:6);
\end{tikzpicture}
\begin{tikzpicture}
\draw (0,0) [out=40, in=150] to node [very near end, sloped, right=1pt, below=1pt] {curve1} (20:6);
\draw (0,0) [out=40, in=150] to node [very near end, sloped, below=1pt, right=1pt] {curve2} (20:6);
\end{tikzpicture}
\end{document}
答案1
有关定位和锚点的所有内容均在章节中解释17.5 定位节点值得一读。
无论如何,我都会尝试向您提供一些有关此内容的基本想法。
第一个也是最重要的教训是,任何定位命令都会确定要使用的节点的锚点。如果您写入below
,则将放置在此位置下方的将是锚点north
,如果您写入above right
,则所选的锚点将是south east
。(您可以在定位选项后选择其他锚点来更改此行为)
第二课,只有最后一个定位选项仍然存在。如果您写入below, right
(,
它们之间),则right
只会应用。
举个例子:
\draw (0,0) [out=40, in=150] to
node [pos=0, draw, sloped, above left] (al) {above left}
node [pos=0, draw, sloped, below right] {below right}
node [pos=.5, draw, sloped, right, below] (rb) {right, below}
node [pos=1, draw, sloped, below, right] (br) {below, right}
(20:6);
将产生
第三课:当使用positioning
具有明确距离值(如)的新库时,像和above=2mm
这样的表达式会产生不同的结果。above right=2mm
above right=2mm and 2mm
例如,以下代码:
\draw (0,0) [out=40, in=150] to coordinate[pos=.5] (aux)
node [pos=.5, draw, sloped, below right=3pt] {below right}
node [pos=.5, draw, sloped, above left=3pt] {above left}
node [pos=.5, draw, sloped, above right=3pt and 3pt] {above right}
node [pos=.5, draw, sloped, below left=3pt and 7pt] {below left}
(20:6);
生成
当然,前面的链接对一切都有更好的解释。
前面示例的完整代码是
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\draw (0,0) [out=40, in=150] to
node [pos=0, draw, sloped, above left] (al) {above left}
node [pos=0, draw, sloped, below right] {below right}
node [pos=.5, draw, sloped, right, below] (rb) {right, below}
node [pos=1, draw, sloped, below, right] (br) {below, right}
(20:6);
\fill[red] (al.south east) circle(1pt);
\fill[red] (rb.north) circle(1pt);
\fill[red] (br.west) circle(1pt);
\end{tikzpicture}
\begin{tikzpicture}
\draw (0,0) [out=40, in=150] to coordinate[pos=.5] (aux)
node [pos=.5, draw, sloped, below right=3pt] {below right}
node [pos=.5, draw, sloped, above left=3pt] {above left}
node [pos=.5, draw, sloped, above right=3pt and 3pt] {above right}
node [pos=.5, draw, sloped, below left=3pt and 7pt] {below left}
(20:6);
\fill[red] (aux) circle(1pt);
\end{tikzpicture}
\end{document}