Wie integriere ich Unterpräambeln beim Einbinden eigenständiger TikZ-Bilder?

Wie integriere ich Unterpräambeln beim Einbinden eigenständiger TikZ-Bilder?

Ich möchte ein TikZ-Bild in mein Dokument einfügen. Ich möchte, dass es in sich abgeschlossen ist, damit ich mein Hauptdokument nicht mit all seinen Präambeln verunreinigen muss. Laut derstandaloneHandbuchsubpreambles(S. 22) Es ist möglich, diese Präambeln mit der Option einzubinden . Wenn ich sie jedoch einstelle subpreambles=true, erhalte ich eine Fehlermeldung und die Präambeln werden trotzdem ignoriert. Wie kann ich die Präambeln des TikZ-Codes einbinden?

Dies ist der Code meines Hauptdokuments:

\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}

Dies ist der Code meines Bildes 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}

Dies ist der Fehler, den ich erhalte:

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.

Antwort1

Versuche Folgendes:

\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}

Bearbeiten:mytikzIch würde Ihre Datei kurz und mit aktueller Syntax zur Bestimmung des Formstils schreiben :

\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}

verwandte Informationen