考虑以下
\tikzset{
myline/.style={to path={(\tikztostart) -- (\tikztotarget)}}
}
和
\draw (0,0) edge[myline] (1,1) edge[myline] (2,0);
现在,它似乎\tikztostart
没有在第二个边缘命令上重置,并且仍然是 (0,0)?
更具体地说,在第二次“调用”边缘时,我认为\tikztostart
会有价值(1,1)
,而不是(2,0)
。
例如,是否有其他控制序列\tikztostart
可以使其工作?
请随意指定和编辑问题标题
可运行的示例代码:
\documentclass[tikz,margin=10pt]{standalone}
\usepackage{tikz}
\tikzset{
myline/.style={to path={(\tikztostart) -- (\tikztotarget)}}
}
\begin{document}
\begin{tikzpicture}
% With edges
\begin{scope}[shift={(0,1)}]
\draw (0,0) edge[myline] (1,1) edge[myline] (2,0);
\node[below] at (1,0){With \texttt{edge}s};
\end{scope}
% With --, which gives "expected" results
\begin{scope}[shift={(0,-1)}]
\draw (0,0) -- (1,1) -- (2,0);
\node[below] at (1,0){With \texttt{--} (expected)};
\end{scope}
\end{tikzpicture}
\end{document}
结果:
答案1
此代码由 Hood Chatman 编写允许您获得所需的边缘结果。
\documentclass[tikz,margin=10pt]{standalone}
\usepackage{tikz}
\tikzset{
myline/.style={to path={(\tikztostart) -- (\tikztotarget)}}
}
\begin{document}
\begin{tikzpicture}
% With edges
\begin{scope}[shift={(0,1)},every edge/.append code={%
\global\let\currenttarget\tikztotarget % save \tikztotarget in a global variable
\pgfkeysalso{append after command={(\currenttarget)}}}]
\draw (0,0) edge[myline] (1,1) edge[myline] (2,0);
\node[below] at (1,0){With \texttt{edge}s};
\end{scope}
% With --, which gives "expected" results
\begin{scope}[shift={(0,-1)}]
\draw (0,0) -- (1,1) -- (2,0);
\node[below] at (1,0){With \texttt{--} (expected)};
\end{scope}
\end{tikzpicture}
\end{document}
如果你放大顶部,你会发现它不太一样,
只是因为将路径分成两部分而不是一部分。