每次我使用此宏时,它都会向右移动。为什么?
\newcommand*{\addLine}[1]{
\begin{tikzpicture}[overlay, remember picture]
\coordinate (x) at (#1,0);
\draw [open triangle 45-] (0,0) -- (x);
\end{tikzpicture}
}
编辑
好吧,我调整了我的真实宏(我只是为了演示而提供了一个较小的示例),但我仍然有一点差距:
\newcommand*{\AddNote}[4]{%
\begin{tikzpicture}[overlay, remember picture]%
\coordinate (x) at (#2,0);
\coordinate (a) at ($(x)!(#1.north)!($(x)+(0,1)$)$);
\coordinate (b) at ($(a)+(0.5,0)$);
\coordinate (c) at ($(b)+(0,#3)$);
\draw [open triangle 45-] (a) -- (b) -- (c);
\node[right] at (c) {\bf\sffamily\smaller#4};
\end{tikzpicture}%
}
答案1
您的宏引入了虚假空格。请参见为什么宏定义中的行尾%
带有注释字符:
无注释字符:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\newcommand*{\addLine}[1]{% <--- a space is introduced without this %
\begin{tikzpicture}[overlay, remember picture]
\coordinate (x) at (#1,0);
\draw [open triangle 45-] (0,0) -- (x);
\end{tikzpicture}% <--- a space is introduced without this %
}
\begin{document}
\addLine{1}\addLine{1}
\end{document}