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.

I am creating some pictures I want to use within nodes. When I use a \newcommand with an argument, extra space is added and I can't get rid of it.

\documentclass{article}
\usepackage{tikz}
\begin{document}

\newcommand{\foo}[1][3]{
\begin{tikzpicture}
    \foreach \x in {0,1,...,#1}
        \filldraw (\x,0) circle (0.2cm);
\end{tikzpicture}
}

\newcommand{\test}{
\begin{tikzpicture}
    \foreach \x in {0,1,...,3}
        \filldraw (\x,0) circle (0.2cm);
\end{tikzpicture}
}

\begin{tikzpicture}
    \node at(0,0)    [draw, rectangle, inner sep=0] {\foo};
    \node at(0,-0.5) [draw, rectangle, inner sep=0] {\test};
\end{tikzpicture}
\end{document}
share|improve this question
    
I don't know tikz, but most likely it is the ends of lines, put a % at the end of every line in your \newcommand your current definition has 5 space tokens coming from the ends of line. –  David Carlisle Mar 29 '12 at 12:53
add comment

1 Answer

up vote 2 down vote accepted

Remove spurious blank spaces:

\newcommand{\foo}[1][3]{%
\begin{tikzpicture}
    \foreach \x in {0,1,...,#1}
        \filldraw (\x,0) circle (0.2cm);
\end{tikzpicture}%
}

\newcommand{\test}{%
\begin{tikzpicture}
    \foreach \x in {0,1,...,3}
        \filldraw (\x,0) circle (0.2cm);
\end{tikzpicture}%
}
share|improve this answer
    
Awesome! Thanks for the fast reply! –  Markus Grün Mar 29 '12 at 13:12
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.