# Bounding box is larger than expected when drawing in 3D

This is a semi-duplicate of this question I think, but the answers provided there don't seem to work for me with 3D pictures.

I'm inputting a tikz picture into a beamer poster, but I think that part of the process is irrelevant, although I can include it if it's not.

My tikz picture looks like this: (spiral.tex)

\documentclass{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{arrows}
\usetikzlibrary{3d}
\tikzset{>=latex}

\begin{document}

\tdplotsetmaincoords{60}{60}
\tdplotsetrotatedcoords{0}{20}{70}

\begin{tikzpicture}[tdplot_rotated_coords,scale=0.5, decoration={coil}]

\draw [decorate, decoration={aspect=0.3, segment length=3.1mm,      amplitude=3mm}, color = red] (0,0) --(2.6,0);
\draw [->, red] (2.6,0)--(2.6,-0.5);

\draw [decorate, decoration={aspect=-0.3, segment length=3.1mm, amplitude=-3mm}, color = blue] (-0.4,-3) -- (2.2,-3);
\draw [->, blue] (2.2, -3)--(2.3, -2.5);

\draw [->] (-0.25, -1.5)--(2.75, -1.5) node[right] {$\bf k$};

\draw[->, ultra thick, red] (4.5, 0.75)--(4.32, -0.5);
\draw[->, ultra thick, blue] (3.75, -3.75)--(3.91, -2.5);

\end{tikzpicture}
\end{document}


If you were to compile that you'd find a large area of whitespace extending off to the edge of the picture. This causes problems when I use

\begin{figure}
\centering
\begin{subfigure}[c]{0.3\textwidth}
\input{Figures/Tikz/spiral.tex}
\end{subfigure}
~
\begin{subfigure}[c]{0.3\textwidth}
\input{Figures/Tikz/another3dtikzpicture.tex} %just an example of what I want to do with the tikz picture
\end{subfigure}
\end{figure}


in my beamer poster.

I tried some of the suggestions in that other question that I linked to but they don't seem to work. I can insert \useasboundingbox (-1, -4) rectangle (5, 1); at the beginning of the picture but it doesn't do anything. I've checked that the box is in the right place by drawing it first.

Also using the command \draw [blue] (current bounding box.south west) rectangle (current bounding box.north east); to find my current bounding box gives me an error: ! Dimension too large.

Are these problems particular to drawing in 3D or particular to my code? Is there anything I can do about it?

Previously I've just compiled my tikz picture as an article and used \includegraphics[clip, trim = l b r t]{spiral.pdf} but that's not very satisfactory.

Thanks.

• Thank you for your question! However, please bear in mind that we don't possess your additional TeX or PDF files. Please include them in the post, use graphics from the mwe package or comment out those lines, I guess. Apr 16, 2014 at 11:22
• @Malipivo I've added a comment for clarification. You shouldn't need the .pdf file, that's just for illustrative purposes Apr 16, 2014 at 13:05
• Superb! I understand, but the codes aren't fully compilable, yet, and it adds additional tasks to be solved by solvers. Please try to manage that somehow on your account not on solvers' part. Apr 16, 2014 at 13:11
• For solvers: I replicated the problem from the first TeX file (TikZ v3). Apr 16, 2014 at 13:15
• @Malipivo I haven't made them compatible at the moment because I think the problem is with the TikZ file itself and not the use of \input in the beamer poster (especially since you've replicated the problem). I put in the stuff about beamer just for some context and to illustrate why the tikz problem is a problem. Cheers. Apr 16, 2014 at 13:21

You can add varwidth option to the standalone class. Add some border if you like.

\documentclass[varwidth,border=5pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{arrows}
\usetikzlibrary{3d}
\tikzset{>=latex}

\begin{document}

\tdplotsetmaincoords{60}{60}
\tdplotsetrotatedcoords{0}{20}{70}

\begin{tikzpicture}[tdplot_rotated_coords,scale=0.5, decoration={coil}]

\draw [decorate, decoration={aspect=0.3, segment length=3.1mm,      amplitude=3mm}, color = red] (0,0) --(2.6,0);
\draw [->, red] (2.6,0)--(2.6,-0.5);

\draw [decorate, decoration={aspect=-0.3, segment length=3.1mm, amplitude=-3mm}, color = blue] (-0.4,-3) -- (2.2,-3);
\draw [->, blue] (2.2, -3)--(2.3, -2.5);

\draw [->] (-0.25, -1.5)--(2.75, -1.5) node[right] {$\bf k$};

\draw[->, ultra thick, red] (4.5, 0.75)--(4.32, -0.5);
\draw[->, ultra thick, blue] (3.75, -3.75)--(3.91, -2.5);

\end{tikzpicture}
\end{document}


As noted by Malipivo, tikz option also works → \documentclass[tikz]{standalone} and remove \usepackage{tikz}.

• tikz option works too. Apr 16, 2014 at 13:42
• @Malipivo You are right. But I prefer varwidth option as I feel that it is more general. Thanks for noting :)
– user11232
Apr 16, 2014 at 13:51
• @Malipivo I have added a line in the answer accordingly. Thanks.
– user11232
Apr 16, 2014 at 13:58
• Aha, brilliant, that worked perfectly. Thanks very much. Apr 16, 2014 at 15:20