スタンドアロンの TikZ イメージを含めるときにサブプリアンブルを組み込む方法は?

スタンドアロンの TikZ イメージを含めるときにサブプリアンブルを組み込む方法は?

TikZ画像を文書に含めたいのですが、メイン文書をそのプリアンブルで汚さないように、自己完結型にしたいのです。standaloneマニュアル(p. 22) オプションを使用してこれらのプリアンブルを含めることは可能ですsubpreambles。 しかし、設定するとsubpreambles=trueエラーが発生し、プリアンブルは無視されます。 TikZ コードのプリアンブルを組み込むにはどうすればよいですか?

これは私のメインドキュメントのコードです:

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

これは私の写真のコードです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}

次のようなエラーが発生します:

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.

答え1

次のことを試してください。

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

編集:mytikzシェイプ スタイルを決定するための最新の構文を使用して、ファイルを簡潔に記述します。

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

関連情報