
如果我們的文件在另一個地方,我們如何定義路徑?
我得到了這個,在序言中我們會寫
\usepackage{graphicx}
然後我們將使用上傳圖形
\includegraphics{File.extension}
但是,如果文件位於其他位置,我將如何給出它的路徑,如何將其居中以及如何向其添加文字?
答案1
為了同步我們的思想,讓我們假設:
- 主輸入檔案位於名為
Current
(例如)的資料夾中, - 該資料夾
Current
位於名為 的資料夾中Parent
, diagrams
該資料夾中還有一個名為包含圖表的資料夾Parent
,photos
資料夾中有一個名為包含照片的資料夾Current
。
透過使用,\graphicspath
您可以聲明要在主輸入檔案中引用的照片和圖表的路徑。每個路徑必須包含在 中{}
且必須以 結尾/
。
剩下的應該就清楚了。
\documentclass{article}
\usepackage{graphicx}
\graphicspath{{photos/},{../diagrams/}}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=0.8\linewidth]{filename}% no need to specify the file extension
\caption{Karl's students }
\label{fig:Karlsstudents}
\end{figure}
\end{document}
答案2
一般建議:將所有圖形檔案放在路徑正下方的「圖片」子目錄中。然後您可以使用加載文件
\includegraphics{./pictures/File.extension}
使用點符號,您也可以使用上面的目錄。下面一行將進入上一層目錄(從 TeX 檔案所在的目錄開始),然後進入“myfiles/pictures”目錄並使用“File.extension”
\includegraphics{../myfiles/pictures/File.extension}
我不建議您將 TeX 文件和圖形文件完全分開。將所有內容放在一起使行動文件目錄變得更加容易。
答案3
我正在使用當前的數字設定:
\begin{figure}[htbp]
\centering
\includegraphics[width = 0.8\textwidth]{path/figurefile}
\caption{Somecaption \label{fig:somelabel}}
\end{figure}
也可以\graphicspath{path}
在序言中指定,以便您可以省略path/
in includegraphics
。然後,LaTeX 將figurefile
在 中搜索path
,但不搜索 的子資料夾path
,您必須在 中 指定它們\includegraphics
。