我正在尝试交叉引用整个子文件,即不是单个章节/小节,但无法显示不同子文件文档的引用。所有图表/表格/方程式/参考资料均能正常工作。
本质上,我有一个主 Dissertation.tex 文件,其中有多个子文件(Chapter1、Chapter2 等),并且每个子文件又有多个子文件(Intro1、Methods1 等)。
dissertation/
|-- Dissertation.tex
|-- Dissertation.cls
|-- makefile (Dissertation, release, clean)
|-- Release/
| |-- Dissertation.pdf
|-- Chapter1/
| |-- Intro1.tex
| |-- Methods1.tex
| |-- Results1.tex
| |-- Discussion1.tex
| |-- Conclusion1.tex
| |-- Figures/
| | -- Figure1.pdf
| | -- Figure2.pdf
| | -- Figure3.pdf
| |-- bib_files/
| | -- bib1.bib
| |-- makefile (Chapter1, Intro1, Methods1, release, clean, etc.)
| |-- Release/
| |-- | -- Chapter1.pdf
| |-- | -- Intro1.pdf
| |-- | -- Methods1.pdf
|-- Chapter2/
| |-- Intro2.tex
| |-- Methods2.tex
| |-- Results2.tex
| |-- Discussion2.tex
| |-- Conclusion2.tex
| |-- bib_files/
| | -- bib2.bib
| |-- Figures/
| | -- Figure1.pdf
| | -- Figure2.pdf
| | -- Figure3.pdf
| |-- makefile (Chapter2, Intro2, Methods2, release, clean, etc.)
| |-- Release/
| |-- | -- Chapter2.pdf
| |-- | -- Intro2.pdf
| |-- | -- Methods2.pdf
|-- AppendixA/
| |-- AppendixA.tex
| |-- Code/
| | -- code1.py
| | -- code2.m
| | -- code3.cc
| |-- Data/
| | -- Data1.csv
| | -- Data2.csv
| | -- Data3.csv
我正在使用 Linux Makefile 来编译文档,并加入了命令latexmk
来帮助多次编译,以使引用正常工作。
# Linux Makefile to create a final pdf of the project
# Variables
FILE = Dissertation
# PDF LaTeX specific
PDFLATEX = "pdflatex -interaction=nonstopmode -synctex=1 --shell-escape"
# You want latexmk to *always* run, because make does not have all the info.
# Also, include non-file targets in .PHONY so they are run regardless of any
# file of the given name existing.
.PHONY: ${FILE}.pdf all clean
# The first rule in a Makefile is the one executed by default ("make"). It
# should always be the "all" rule, so that "make" and "make all" are identical.
all: ${FILE}.pdf
# CUSTOM BUILD RULES
# In case you didn't know, '$@' is a variable holding the name of the target,
# and '$<' is a variable holding the (first) dependency of a rule.
# "raw2tex" and "dat2tex" are just placeholders for whatever custom steps
# you might have.
%.tex: %.raw
./raw2tex $< > $@
%.tex: %.dat
./dat2tex $< > $@
# MAIN LATEXMK RULE
# -pdf tells latexmk to generate PDF directly (instead of DVI).
# -pdflatex="" tells latexmk to call a specific backend with specific options.
# -use-make tells latexmk to call make for generating missing files.
# -interaction=nonstopmode keeps the pdflatex backend from stopping at a
# missing file reference and interactively asking you for an alternative.
# --shell-escape allows for *minted to run code highlighting
# -f forces latexmk to run until compiling has been complete regardless of
# cross referencing (i.e. it continues to run until references are in the
# correct location)
${FILE}.pdf: ${FILE}.tex
latexmk -pdf -pdflatex=${PDFLATEX} -f -use-make ${FILE}.tex
# Clean up unnecessary files
clean:
latexmk -C
# specific to latexmk
clear:
rm -rf auto *_minted-* *.log *.aux *.synctex.gz *.out *.toc *.run *.bcf *.lof *.lot *.tdo *.run.xml *.pdf *.bbl *.blg
release:
rm -rf Release
mkdir Release
cp *.pdf Release
make clear
make clean
以下是我设置 Chapter2.tex 的方式。
%%% -*-LaTeX-*-
\documentclass[../Dissertation]{subfiles}
\graphicspath{{Chapter2/Figures/}{Figures/}} % Graphics path for images
\addbibresource{bib_files/bibliography.bib} % Chapter 2 references
\begin{document}\label{Chapter2}
% Needs to be capitalized (University Rules)
\chapter{\uppercase{Title}}
\hspace{\parindent}
Experimental data measurement.
\subfile{./Chapter2/0_Abstract}
\subfile{./Chapter2/1_Introduction}
\subfile{./Chapter2/2_Methods}
\subfile{./Chapter2/3_Results}
\subfile{./Chapter2/4_Discussion}
\subfile{./Chapter2/5_Conclusion}
\subfile{./Chapter2/6_Acknowledgment}
% bibliography
\printbibliography[segment=\therefsegment,heading=references]
\end{document}
我尝试label{Chapter2}
在 Chapter2.tex 文件中添加内容,并想通过以下方式在 Chapter4.tex 中引用它……\ref{Chapter2}
但这似乎不起作用。
%%% -*-LaTeX-*-
\documentclass[../Dissertation]{subfiles}
\doublespacing
\graphicspath{{Chapter4/Figures/}{Figures/}} % Graphics path for images
\begin{document}
\section{Methods}\label{Methods_4}
\Lipsum[8]
\subsection{FEA input data}\label{InputData_4}
Using the experimental data from \ref{Chapter2}, the maximum force was determined using ...
\end{document}
谢谢!
答案1
我理解你的问题的方式是,你想引用一个章节而不是(子)文件本身。
您要做的就是将 放置\label{Chapter2}
在 之后\chapter{\uppercase{Title}}
而不是 之后\begin{document}
。