> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/ko/document-structure/08-multi-file-latex-projects.md).

# 다중 파일 LaTeX 프로젝트

## 소개

에서 [큰 LaTeX 문서들](/latex/ko/document-structure/07-management-in-a-large-project.md) 보통 여러 개가 있다 `.tex` 파일이 있고, 각 장이나 섹션마다 하나씩 있으며, 그런 다음 하나의 출력물을 생성하기 위해 함께 결합된다. 이렇게 하면 모든 것을 체계적으로 정리하기 쉽고 문서를 디버깅하기도 쉬워지지만, 문서가 커질수록 컴파일 시간은 더 길어진다. 보통은 매번 특정 파일에서만 작업하는 데 관심이 있기 때문에 이는 답답할 수 있다.

이 문제를 극복하는 자연스러운 방법은 각 파일을 별도로 컴파일하는 것이다. 다중 파일 프로젝트에서 단일 파일의 컴파일을 허용하는 주요 패키지 두 가지가 있다. 어떤 것을 선택할지는 필요한 것에 달려 있다.

* 로 [그 **subfiles** 패키지](#the-subfiles-package) subfiles를 사용하면 각 하위 파일을 독립적으로 컴파일할 수 있고, 각 하위 파일은 자동으로 메인 파일의 서문을 사용한다.
* 로 [그 **standalone** 패키지](#the-standalone-package) 각 하위 파일은 독립 파일로 동작하므로, 나중에 모든 하위 파일의 서문을 가져오는 메인 문서에서 함께 합칠 수 있다. 같은 파일을 하나 이상의 문서에서 재사용해야 할 때 특히 유용하며, tikz 그림이 그 좋은 예이다.

## Overleaf .tex 파일의 \documentclass에 대한 참고 사항

다음 비디오 클립에서 보여주듯이, 프로젝트의 메인 `.tex` 파일을 설정해 두었더라도 다른 파일을 컴파일하도록 선택할 수 있다. 단, 그 파일에 `\documentclass` 선언이 포함되어 있어야 한다. 그러나 용어집, 파일 경로 접근 등 프로젝트의 모든 요소가 올바르게 컴파일되도록 하려면 `.bib` 프로젝트 루트 디렉터리에 포함된 파일만 컴파일할 것을 강력히 권장한다.

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/U2nGfRx9NwNGX0vWXNebP/1ca4b9a4b2f36d5ca9c0dbaa87f44bfa/maincompile.mp4>" %}

## subfiles 패키지

이 패키지는 대부분의 상황에 적합하며, 사용하기가 정말 쉽다.

이 섹션의 예제는 다음과 같은 계층적 파일 구조를 갖는다:

![CompileSubfilesEx1OverleafV2.png](/files/5498d42056438f17d7bfb7284795a9910068b5d7)

### 메인 파일

메인 파일에서는 두 개의 특수 명령이 필요하다.

```latex
\documentclass{article}
\usepackage{graphicx}
\graphicspath{{images/}}

\usepackage{blindtext}

\usepackage{subfiles} % 서문에서 가장 마지막에 불러오는 것이 좋음

\title{subfiles 패키지 예제}
\author{Overleaf}
\date{ }

\begin{document}

\maketitle

\section{Introduction}

\subfile{sections/introduction}

\section{Second section}

\subfile{sections/section2}

\end{document}
```

![CompileSubfilesEx1aOverleafV2.png](/files/9cc4a2e1edca0539c1ff7a805e6558d328753b03)

파일별 컴파일에는 다음 줄이 필요하다

```latex
\usepackage{subfiles}
```

서문에 넣으면, 이것이 `subfiles` 패키지를 활성화한다. 그런 다음 각 외부 하위 파일은 명령 `\subfile{}`. 예제에서는 파일 `introduction.tex` 및 `section2.tex` 이 메인 파일로 가져와지며 `sections` 폴더에서 가져온다. 파일 확장자는 필수가 아니다.

[열어보라 `subfiles` 패키지 예제를 Overleaf에서 열기](https://www.overleaf.com/project/new/template/19626?id=66392908\&templateName=Subfiles+package+example\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

### 하위 파일들

메인 파일을 설정한 후에는 각 하위 파일이 특별한 구조를 가져야 한다.

```latex
\documentclass[../main.tex]{subfiles}
\graphicspath{{\subfix{../images/}}}
\begin{document}
\textbf{안녕하세요, 세상!}
\begin{figure}[bh]
\centering
\includegraphics[width=3cm]{overleaf-logo}

\label{fig:img1}
\caption{Overleaf 로고}
\end{figure}

안녕하세요, 의미 없는 텍스트가 있습니다...

\end{document}
```

![CompileSubfilesEx2OverleafV2.png](/files/143209559d6592533635e3ac792fa35635842875)

이제 이 파일은 독립 실행형 파일로 컴파일할 수 있으며, 문서 클래스와 나머지 서문은 메인 문서에서 정의된 것과 동일하다.

여기서 첫 번째 명령은

```latex
\documentclass[../main.tex]{subfiles}
```

대괄호 안의 매개변수 `../main.tex`, 이며 메인 문서로의 상대 경로이다. 이 경우 파일 `introduction.tex` 은 폴더 안에 있다 `sections`, 따라서 파일 `main.tex` 은 현재 폴더보다 한 단계 위에 있다(이것이 `../` 를 의미한다).

또한 다음 항목을 사용해야 한다 `\subfix` 상대 폴더 경로와 함께 명령을 지정할 때 `\graphicspath` 를 `introduction.tex`:

```latex
\graphicspath{{\subfix{../images/}}}
```

그런 다음 실제 내용은 `\begin{document}` 및 `\end{document}`. 이 환경 밖의 모든 것은 무시되며, 더 정확히는 서문의 일부로 간주된다. 파일의 위아래에 빈 줄을 남기지 않도록 하라.

[열어보라 `subfiles` 패키지 예제를 Overleaf에서 열기](https://www.overleaf.com/project/new/template/19626?id=66392908\&templateName=Subfiles+package+example\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## standalone 패키지

패키지 **standalone** 는 **subfiles** 과 동일한 기능을 제공하며 더 유연하지만, 문법은 더 복잡하고 오류가 발생하기 쉽다. 주요 차이점은 각 하위 파일이 자체 서문을 가진다는 것이다.

이 섹션의 예제는 다음과 같은 계층적 파일 구조를 갖는다:

![CompileSubfilesEx3OverleafV2.png](/files/4fdf070141b79ef320b064eb47b91405963404aa)

### 메인 파일

메인 파일은 여러 파일로 이루어진 다른 어떤 프로젝트의 메인 파일과 매우 유사하다.

```latex
\documentclass{article}
\usepackage[subpreambles=true]{standalone}
\usepackage{import}

\title{standalone 패키지 예제}
\author{Overleaf}
\date{2021년 5월}

\begin{document}

\maketitle

\section{First section}
\import{sections/}{introduction}

\section{Second section}
\import{sections/}{section2}

\end{document}
```

![CompileSubfilesEx3Overleaf.png](/files/58f5de05af399e6e945324f7439b05eaf2a421f3)

다음 줄은

```latex
\usepackage[subpreambles=true]{standalone}
```

패키지를 활성화한다 **standalone** 패키지이며, 문서의 초반부에 배치해야 한다. 대괄호 안의 매개변수는 LaTeX에게 각 하위 파일에서 서문을 가져오도록 지시한다(패키지는 한 번만 불러와진다). 이를 생략하면, 하위 파일이 동작하도록 메인 문서의 서문에 필요한 모든 명령이 있는지 확인하라. 서로 다른 서문 간의 호환성 문제 가능성 때문에 주의해야 한다.

메인 문서의 본문에서는 각 하위 파일을 `\import{}{}`. 표준 `\input{}` 명령도 사용할 수 있지만, 이 예제의 것은 [큰 프로젝트를 관리하는 데 권장된다](/latex/ko/document-structure/07-management-in-a-large-project.md) 중첩된 파일에서 오류를 방지하기 때문이다.

[의 예제를 열어보라 `standalone` Overleaf에서 패키지](https://www.overleaf.com/project/new/template/19636?id=66440758\&templateName=Standalone+package+example\&latexEngine=pdflatex\&texImage=\&mainFile=)

### 하위 파일들

각 하위 파일은 자체 서문을 가져야 하며, 독립 실행형 문서로 작동하는 데 필요한 모든 패키지를 가져와야 한다.

```latex
\documentclass[class=article, crop=false]{standalone}
\usepackage[subpreambles=true]{standalone}
\usepackage{import}
\usepackage{blindtext}

\begin{document}
이 줄 아래에 TikZ 그림이 렌더링된다

\begin{figure}[ht]
\centering
\subimport{../}{diagram.tex}
\label{fig:tikzexample}
\caption{아름답고 간단한 다이어그램}
\end{figure}

\blindtext
\end{document}
```

![CompileSubfilesEx4OverleafV2.png](/files/fa994dea657109fccc2a5cf6f47008b3b7bcd964)

하위 파일의 첫 번째 줄은

```latex
\documentclass[class=article, crop=false]{standalone}
```

이 파일이 **standalone** 패키지와 함께 사용될 파일임을 선언한다. 대괄호 안에는 두 개의 선택적 매개변수가 있다.

* `class=article`. 을 설정한다 `article` 를 기본 클래스로 하며, 다른 클래스들도 사용할 수 있다: book, report 등(단, beamer는 제외).
* `crop=false`. 이 옵션을 생략하면 출력은 최소 크기로 잘려 나온다.

다음 명령은 필수는 아니지만

```latex
\usepackage[subpreambles=true]{standalone}
```

여기 중첩된 **standalone** 파일이 있다. 하나의 [tikz 그림은](/latex/ko/figures-and-tables/05-tikz-package.md) 를 사용하여 삽입되며, [`\subimport{../}{diagram.tex}`](/latex/ko/document-structure/07-management-in-a-large-project.md#importing-files)아래에서 "diagram.tex" 파일의 내용을 볼 수 있다:

```latex
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture}[
roundnode/.style={circle, draw=green!60, fill=green!5, very thick, minimum size=7mm},
squarednode/.style={rectangle, draw=red!60, fill=red!5, very thick, minimum size=5mm},
]
%Nodes
\node[squarednode]      (maintopic)                              {2};
\node[roundnode]        (uppercircle)       [above=of maintopic] {1};
\node[squarednode]      (rightsquare)       [right=of maintopic] {3};
\node[roundnode]        (lowercircle)       [below=of maintopic] {4};

%Lines
\draw[->] (uppercircle.south) -- (maintopic.north);
\draw[->] (maintopic.east) -- (rightsquare.west);
\draw[->] (rightsquare.south) .. controls +(down:7mm) and +(right:7mm) .. (lowercircle.east);

\end{tikzpicture}
\end{document}
```

[Overleaf에서 이 standalone TikZ 예제를 열어보라](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Standalone+TikZ+example\&snip=%5Cdocumentclass%7Bstandalone%7D%0A%5Cusepackage%7Btikz%7D%0A%5Cusetikzlibrary%7Bpositioning%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cbegin%7Btikzpicture%7D%5B%0Aroundnode%2F.style%3D%7Bcircle%2C+draw%3Dgreen%2160%2C+fill%3Dgreen%215%2C+very+thick%2C+minimum+size%3D7mm%7D%2C%0Asquarednode%2F.style%3D%7Brectangle%2C+draw%3Dred%2160%2C+fill%3Dred%215%2C+very+thick%2C+minimum+size%3D5mm%7D%2C%0A%5D%0A%25Nodes%0A%5Cnode%5Bsquarednode%5D++++++%28maintopic%29++++++++++++++++++++++++++++++%7B2%7D%3B%0A%5Cnode%5Broundnode%5D++++++++%28uppercircle%29+++++++%5Babove%3Dof+maintopic%5D+%7B1%7D%3B%0A%5Cnode%5Bsquarednode%5D++++++%28rightsquare%29+++++++%5Bright%3Dof+maintopic%5D+%7B3%7D%3B%0A%5Cnode%5Broundnode%5D++++++++%28lowercircle%29+++++++%5Bbelow%3Dof+maintopic%5D+%7B4%7D%3B%0A%0A%25Lines%0A%5Cdraw%5B-%3E%5D+%28uppercircle.south%29+--+%28maintopic.north%29%3B%0A%5Cdraw%5B-%3E%5D+%28maintopic.east%29+--+%28rightsquare.west%29%3B%0A%5Cdraw%5B-%3E%5D+%28rightsquare.south%29+..+controls+%2B%28down%3A7mm%29+and+%2B%28right%3A7mm%29+..+%28lowercircle.east%29%3B%0A%0A%5Cend%7Btikzpicture%7D%0A%5Cend%7Bdocument%7D)

![CompileSubfilesEx5.png](/files/e0c9c5274582ecfae29ddd1e17669bcd4aa0d09e)

이것이 **standalone**의 주요 기능이다. 이 파일을 다른 어떤 문서에도 가져와 코드를 재사용할 수 있다. 예를 들어, 이 다이어그램은 나중에 아무런 수정 없이 발표 자료에 사용할 수 있다.

[의 예제를 열어보라 `standalone` Overleaf에서 패키지](https://www.overleaf.com/project/new/template/19636?id=66440758\&templateName=Standalone+package+example\&latexEngine=pdflatex\&texImage=\&mainFile=)

## 추가 읽을거리

자세한 내용은 다음을 참조하세요

* [대규모 프로젝트에서의 관리](/latex/ko/document-structure/07-management-in-a-large-project.md)
* [섹션과 방정식의 상호 참조](/latex/ko/document-structure/03-cross-referencing-sections-equations-and-floats.md)
* [색인](/latex/ko/document-structure/04-indices.md)
* [용어집](/latex/ko/document-structure/05-glossaries.md)
* [하이퍼링크](/latex/ko/document-structure/09-hyperlinks.md)
* [페이지 번호 매기기](/latex/ko/formatting/03-page-numbering.md)
* [단면 및 양면 문서](/latex/ko/formatting/08-single-sided-and-double-sided-documents.md)
* [다단 구성](/latex/ko/formatting/09-multiple-columns.md)
* [문단 서식](/latex/ko/formatting/04-articles-how-to-change-paragraph-spacing-in-latex.md)
* [페이지 크기와 여백](/latex/ko/formatting/07-page-size-and-margins.md)
* [카운터](/latex/ko/formatting/10-counters.md)
* [여백 노트](/latex/ko/formatting/15-margin-notes.md)
* [굵게, 기울임꼴 및 밑줄](/latex/ko/latex/03-bold-italics-and-underlining.md)
* [글꼴 크기, 패밀리 및 스타일](/latex/ko/fonts/01-font-sizes-families-and-styles.md)
* [글꼴 서체](/latex/ko/fonts/02-font-typefaces.md)
* [XeLaTeX로 현대 글꼴 지원](/latex/ko/fonts/03-xelatex.md)
* [국제 언어 지원](/latex/ko/languages/03-international-language-support.md)
* [글꼴 크기, 패밀리 및 스타일](/latex/ko/fonts/01-font-sizes-families-and-styles.md)
* [큰 프로젝트 컴파일](/latex/ko/knowledge-base/038-fixing-and-preventing-compile-timeouts.md#compiling-big-projects)
* [이미지 삽입](/latex/ko/more-topics/27-inserting-images.md)
* [TikZ 패키지](/latex/ko/figures-and-tables/05-tikz-package.md)
* [자신만의 패키지 작성하기](/latex/ko/class-files/03-writing-your-own-package.md)
* [자신만의 클래스 작성하기](/latex/ko/class-files/04-writing-your-own-class.md)
* [이 **subfiles** 패키지 문서](http://repositorios.cpai.unb.br/ctan/macros/latex/contrib/subfiles/subfiles.pdf)
* [이 **standalone** 패키지 문서](http://repositorios.cpai.unb.br/ctan/macros/latex/contrib/standalone/standalone.pdf)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/ko/document-structure/08-multi-file-latex-projects.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
