하위 파일 패키지를 사용하는 동안 참조/레이블 지정 문제

하위 파일 패키지를 사용하는 동안 참조/레이블 지정 문제

패키지 와 함께 라벨을 사용하는 데 문제가 있습니다 subfiles. 한 섹션에 글을 쓸 때 다른 섹션(또는 해당 섹션 내의 모든 항목)을 참조하려고 하면 정의되지 않은 레이블 오류가 발생합니다. 나의 main.tex:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\graphicspath{{images/}{../images/}}

\usepackage{subfiles}

\begin{document}
\maketitle

\section{Introduction}
\label{sec:intro}
\subfile{sections/CH1_Introduction}

\section{Theory of Ultrasound Anemometer}
\label{sec:theory}
\subfile{sections/CH2_Theory}

예를 들어, '소개' 섹션 파일에 다음과 같이 작성합니다.

In section \ref{sec:theory} the theory will be discussed ...

정의되지 않은 참조 오류가 발생합니다. 누군가 나를 도와줄 수 있나요? label 명령에 문제가 있습니까? 아니면 내가 뭔가 다른 일을 잘못하고 있는 걸까?

답변1

이는 xr 패키지를 사용하여 수행할 수 있습니다. 다음은 프로젝트 레이아웃에 대해 몇 가지 가정을 하는 MWE입니다. 루트 폴더의 다음 파일 아래에 있습니다 main.tex.

\documentclass{article}
\usepackage{xr}
\usepackage{subfiles}

\begin{document}
\section{Introduction}
\subfile{sections/CH1_Introduction}
\label{sec:intro}

\section{Theory of Ultrasound Anemometer}
\subfile{sections/CH2_Theory}
\label{sec:theory}
\end{document}

그런 다음 이라는 하위 폴더에는 다음 sections이라는 두 개의 추가 tex 파일이 있습니다 CH1_Introduction.

\documentclass[../main.tex]{subfiles}
\externaldocument{../main.tex}

\begin{document}
This is a text written in the introduction file that discusses the rest of the paper. We will discuss the theory of ultrasound traducers in section \ref{sec:theory}.
\end{document}

그리고 CH2_Theory.tex:

\documentclass[../main.tex]{subfiles}
\externaldocument{../main.tex}
\begin{document}
Here we talk about the ultrasound traducers that we said we would discuss in section \ref{sec:intro}. 
\end{document}

main.tex반환보다 컴파일 :

여기에 이미지 설명을 입력하세요

이제 모든 섹션이 기본 문서에서 호출된다고 가정하면 소개에서 섹션(현재 레이아웃의 하위 섹션은 아님)을 인용할 수 있습니다.

관련 정보