# Extra whitespace around tikz-3dplot? How to fix?

Can someone explain me (MWE derived from this 3D Box example):

• Why below MWE produces whitespace on the left in the second picture? This is caused by the 2 set-coords. If you comment them out, the space is gone, but the box does not look the same anymore
• How can I make the coordinates local instead of global? The problem is that they are now directly in the tikzpicture parameters, so I cannot move them inside the tikzpicture environment. Well you can move them inside, but then it does not work anymore (second picture will then looks the same as the first picture).

MWE

\documentclass{article}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\tdplotsetmaincoords{60}{125}
\tdplotsetrotatedcoords{0}{0}{0} %<- rotate around (z,y,z)
\begin{document}
\framebox {
\begin{tikzpicture}[scale=1,tdplot_rotated_coords,
cube/.style={very thick,black},
grid/.style={very thin,gray}]%
\draw[cube,fill=green!10] (0,0,0) -- (0,2,0) -- (2,2,0) -- (2,0,0) -- cycle;%
\end{tikzpicture}
}
\framebox{
% If you comment these 2 lines out the space is gone (but not correctly rotated anymroe)
\tdplotsetmaincoords{35}{125}
\tdplotsetrotatedcoords{0}{0}{0} %<- rotate around (z,y,z)
% ---
\begin{tikzpicture}[scale=1,tdplot_rotated_coords,
cube/.style={very thick,black}]%
\draw[cube,fill=green!10] (0,0,0) -- (0,2,0) -- (2,2,0) -- (2,0,0) -- cycle;%
\end{tikzpicture}
}
\end{document}


Every time you end a line with a { or } you add a space. Alas, tikz-3dplot does this a lot. \tdplotsetmaincoords only only adds 2 spaces, but \tdplotsetrotatedcoords adds a bunch. The tikz parser ignores spaces.

BTW, it seems that tikz does its own garbage collection, so setting global pgfkey values is not that simple.

\documentclass{article}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\tdplotsetmaincoords{60}{125}
\tdplotsetrotatedcoords{0}{0}{0} %<- rotate around (z,y,z)
\begin{document}
\framebox {%
\begin{tikzpicture}[scale=1,tdplot_rotated_coords,
cube/.style={very thick,black},
grid/.style={very thin,gray}]%
\draw[cube,fill=green!10] (0,0,0) -- (0,2,0) -- (2,2,0) -- (2,0,0) -- cycle;%
\end{tikzpicture}%
}%
\framebox{%
\begin{tikzpicture}[scale=1,cube/.style={very thick,black}]%
\tdplotsetmaincoords{35}{125}%
\tdplotsetrotatedcoords{0}{0}{0}%<- rotate around (z,y,z)
\begin{scope} [tdplot_rotated_coords]
\draw[cube,fill=green!10] (0,0,0) -- (0,2,0) -- (2,2,0) -- (2,0,0) -- cycle;%
\end{scope}
\end{tikzpicture}%
}
\end{document}