Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Every time I'm using this macro it shifts to the right. Why?

\newcommand*{\addLine}[1]{
    \begin{tikzpicture}[overlay, remember picture]
        \coordinate (x) at (#1,0);
        \draw [open triangle 45-] (0,0) -- (x);
    \end{tikzpicture}
}

Edit

Well, I adapted my real macro (I just provided a smaller example for the sake of demonstration), but I still have a little gap:

    \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}%
    }
share|improve this question
1  
Try \newcommand*{addLine}[1]{% and \end{tikzpicture}%. I'm not sure what packages are required to get your example to compile, so I can't test. Possibly also a % after remember picture]% –  Scott H. Dec 10 '12 at 19:31
add comment

1 Answer

up vote 8 down vote accepted

Your macro is introducing spurious spaces. See Why the end-of-line % in macro definitions

With comment chars:

enter image description here

Without comment chars:

enter image description here

\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}
share|improve this answer
    
I always wondered what's the matter of this :D –  Matthias Dec 10 '12 at 19:55
    
Now you know! They're easy enough to miss, see for example, tex.stackexchange.com/a/86265/14100 –  Scott H. Dec 10 '12 at 19:59
    
Hi Scott: I think there's another problem. Please have a look on my edits. –  Matthias Dec 10 '12 at 20:04
    
I'm super-flashed: I put a % to the end of the macro usage. Now the gap is gone... Is this the correct approach? –  Matthias Dec 10 '12 at 20:11
    
Yes, I believe you are having the same issue in document. –  Scott H. Dec 10 '12 at 20:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.