子目錄中的子文件,未找到文件

子目錄中的子文件,未找到文件

我正在與另外兩個人一起使用 Dropbox 作為文件儲存機制編寫一份長文件。我希望每個人都能單獨完成自己的作品。因此我希望能夠單獨編譯每個文檔,以及編譯主文檔。子文件包似乎非常適合這個。

我嘗試遵循模組化文件的範例維基教科書,但它對我不起作用。將建立頂級文檔,但較低層級的文檔將出現文件未找到錯誤。

這是我的設定:

  • 圖片資料夾
  • tex資料夾
  • 主文件
  • 樣式.sty

main.tex 內部:

\documentclass[11pt,letterpaper]{article}
\usepackage{styling} %includes \usepackage{subfiles}
\begin{document}
\maketitle
\tableofcontents
\subfile{./tex/subpiece1}
\end{document}

tex 資料夾中的 subpiece1 內:

\documentclass[../main.tex]{subfiles}
\graphicspath{ {Images/subpiece1/} }

\begin{document}
\section{sectiontitle}
%Images and text
\end{document}

單獨建構子檔案時發生錯誤:../main.tex:4: LaTeX 錯誤: 找不到檔案「styling.sty」。 [^^M]

答案1

當我使用子文件包編譯我的第一個多文件文檔時,我遇到了與您相同的問題。

由於我不是長期乳膠用戶,我不完全理解問題的機制,但我懷疑問題是當您編譯“從屬”文件(在您的情況下為“subpiece1.tex”)時,您的編譯器會搜尋自訂套件與“subpiece1.tex”和其他預設tex 目錄位於同一目錄中。

我設法透過更改 \usepackage{} 命令以包含「主」和「從」.tex 檔案通用的相對路徑來解決該問題。

你需要做什麼:

  1. 在主目錄中新增主文檔的資料夾。即你的主目錄應該有資料夾:主資料夾(包含main.tex),tex資料夾,images資料夾。
  2. 編輯 main.tex 資料夾,以便 \usepackage{} 指令包含「styling.sty」的相對路徑(它應該讀取 \usepackage{../styling},沒有檔案副檔名)
  3. 如果您正確執行了第一步,「styling.sty」將具有與「main.tex」和「subpiece1.tex」相同的相對路徑(兩者的相對路徑是上一個資料夾。這是透過「.. /”中的“../”實現的) \usepackage{} 指令)
  4. 更新所有其他相對檔案路徑,以便它們根據需要進行讀取。

main.tex 現在讀取

\documentclass[11pt,letterpaper]{article}
\usepackage{../styling} %includes \usepackage{subfiles}
\begin{document}
%\maketitle (I just removed these because for the demonstartion i didnt actually need them)
%\tableofcontents
\subfile{../tex/subpiece1}
\end{document}

subpiece1 現在讀取

\documentclass[../master/main.tex]{subfiles}
% again I just removed the graphics path because I have no need for it
\begin{document}
\section{sectiontitle}
%Images and text
\end{document}

我個人更喜歡將 preamble.sty 分組到與 main.tex 相同的資料夾中,但基本想法是相同的。我相信只要“main.tex”和“subpiece1.tex”檔案的相對路徑相同,任何路徑都可以。

我還懷疑有更好/更優雅的方法來解決這個問題,但到目前為止這對我有用。

相關內容