1

I want to include a TikZ image into my document. I want it to be self-contained, so that I do not have to pollute my main document with all of its preambles. According to the standalone manual (p. 22) it is possible to include these preambles with the subpreambles option. But when I set subpreambles=true I get an error and the preambles are ignored anyway. How can I incorporate the preambles of the TikZ code?

This is the code of my main document:

\documentclass{book}
\usepackage{tikz}
\usepackage{standalone}
\begin{document}
Text ...
\begin{figure}
    \includestandalone[subpreambles=true]{mytikz}
    \caption{My TikZ picture}
    \label{fig:tikz:my}
\end{figure}
\end{document}

This is the code of my picture mytikz.tex:

\documentclass[tikz]{standalone}
\usepackage{tikz}
\tikzstyle{object_representation} = [
    align = center,
    draw = black,
    fill = white,
    minimum width = 2cm,
    minimum height = 2cm,
    rectangle,
    rounded corners,
]
\begin{document}
\begin{tikzpicture}[node distance = 3cm]
    \node (foo) [object_representation] {Foo};
\end{tikzpicture}
\end{document}

This is the error I get:

ABD: EveryShipout initializing macros

Package xkeyval Warning: key `subpreambles' has been disabled on input line 7.

(mytikz.tex

! Package pgfkeys Error: I do not know the key '/tikz/object_representation' an
d I am going to ignore it. Perhaps you misspelled it.

See the pgfkeys package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.18         \node (foo) [object_representation]
                                                 {Foo};
No pages of output.
Transcript written on main.log.
0

1 Answer 1

2

Try the following:

\documentclass{book}
\usepackage{tikz}
\usepackage[subpreambles=true]{standalone} % <--- option should be here

\begin{document}
Text ...
\begin{figure}
    \includestandalone{mytikz}
    \caption{My TikZ picture}
    \label{fig:tikz:my}
\end{figure}
\end{document}

Edit: I would write your mytikz file shortly and with recent syntax for determining of the shape style:

\documentclass[tikz]{standalone}% <-- it is sufficient to has `tikz` only here
\tikzset{object_representation/.style = {% <---
    align = center,
    draw = black,
    fill = white,
    minimum width = 2cm,
    minimum height = 2cm,
    rectangle,
    rounded corners}
        }

\begin{document}
\begin{tikzpicture}
    \node (foo) [object_representation] {Foo};
\end{tikzpicture}
\end{document}
1
  • Thank you very much for catching this!
    – 303
    Commented Aug 4, 2019 at 15:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .