2

I think I found a bug, but there might be a reason for it.

So there I was, making some nice figure of a duck on a gray backround in tikz. But as it turned out, I needed the figure to have a different size, and the figure had gotten complicated, and I didn't want to redo all the placements of things. So I thought to myself. Can I not just adjust the size of the figure to the size I want? What a great idea! So I usepackaged the adjustwidth package, and wrote \begin{adjustbox}{width=5cm} ... \end{adjustbox} around my picture:

\documentclass[tikz]{standalone}

\usepackage{graphicx}
\usepackage{duckuments}
\usepackage{adjustbox}

\begin{document}

\begin{adjustbox}{width = 5cm}
\begin{tikzpicture}

    \node[anchor = north east] at (5.5,0) {\includegraphics{example-image-duck}};

\end{tikzpicture}
\end{adjustbox}

\end{document}

Around my tikzpicture, but low and behold, it did not compile!

For many a night, I scratch my brain, did adjustbox not like ducks on gray backrounds? surely that could not be the case (I was also conviced I had adjusted the width of ducks on gray boxes at earlier times). In a desperate attempt to fix the mistake, I moved the use of tikz from the declaration of the standalone documentclass to a regular usepckage statement:

\documentclass{standalone}

\usepackage{graphicx}
\usepackage{duckuments}
\usepackage{adjustbox}
\usepackage{tikz}

\begin{document}

\begin{adjustbox}{width = 5cm}
\begin{tikzpicture}

    \node[anchor = north east] at (5.5,0) {\includegraphics{example-image-duck}};

\end{tikzpicture}
\end{adjustbox}

\end{document}

To my surprise the code compiled! And what came out was a beautiful duck with a blue hat and a green lightsaber on a gray background 5 cm wide, never had my life felt so complete!

enter image description here

My question then is, Why does this fail when I import tikz through the documentclass. Is there times where importing tikz through the standalone documentclass is more benificial than others? what is the proper way to go about this?

For the interested, it also fails if you have tikz imported both in the documentclass and as a usepackage.

Thanks for reading and for your answers ;-)

4
  • 1
    When you use the class option tikz, standalone will output multiple pages, and each page will be the contents of a single tikzpicture environment. So the tikz option does more than just loading a package for you.
    – Skillmon
    Oct 26 '20 at 9:58
  • Thanks, I guess that answers my question ;-) Oct 26 '20 at 10:59
  • It will work if you lose the adjustbox, which tries to create a box 5cm wide and containing nothing. Alternatively, you can use a wrapper (see tex.stackexchange.com/questions/277784/…). To answer your question, avoid the [tikz] option of standalone. Oct 26 '20 at 15:29
  • @JohnKormylo I'm fully aware it will work without the adjustbox, but I need the adjustbox to set the width of the entire figure, The figure I'm actually working on is much more complicated 8-) Oct 26 '20 at 17:06
4

The standalone class has the feature to output multiple pages, in which case you have to specify an environment which should serve as a single page. The option tikz does not only load the TikZ package, but also sets things up for standalone to use the tikzpicture environment for the environment which delimits single pages, hence the environment will get an additional meaning/job.

So the tikz option does more than just loading TikZ, but also changes the tikzpicture environment, which is why you can't use it in any way you want after loading it via the class option.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.