0

Upon creating some graphs with TikZ, I noticed that the border at one side was much larger than it needed to be. The cause seems to be the \pgfmathsetmacro command:

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

%\pgfmathsetmacro{\a}{0}
%\pgfmathsetmacro{\b}{0}
%\pgfmathsetmacro{\c}{0}
%\pgfmathsetmacro{\d}{0}
%\pgfmathsetmacro{\e}{0}

\begin{tikzpicture}
\draw (0, 0) rectangle (1, 1);
\end{tikzpicture}

\end{document}

Without any defined macros, the output looks like this (Adobe reader background is gray):

Correct border

With each macro, the size increases. With all five macros defined, it looks like this:

Wrong border

How can this behaviour be explained? Am I using the \pgfmathsetmacro in a wrong way? I did this a lot in the past and never had such a problem. The following did not help, the border didn't change at all:

\documentclass[border=0pt]{standalone}
Qrrbrbirlbel
  • 119,821
  • 2
    Add % after the \pgfmathsetmacro{\?}{0} lines. If these macros are only for the next tikzpicture put them behind \begin{tikzpicture}. This keeps them local to this picture and you get rid of any white-space problems. – Qrrbrbirlbel Apr 26 '15 at 16:11
  • @Qrrbrbirlbel That was indeed it... and seems like I didn't look for the right keywords. Thanks! What do you mean by "put them behind \begin{tikzpicture}"? Is it possible to assign them similar to the parameters in [] ? Or should I just avoid newlines? – Brokenmind Apr 26 '15 at 16:17
  • 1
    Yes, just add them after the options of \begin{tikzpicture} or use PGFmath function but can only be used in places which are parsed by PGFmath (most places with-in TikZ). For example: declare function={a=0; b=0; c(\i)=\i^2;}. – Qrrbrbirlbel Apr 26 '15 at 16:20

0 Answers0