在最简单的情况下,我有一个正方形,其边应被标记。然后我移动正方形,要么手动向每个点的 x 或 y 坐标添加偏移量,要么使用xshift
和yshift
。只要我指定通过五个点的路径,一切都会正常工作:四个角加上起点,因此再次是第一个角。
如果我cycle
再次使用而不是传递第一个坐标,最后一个标签就会发生非常奇怪的事情。特别是当我重新缩放tikzpicture
...
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
% Not helping: every node/.style={scale=2}
\begin{tikzpicture}[scale=2]
% Works
\draw
(0,0) -- node[left] {A0}
(0,1) -- node[above] {B0}
(1,1) -- node[right] {C0}
(1,0) -- node[below] {D0}
cycle;
% Works
\draw
(2,0) -- node[left] {A2}
(2,1) -- node[above] {B2}
(2+1,1) -- node[right] {C2}
(2+1,0) -- node[below] {D2}
(2,0);
% Does not work (as long as scale!=1)
\draw
(4,0) -- node[left] {A4}
(4,1) -- node[above] {B4}
(4+1,1) -- node[right] {C4}
(4+1,0) -- node[below] {D4}
cycle;
% This works
\draw[yshift=-2cm]
(0,0) -- node[left] {A6}
(0,1) -- node[above] {B6}
(1,1) -- node[right] {C6}
(1,0) -- node[below] {D6}
(0,0);
% Never works (it's really "cycle" that's to blame here)
\draw[yshift=-2cm, xshift=2cm]
(0,0) -- node[left] {A8}
(0,1) -- node[above] {B8}
(1,1) -- node[right] {C8}
(1,0) -- node[below] {D8}
cycle;
\end{tikzpicture}
\end{document}
答案1
使用(current subpath start) -- cycle
有效。(但我不清楚为什么cycle
不行。)
\documentclass[tikz]{standalone}
\begin{document}
% Not helping: every node/.style={scale=2}
\begin{tikzpicture}[scale=2]
% Works
\draw
(0,0) -- node[left] {A0}
(0,1) -- node[above] {B0}
(1,1) -- node[right] {C0}
(1,0) -- node[below] {D0}
cycle;
% Works
\draw
(2,0) -- node[left] {A2}
(2,1) -- node[above] {B2}
(2+1,1) -- node[right] {C2}
(2+1,0) -- node[below] {D2}
(2,0);
% Does not work (as long as scale!=1)
\draw
(4,0) -- node[left] {A4}
(4,1) -- node[above] {B4}
(4+1,1) -- node[right] {C4}
(4+1,0) -- node[below] {D4}
(current subpath start) -- cycle;
% This works
\draw[yshift=-2cm]
(0,0) -- node[left] {A6}
(0,1) -- node[above] {B6}
(1,1) -- node[right] {C6}
(1,0) -- node[below] {D6}
(0,0);
% Never works (it's really "cycle" that's to blame here)
\draw[yshift=-2cm, xshift=2cm]
(0,0) -- node[left] {A8}
(0,1) -- node[above] {B8}
(1,1) -- node[right] {C8}
(1,0) -- node[below] {D8}
(current subpath start)
-- cycle;
\end{tikzpicture}
\end{document}