2

I've created a standalone file containing two tikzpicture environments. If I compile the file by itself, I am seeing two pages generated. So far so good.

\documentclass[tikz]{standalone}
\usetikzlibrary{...}

\begin{document}
\tikzset{...}
\begin{tikzpicture}
  ...
\end{tikzpicture}
\begin{tikzpicture}
  ...
\end{tikzpicture}
\end{document}

Now I want to include only the first or the second one of them in my main document:

\begin{figure}
  \centering
  \includestandalone[page=2]{figures/diagrams}
  \caption{The enhanced diagram}
\end{figure}

Other than expected and documented, the result is both diagrams being printed side-by-side with the second one surpassing the right margin of the page. Any idea what could be the issue?

result

Edit, Solution: Turns out the problem originated out of multiple errors. Maybe this will be a help for others:

  1. @torbjørn-t brought to my attention, that the default mode=tex setting doesn't support the pages option. Be sure to activate one of the other inclusion modes in the main document. I decided to go with:

    \usepackage[mode=build]{standalone}
    
  2. Next issue was, that the cascaded build now yielded the following error: Package standalone Warning: Graphic '...' could not be build. Shell escape activated? Be sure to enable shell escape.

  3. In my case the above wasn't actually related to shell escape but to a build error inside the standalone diagrams document in combination with the fact, that it is located in the subdirectory figures. Turns out the build is executed in a different path and a \include{general_properties} couldn't be resolved correctly. To solve this and similar issues, be sure to check the individual log files next to your standalone file.

4

Haven't used this myself, but the behaviour depends on the mode setting, see the description of \includestandalone in the standalone manual (section 5.3). For example, with

\includestandalone[mode=image,page=2]{filename}

it will include (page 2 of) filename.pdf. With

\includestandalone[mode=build,page=2]{filename}

it will compile filename.tex and include filename.pdf. There is also mode=buildnew which will compile the other file only if it is newer than the PDF, or mode=buildmissing which compiles it only if the PDF isn't there. The default is likely mode=tex, which is similar to \input, so it adds the code directly (sans preamble and document environment).

You can also set the mode as an option to the package, e.g.

\usepackage[mode=buildnew]{standalone}

or use \standaloneconfig, e.g.

\standaloneconfig{mode=buildmissing}

if you want the same setting for all \includestandalones.

  • Hey! Thanks for the quick answer. I knew about those options and immediately played around with them. Sadly none corrects the described behavior. – Mazzen Apr 20 '18 at 13:04
  • @Mazzen Then I'm at a loss, because they worked perfectly fine here. Without mode=image (or one of the builds -- note they require compiling with --shell-escape), I got both pages, but with mode=image I only got the second page. Instead of your second code snippet, could you show a complete, minimal document (from \documentclass to \end{document}, a minimal working example) demonstrating the problem? That might make it possible to work out what's wrong. – Torbjørn T. Apr 20 '18 at 13:36
  • We are getting closer. I've switched over to the build option. My diagrams are included as before but I'm seeing the error message Package standalone Warning: Graphic '...' could not be build. Shell escape activated?. Shell escape is enabled and I was able to test it's function with pdftexcmds. I'll look deeper, seems like my document/the MWE is not the problem. – Mazzen Apr 20 '18 at 14:33
  • Got it working. The error was something completely different and a wild mixture of imperfect details :) I'll add the solution to my OP. Thanks for your input, without it I would probably not have troubleshooted for that long. – Mazzen Apr 20 '18 at 14:51

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.