
[更新]
如果我的問題不太清楚,我很抱歉。我的意思是如何簡化 main.tex 中語法的編寫以顯示具有相同設定的圖像,
\begin{figure}[ht]
\centering
\includegraphics{Pictures/pic1.png}
\caption{Picture 1}
\label{fig:pic1}
\end{figure}
只寫,也許,
\includegraphics[caption,label]{pic1.png}
[原問題]
我正在寫一本包含一些圖形的電子書。其中一些是由程式碼(使用 TikZ)產生的,例如pic1.tex
.我認為如果將它們保存在單獨的文件中,編輯會更容易。我將所有圖形放入名為“圖片”的資料夾中。我用相同的前綴命名所有圖形pic
,例如 pic2.png、pic3.jpg 等。
如何用最少的程式碼包含它們,例如:
\include{pic1.tex}
比
\begin{figure}[h]
\centering
\includegraphics{Pictures/pic1.tex}
\caption{Picture 1}
\label{fig:pic1}
\end{figure}
答案1
如果您想成為最好的從業者,請考慮以下事項。讓您的文件和資料夾層次結構如下。
main.tex
在Project
。rules.jpg
是在SubDir
.behaviors.jpg
是在ParentSiblingDir
.
% main.tex
\documentclass{article}
\usepackage{graphicx}
\graphicspath{{SubDir/}{../ParentSiblingDir/}}
\newcommand\Insert[5][hbtp]{%
\begin{figure}[#1]
\centering
\includegraphics[#2]{#3}
\caption{#4}
\label{#5}
\end{figure}}
\begin{document}
\Insert{scale=.2}{behaviors}{Students' behaviors}{fig:behaviors}
\Insert{scale=.2}{rules}{Father's rules}{fig:rules}
\end{document}
評論:
用於
\graphicspath
註冊將包含或匯入影像的資料夾(目錄)。格式為\graphicspath{{<relative path1>}{<relative path2>}{<relative path...>}}
.每條路徑都必須遵循/
.剩下的程式碼應該夠清晰了!