I have extra whitespace to the left of a TikZ image produced in a standalone
environment:
I don't know why this is occurring. I thought perhaps the left projector bounding box, but the right projector is a mirror of the first using \begin{scope}[xscale=-1]
, and it doesn't produce the same whitespace to the right.
I can probably crop this fairly easily, but I'd like to know why it's happening to prevent it in the future.
Comments on my code are welcome; I'm new to TikZ. My working example:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\pgfmathsetmacro{\cubex}{1}
\pgfmathsetmacro{\cubey}{1}
\pgfmathsetmacro{\cubez}{1}
\def\projector[#1:#2:#3] {
% Angle and place the projector
\begin{scope}[rotate around={#1:(#2,#3)}]
% Projector and lens
\draw [red] (#2, #3) rectangle (#2 + 1, #3 + .5);
\draw [red] (#2 + 1, #3 + .175) rectangle (#2 + 1.25, #3 + .325);
% Field-Of-View annotation
\draw ( #2 + 1.25, #3 + .325 ) -- ( #2 + 4, #3 + 2);
\draw ( #2 + 1.25, #3 + .175 ) -- ( #2 + 4, #3 - 1);
\end{scope} }
\begin{tikzpicture}
% Draw a cube.
\draw[fill=blue] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0, 0) -- cycle;
\draw[fill=green] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0, \cubez) -- cycle;
\draw[fill=red] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0, 0) -- cycle;
% Draw a projector.
\projector[-40:-4.5:2]
% Second projector is mirrored
\begin{scope}[xscale=-1]
\projector[-40:-3.5:2]
\end{scope}
\end{tikzpicture}
\end{document}
%
after each of the three\pgfmathsetmacro
statements and at the end of the\end{scope} }
line, the space disappears (or you could move those things before\begin{document}
).standalone
, even if it's a general TeX thing.