
我想將 TikZ 圖像包含到我的文件中。我希望它是獨立的,這樣我就不必用它的所有序言來污染我的主要文件。根據standalone
手動的(第 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}