如何为包含的文件中图形提供短路径?

如何为包含的文件中图形提供短路径?

我正在使用 LaTeX 创建研究日记,其输入文件存储在文件夹 A 中

Diary
   |
   |+ Diary.tex
   |
   |+ January
   |     |
   |     |+ January.tex 
   |     |
   |     |+ Figures
   |          |
   |          |+ Figure_A1.pdf
   |          |
   |          |+ Figure_A2.pdf
   |
   |+ February
   |     |
   |     |+ February.tex 
   |     |
   |     |+ Figures
   |          |
   |          |+ Figure_B1.pdf
   |          |
   |          |+ Figure_B2.pdf
   |
   |+ March
        |
        |+ March.tex 
        |
        |+ Figures
              |
              |+ Figure_C1.pdf
              |
              |+ Figure_C2.pdf

目前我将一月、二月、三月的文件作为输入文件放在 Diary.tex 中,如下所示:

日记.tex

\documentclass[15pt,a4paper]{book}
\usepackage{lipsum}
\usepackage{url}
\usepackage[nochapters]{classicthesis}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{color}
\usepackage{tabularx}
\usepackage[left=1.5in,right=1in,top=1in,bottom=1in]{geometry}


\begin{document}
    \title{\rmfamily\normalfont\spacedallcaps{Research diary}}
    \author{\spacedlowsmallcaps{nxkr}}
    \date{} % no date
    \clearpage\maketitle
    \thispagestyle{empty}
    \include{./January/January}
    \include{./February/February}   
    \include{./March/March}
\pagebreak
\bibliographystyle{unsrt}
\bibliography{References}
\end{document}

一月.tex

\section*{January}
\begin{figure}
\begin{center}
\includegraphics[scale=1]{./January/Figures/Figure_A1.pdf}
\caption{OFigure_A1}
\end{center}
\label{fig:figure_A1}
\end{figure}
\begin{figure}
\begin{center}
\includegraphics[scale=1]{./January/Figures/Figure_A2.pdf}
\caption{OFigure_A2}
\end{center}
\label{fig:figure_A2}
\end{figure}

二月.tex

\section*{February}
\begin{figure}
\begin{center}
\includegraphics[scale=1]{./February/Figures/Figure_B1.pdf}
\caption{OFigure_B1}
\end{center}
\label{fig:figure_B1}
\end{figure}
\begin{figure}
\begin{center}
\includegraphics[scale=1]{./February/Figures/Figure_B2.pdf}
\caption{OFigure_B2}
\end{center}
\label{fig:figure_B2}
\end{figure}

三月.tex

\section*{March}
\begin{figure}
\begin{center}
\includegraphics[scale=1]{./March/Figures/Figure_C1.pdf}
\caption{OFigure_A1}
\end{center}
\label{fig:figure_C1}
\end{figure}
\begin{figure}
\begin{center}
\includegraphics[scale=1]{./March/Figures/Figure_C2.pdf}
\caption{OFigure_C2}
\end{center}
\label{fig:figure_C2}
\end{figure}

我是否必须提供图形文件的完整路径目录,例如:

./January/Figures/Figure_A1.pdf
./January/Figures/Figure_A2.pdf

有什么方法可以只提供子目录路径,例如:

./Figures/Figure_A1.pdf
./Figures/Figure_A2.pdf

答案1

是的,有一种方法,在加载graphicx包后,我们使用\graphicspath命令来扩展可搜索路径及其搜索顺序(TeX 引擎从顶部到底部文件夹)。

在你将其他三个 TeX 文件中的标题下划线更改为\_并删除这些子文件夹后,这个主 TeX 文件应该可以正常工作(已使用pdflatexxelatex和测试lualatex):

\documentclass[15pt,a4paper]{book}
\usepackage{lipsum}
\usepackage{url}
\usepackage[nochapters]{classicthesis}
\usepackage{graphicx}
\graphicspath{ 
   {January/Figures/}
   {February/Figures/}
   {March/Figures/}
   }

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{color}
\usepackage{tabularx}
\usepackage[left=1.5in,right=1in,top=1in,bottom=1in]{geometry}

\begin{document}
    \title{\rmfamily\normalfont\spacedallcaps{Research diary}}
    \author{\spacedlowsmallcaps{nxkr}}
    \date{} % no date
    \clearpage\maketitle
    \thispagestyle{empty}
    \include{./January/January}
    \include{./February/February}   
    \include{./March/March}
\pagebreak
\bibliographystyle{unsrt}
\bibliography{References}
\end{document}

文件January.tex

\section*{January}
\begin{figure}
\begin{center}
\includegraphics[scale=1]{Figure_A1.pdf}
\caption{OFigure\_A1}
\end{center}
\label{fig:figure_A1}
\end{figure}
\begin{figure}
\begin{center}
\includegraphics[scale=1]{Figure_A2.pdf}
\caption{OFigure\_A2}
\end{center}
\label{fig:figure_A2}
\end{figure}

文件February.tex

\section*{February}
\begin{figure}
\begin{center}
\includegraphics[scale=1]{Figure_B1.pdf}
\caption{OFigure\_B1}
\end{center}
\label{fig:figure_B1}
\end{figure}
\begin{figure}
\begin{center}
\includegraphics[scale=1]{Figure_B2.pdf}
\caption{OFigure\_B2}
\end{center}
\label{fig:figure_B2}
\end{figure}

文件March.tex

\section*{March}
\begin{figure}
\begin{center}
\includegraphics[scale=1]{Figure_C1.pdf}
\caption{OFigure\_A1}
\end{center}
\label{fig:figure_C1}
\end{figure}
\begin{figure}
\begin{center}
\includegraphics[scale=1]{Figure_C2.pdf}
\caption{OFigure\_C2}
\end{center}
\label{fig:figure_C2}
\end{figure}

答案2

您应该\graphicspath在前言中放置一个命令。在参数中,您可以指示要包含的图形所在的路径。

 \graphicspath{{./Figures/}}

然后您可以在文档中输入,例如,

\includegraphics{Figure_A1.pdf}

相关内容