我有幾個 tikz 人物,其中一些有 400 多行程式碼。這使我在主文件上的工作變得複雜,因為我必須經常滾動所有這些程式碼,所以我想我把它放在一個外部文件中,然後我可以簡單地將其包含在我的主文件中。現在我不知道如何繼續,我看到兩種方法:
- 將每張圖片放入單獨的文件中,編譯為 PDF,包含 PDF 圖形
- 將每張圖片放在單獨的文件中,包含文件,編譯主文檔
哪種方法最好?我到底該怎麼做呢?例如在選項二中,我不知道什麼子文件中需要程式碼:我應該開始定義 a\documentclass
並像它是一個獨立文檔一樣繼續,還是可以將我從主文檔中「剪下」的程式碼放入其中?
那我該怎麼辦?include
?input
?
微量元素
\documentclass{scrreprt}
\usepackage{tikz}
\usepackage{lipsum}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt
\begin{document}
\chapter{Foo}
\lipsum[1]
\begin{figure}[h!]
\centering
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%Shape: Rectangle [id:dp6874714272670446]
\draw (600.5,167) -- (608.5,167) -- (608.5,181.5) -- (600.5,181.5) -- cycle ;
%Shape: Rectangle [id:dp25216565311879857]
\draw (569,127) -- (639,127) -- (639,167) -- (569,167) -- cycle ;
%Shape: Rectangle [id:dp10652138678304235]
\draw (593.5,181.5) -- (614.5,181.5) -- (614.5,188.5) -- (593.5,188.5) -- cycle ;
%Shape: Rectangle [id:dp27982392636707765]
\draw (572.5,130.71) -- (635.5,130.71) -- (635.5,163.29) -- (572.5,163.29) -- cycle ;
%Shape: Rectangle [id:dp29031818189807423]
\draw (572.75,193.2) -- (637.25,193.2) -- (637.25,212.43) -- (572.75,212.43) -- cycle ;
%Shape: Rectangle [id:dp6960940497473749]
\draw (577.35,196.4) -- (581,196.4) -- (581,198.41) -- (577.35,198.41) -- cycle ;
%Shape: Rectangle [id:dp012575111125552318]
\draw (583.35,196.4) -- (587,196.4) -- (587,198.41) -- (583.35,198.41) -- cycle ;
%Shape: Rectangle [id:dp7462575500863122]
\draw (589.35,196.4) -- (593,196.4) -- (593,198.41) -- (589.35,198.41) -- cycle ;
%Shape: Rectangle [id:dp74377024282381]
\draw (595.35,196.4) -- (599,196.4) -- (599,198.41) -- (595.35,198.41) -- cycle ;
%Shape: Rectangle [id:dp5681813434227054]
\draw (577.35,200.41) -- (581,200.41) -- (581,202.41) -- (577.35,202.41) -- cycle ;
%Shape: Rectangle [id:dp45670728197953436]
\draw (583.35,200.41) -- (587,200.41) -- (587,202.41) -- (583.35,202.41) -- cycle ;
%Shape: Rectangle [id:dp4491046180017293]
\draw (589.35,200.41) -- (593,200.41) -- (593,202.41) -- (589.35,202.41) -- cycle ;
%Shape: Rectangle [id:dp6731288033777918]
\draw (595.35,200.41) -- (599,200.41) -- (599,202.41) -- (595.35,202.41) -- cycle ;
%Shape: Rectangle [id:dp7160498396948172]
\draw (601.35,196.4) -- (605,196.4) -- (605,198.41) -- (601.35,198.41) -- cycle ;
%Shape: Rectangle [id:dp13325729640208062]
\draw (607.35,196.4) -- (611,196.4) -- (611,198.41) -- (607.35,198.41) -- cycle ;
%Shape: Rectangle [id:dp2394144125721973]
\draw (601.35,200.41) -- (605,200.41) -- (605,202.41) -- (601.35,202.41) -- cycle ;
%Shape: Rectangle [id:dp19114186601978278]
\draw (607.35,200.41) -- (611,200.41) -- (611,202.41) -- (607.35,202.41) -- cycle ;
%Shape: Rectangle [id:dp6393250197036928]
\draw (616.35,196.4) -- (620,196.4) -- (620,198.41) -- (616.35,198.41) -- cycle ;
%Shape: Rectangle [id:dp5875707462557691]
\draw (616.35,200.41) -- (620,200.41) -- (620,202.41) -- (616.35,202.41) -- cycle ;
%Shape: Rectangle [id:dp2632343129417658]
\draw (622.35,196.4) -- (626,196.4) -- (626,198.41) -- (622.35,198.41) -- cycle ;
%Shape: Rectangle [id:dp16732048982102876]
\draw (628.35,196.4) -- (632,196.4) -- (632,198.41) -- (628.35,198.41) -- cycle ;
%Shape: Rectangle [id:dp994069766161821]
\draw (622.35,200.41) -- (626,200.41) -- (626,202.41) -- (622.35,202.41) -- cycle ;
%Shape: Rectangle [id:dp22742437505582824]
\draw (628.35,200.41) -- (632,200.41) -- (632,202.41) -- (628.35,202.41) -- cycle ;
%Shape: Rectangle [id:dp7394772484697936]
\draw (577.35,204.42) -- (581,204.42) -- (581,206.42) -- (577.35,206.42) -- cycle ;
%Shape: Rectangle [id:dp22090387903101294]
\draw (583.35,204.42) -- (587,204.42) -- (587,206.42) -- (583.35,206.42) -- cycle ;
%Shape: Rectangle [id:dp3094625226147294]
\draw (589.35,204.42) -- (593,204.42) -- (593,206.42) -- (589.35,206.42) -- cycle ;
%Shape: Rectangle [id:dp2693883419330956]
\draw (595.35,204.42) -- (599,204.42) -- (599,206.42) -- (595.35,206.42) -- cycle ;
%Shape: Rectangle [id:dp879541864109227]
\draw (577.35,208.42) -- (581,208.42) -- (581,210.43) -- (577.35,210.43) -- cycle ;
%Shape: Rectangle [id:dp005070405348506002]
\draw (583,208.42) -- (599.35,208.42) -- (599.35,210.43) -- (583,210.43) -- cycle ;
%Shape: Rectangle [id:dp7109131109721036]
\draw (601.35,204.42) -- (605,204.42) -- (605,206.42) -- (601.35,206.42) -- cycle ;
%Shape: Rectangle [id:dp34805202583561967]
\draw (607.35,204.42) -- (611,204.42) -- (611,206.42) -- (607.35,206.42) -- cycle ;
%Shape: Rectangle [id:dp88037563000339]
\draw (601.35,208.42) -- (605,208.42) -- (605,210.43) -- (601.35,210.43) -- cycle ;
%Shape: Rectangle [id:dp199400132263712]
\draw (607.35,208.42) -- (611,208.42) -- (611,210.43) -- (607.35,210.43) -- cycle ;
%Shape: Rectangle [id:dp4342588107618768]
\draw (616.35,208.42) -- (620,208.42) -- (620,210.43) -- (616.35,210.43) -- cycle ;
%Shape: Rectangle [id:dp9519101603214133]
\draw (622.35,204.42) -- (626,204.42) -- (626,206.42) -- (622.35,206.42) -- cycle ;
%Shape: Rectangle [id:dp4542360869287658]
\draw (622.35,208.42) -- (626,208.42) -- (626,210.43) -- (622.35,210.43) -- cycle ;
%Shape: Rectangle [id:dp5417437553938629]
\draw (628.35,208.42) -- (632,208.42) -- (632,210.43) -- (628.35,210.43) -- cycle ;
\end{tikzpicture}
\caption{This is just a part of the total picture.}
\end{figure}
\lipsum[2]
\end{document}
答案1
簡單的回答,你可以兩者都做。然而,仔細觀察,每個人都有自己的優點和缺點。
方法一
%&pdflatex
% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
\documentclass{scrreprt}
\usepackage{tikz}
\usepackage{lipsum}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt
\usetikzlibrary{external}
\tikzexternalize[prefix=tikzexfig/]
\usepackage{standalone}
\begin{document}
\chapter{Foo}
\lipsum[1]
\begin{figure*}[h]
\centering{
\input{ex.tex}
\caption{This is just a part of the total picture.}
\label{f1}
}
\end{figure*}
\lipsum[2]
\end{document}
注意:
tikzexfig
是主目錄中的一個資料夾。更新1:您必須轉義 shell 才能編譯該文件。
ex.tex
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%Shape: Rectangle [id:dp6874714272670446]
\draw (600.5,167) -- (608.5,167) -- (608.5,181.5) -- (600.5,181.5) -- cycle ;
\end{tikzpicture}
優點:
- 由於智慧型快取 pdf 中的圖形,內嵌編譯變得更加容易。
缺點:
當用於出版物時,您肯定必須使用
standalone
package 來單獨編譯它們。將達到記憶體限制 (
pdftex/LaTeX
)。編輯時,必須
pdf's
手動刪除已經產生的。 (我還不知道有更好的替代方案來實現自動化)。我與 @DavidCarlisle 進行了很好的討論,討論瞭如何在其周圍放置一個包裝器,類似於psfrag
.然而,結果卻是慘痛的失敗;-)
。第一次編譯所有數字將需要一些
hell-a-lot
時間。後續編譯速度快得多。
方法2
我不打算討論它,因為它是標準standalone
包實現。
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%Shape: Rectangle [id:dp6874714272670446]
\draw (600.5,167) -- (608.5,167) -- (608.5,181.5) -- (600.5,181.5) -- cycle ;
\end{tikzpicture}
\end{document}
優點:
更容易的類似文件的外部化。
以不同的格式提供您的輸出。有關更多信息,請訪問包文檔。
我們可以在更短的時間內獲取輸出並進行編譯。
缺點:
- 不同的子文件。至少,我還不知道將其包括在方法一。
免責聲明1:我記得在某個地方看到過,
tikzexternal
並且standalone
不應該一起使用。但我不記得為什麼,也不確定它的影響。免責聲明2:對於
pdftex/LaTeX
,記憶體限制是這兩種方法本身的常見問題。