> 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/commands/02-environments.md).

# 환경

LaTeX 환경은 문서 내용의 한 부분에 특정한 조판 효과를 적용하는 데 사용됩니다. 이 글에서는 기존 환경을 사용하는 방법과 새 환경을 정의하는 방법을 설명합니다.

## 소개

환경은 다음으로 시작합니다 `\begin{name}` 그리고 다음으로 끝납니다 `\end{name}`:

```
\begin{name}
여기에 내용을 입력...
...여기에 들어갑니다...
\end{name}
```

여기서 “`이름`”는 사용 중인 환경의 이름입니다. 예를 들어 다음 예제에서는 “`center`”를 사용해 텍스트 단락을 정렬(가운데 정렬)합니다:

```latex
\documentclass{article}
\begin{document}
\begin{center}
이것은 \texttt{center} 환경의 데모입니다.
이 텍스트 단락은 \textit{가운데 정렬}될 것입니다. 왜냐하면
특수한 환경 안에 포함되어 있기 때문입니다. 환경은
문서 내의 텍스트 블록을 효율적으로 수정하는 방법을 제공합니다.
\end{center}
\end{document}
```

[이 예제를 Overleaf에서 열어 보세요.](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Simple+environment+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bcenter%7D%0AThis+is+a+demonstration+of+the+%5Ctexttt%7Bcenter%7D+environment.+%0AThis+paragraph+of+text+will+be+%5Ctextit%7Bcentred%7D+because+it+is+%0Acontained+within+a+special+environment.+Environments+provide+%0Aan+efficient+way+to+modify+blocks+of+text+within+your+document.%0A%5Cend%7Bcenter%7D%0A%5Cend%7Bdocument%7D)

이 예제는 다음과 같은 출력을 생성합니다:

![가운데 정렬을 보여주는 이미지](/files/ada0f7891818d544f481e34c0302a76c6c699f30)

## 환경

다음 예시는 `tabular` 작은 표를 조판하기 위한 환경입니다. `tabular` 는 추가 인수를 받습니다 `{ c c c }` 이는 셀의 정렬을 정의합니다. 자세한 내용은 [표](/latex/ko/figures-and-tables/01-tables.md) 문서를 참조하세요.

```latex
\documentclass{article}
\begin{document}
\begin{tabular}{ c c c }
  cell1 & cell2 & cell3 \\
  cell4 & cell5 & cell6 \\
  cell7 & cell8 & cell9 \\
 \end{tabular}
\end{document}
```

[이 예제를 Overleaf에서 열어 보세요.](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Simple+tabular+environment+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Btabular%7D%7B+c+c+c+%7D+%0A++cell1+%26+cell2+%26+cell3+%5C%5C+%0A++cell4+%26+cell5+%26+cell6+%5C%5C+%0A++cell7+%26+cell8+%26+cell9+%5C%5C+%0A+%5Cend%7Btabular%7D%0A%5Cend%7Bdocument%7D)

이 예제는 다음과 같은 출력을 생성합니다:

![tabular 환경의 예](/files/5075b14113224be61f0bb51cab498aad7af311d2)

일부 환경은 선택적 인수를 허용하며, 이는 일반적으로 괄호 안에 전달됩니다(`[...]`).

## 새 환경 정의하기

새 환경을 정의하려면 `\newenvironment` 명령을 사용합니다. 일반 형식은 다음과 같습니다:

```
\newenvironment{name}[numarg][optarg_default]{begin_def}{end_def}
```

여기서:

* `이름` 은 이 사용자 정의 인수의 이름입니다;
* `numarg` 은 이 환경이 허용하는 인수의 개수로, 1에서 9까지입니다. 만약 `[numarg]` 가 생략되면 이 환경은 인수를 받지 않습니다. 다음 예제의 [`boxed` 환경이 그 예입니다](#defining-simple-environments);
* `optarg_default` 는 첫 번째 인수를 선택 사항으로 만들고 기본값을 제공합니다. 즉, 선택적 인수 값이 제공되지 않을 때 사용되는 값입니다;
* `begin_def` 는 환경이 시작될 때(열릴 때) 실행되는 LaTeX 코드입니다. 즉, 다음을 쓸 때 `\begin{name}`. 이 코드에서는 환경이 허용하는 인수를 사용할 수 있습니다. 선택적 인수는 #1이며, 나머지 인수는 #2부터 #numarg까지를 사용해 접근합니다;
* `end_def` 는 환경이 끝날 때(닫힐 때) 실행되는 LaTeX 코드입니다. 즉, 다음을 쓸 때 `\end{name}`. 이 코드 구간에서는 어떤 인수도 사용할 수 없습니다.

### 간단한 환경 정의하기

첫 번째 예제에서는 `boxed` 환경을 정의합니다. 이 환경은 어떤 인수도 받지 않습니다. 환경 안에 포함된 텍스트 주위에 상자를 그립니다:

```latex
\documentclass{article}
% 프리앰블에서 환경을 정의할 수 있습니다
\newenvironment{boxed}
    {\begin{center}
    \begin{tabular}{|p{0.9\textwidth}|}
    \hline\\
    }
    {
    \\\\\hline
    \end{tabular}
    \end{center}
    }
%
\begin{document}
이제 문서에서 \texttt{boxed} 환경을 사용할 수 있습니다:

\begin{boxed}
이 텍스트는 \texttt{boxed} 환경 안에서 형식이 지정됩니다.
\end{boxed}

이 텍스트는 \texttt{boxed} 환경 밖에서 조판됩니다.
\end{document}
```

[이 예제를 Overleaf에서 열어 보세요.](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Creating+a+new+environment\&snip=%5Cdocumentclass%7Barticle%7D%0A%25We+can+define+the+environment+in+the+preamble%0A%5Cnewenvironment%7Bboxed%7D%0A++++%7B%5Cbegin%7Bcenter%7D%0A++++%5Cbegin%7Btabular%7D%7B%7Cp%7B0.9%5Ctextwidth%7D%7C%7D%0A++++%5Chline%5C%5C%0A++++%7D%0A++++%7B+%0A++++%5C%5C%5C%5C%5Chline%0A++++%5Cend%7Btabular%7D+%0A++++%5Cend%7Bcenter%7D%0A++++%7D%0A%25%0A%5Cbegin%7Bdocument%7D%0ANow+we+can+use+the+%5Ctexttt%7Bboxed%7D+environment+in+our+document%3A%0A%0A%5Cbegin%7Bboxed%7D%0AThis+text+is+formatted+within+the+%5Ctexttt%7Bboxed%7D+environment.%0A%5Cend%7Bboxed%7D%0A%0AThis+text+is+typeset+outside+the+%5Ctexttt%7Bboxed%7D+environment.%0A%5Cend%7Bdocument%7D)

이 예제는 다음과 같은 출력을 생성합니다:

![사용자 정의 LaTeX 환경 데모](/files/3021e7c4bfc374cc4bb8b53a84c9afb3093d6a0e)

우리의 정의를 `boxed` 의 일반 형식과 비교해 보면 `\newenvironment` 다음을 알 수 있습니다:

* `이름` 는 `boxed`;
* 둘 다 `[numarg]` 또는 `[optarg_default]` 가 제공되지 않습니다. 이 환경은 인수를 받지 않기 때문입니다;
* `begin_def` 는 LaTeX 코드입니다. 중괄호 한 쌍 사이에 제공되며 `{...}`—환경이 *시작될 때* (열릴 때) 실행됩니다:

```latex
\begin{center}
    \begin{tabular}{|p{0.9\textwidth}|}
    \hline\\
```

* `end_def` 는 LaTeX 코드입니다. 중괄호 한 쌍 사이에 제공되며 `{...}`—환경이 *종료됩니다* (닫힐 때):

```latex
    \\\\\hline
    \end{tabular}
    \end{center}
```

예제에서는 `begin_def` 시작합니다 `center` 환경을 시작하고, 그 안에서 `tabular` 환경을 열어, 환경에 배치한 텍스트 주위에 세로선과 가로선을 그립니다. `end_def` 는 또 다른 가로선을 그린 다음 `tabular` 및 `center` 환경들을 닫습니다.

### 인수를 받는 환경 정의하기

이전 예제를 다음과 같이 확장해 봅시다:

* 선택적 인수를 사용해 제목을 조판합니다. 제목이 제공되지 않으면 기본값 `이것은 상자입니다`;
* 를 사용합니다. 두 번째 인수는 환경 자체 안에서 제공하는 텍스트 앞에 조판할 내용을 포함합니다.

따라서 인수는 2개입니다:

* 첫 번째(인수 1)는 선택 사항입니다;
* 두 번째(인수 2)는 선택 사항이 아닙니다.

즉, `numarg`=2.

업데이트된 우리의 다음 정의를 사용할 수 있습니다 `boxed` 환경:

```latex
\newenvironment{boxed}[2][이것은 상자입니다]
    {\begin{center}
    인수 1 (\#1)=#1\\[1ex]
    \begin{tabular}{{{!}}p{0.9\textwidth}{{!}}}
    \hline\\
    인수 2 (\#2)=#2\\[2ex]
    }
    {
    \\\\\hline
    \end{tabular}
    \end{center}
    }
```

이 향상된 버전은 원본과 다음과 같은 점에서 다릅니다:

* \[numarg]가 존재하며 값은 2입니다;
* \[optarg\_default]도 존재하여 첫 번째 인수를 기본값과 함께 선택 사항으로 만듭니다 `이것은 상자입니다`.

다음 예제는 업그레이드된 우리의 몇 가지 사용법을 보여줍니다 `boxed` 환경:

```latex
\documentclass{article}
% 첫 번째
% 인수의 기본값은 [이것은 상자입니다]로 제공됩니다
\newenvironment{boxed}[2][이것은 상자입니다]
    {\begin{center}
    인수 1 (\#1)=#1\\[1ex]
    \begin{tabular}{|p{0.9\textwidth}|}
    \hline\\
    인수 2 (\#2)=#2\\[2ex]
    }
    {
    \\\\\hline
    \end{tabular}
    \end{center}
    }
\begin{document}
\textbf{예제 1}: 첫 번째 인수에 기본값을 사용합니다:

\begin{boxed}{예비 텍스트}
이 텍스트는 \textit{안}에 있습니다.
\end{boxed}

이 텍스트는 \textit{밖}에 있습니다.

\vskip12pt

\textbf{예제 2}: 첫 번째 인수에 값을 제공합니다:

\begin{boxed}[기본값이 아닌 값]{더 많은 예비 텍스트}
이 텍스트는 여전히 \textit{안}에 있습니다.
\end{boxed}

이 텍스트도 \textit{밖}에 있습니다.
\end{document}
```

[이 예제를 Overleaf에서 열어 보세요.](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Environment+with+an+optional+argument\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Note+the+default+value+for+the+first%0A%25+argument+is+provided+by+%5BThis+is+a+box%5D%0A%5Cnewenvironment%7Bboxed%7D%5B2%5D%5BThis+is+a+box%5D%0A++++%7B%5Cbegin%7Bcenter%7D%0A++++Argument+1+%28%5C%231%29%3D%231%5C%5C%5B1ex%5D%0A++++%5Cbegin%7Btabular%7D%7B%7Cp%7B0.9%5Ctextwidth%7D%7C%7D%0A++++%5Chline%5C%5C%0A++++Argument+2+%28%5C%232%29%3D%232%5C%5C%5B2ex%5D%0A++++%7D%0A++++%7B+%0A++++%5C%5C%5C%5C%5Chline%0A++++%5Cend%7Btabular%7D+%0A++++%5Cend%7Bcenter%7D%0A++++%7D%0A%5Cbegin%7Bdocument%7D%0A%5Ctextbf%7BExample+1%7D%3A+Use+the+default+value+for+the+first+argument%3A%0A+%0A%5Cbegin%7Bboxed%7D%7BSome+preliminary+text%7D%0AThis+text+is+%5Ctextit%7Binside%7D+the+environment.%0A%5Cend%7Bboxed%7D%0A%0AThis+text+is+%5Ctextit%7Boutside%7D+the+environment.%0A%0A%5Cvskip12pt%0A%0A%5Ctextbf%7BExample+2%7D%3A+Provide+a+value+for+the+first+argument%3A%0A+%0A%5Cbegin%7Bboxed%7D%5BThis+is+not+the+default+value%5D%7BSome+more+preliminary+text%7D%0AThis+text+is+still+%5Ctextit%7Binside%7D+the+environment.%0A%5Cend%7Bboxed%7D%0A%0AThis+text+is+also+%5Ctextit%7Boutside%7D+the+environment.%0A%5Cend%7Bdocument%7D)

이 예제는 다음과 같은 출력을 생성합니다:

![선택적 매개변수가 있는 환경](/files/2bbdeb2af4f9f2170d87321d5b63bbf555c1cfde)

### 번호가 매겨진 환경

번호가 매겨진 환경은 수동으로 만들거나, 또는 다음 명령으로 직접 만들 수 있습니다 `\newtheorem`, 다음 예제에서 보듯이:

```latex
\documentclass{article}
% 프리앰블에서 번호가 매겨진 환경을 정의합니다
\newcounter{example}[section]
\newenvironment{example}[1][]{\refstepcounter{example}\par\medskip
   \noindent \textbf{예제~\theexample. #1} \rmfamily}{\medskip}

% 또 다른 번호가 매겨진 환경을 \newtheorem으로 정의합니다
\usepackage{amsmath} % \newtheorem 명령을 위해
\newtheorem{SampleEnv}{샘플 환경}[section]
\begin{document}

\section{사용자 정의 번호가 매겨진 환경}

\begin{example}
첫 번째 사용자 정의 번호가 매겨진 환경(번호 \theexample).
\end{example}

\begin{example}
두 번째 사용자 정의 번호가 매겨진 환경(번호 \theexample).
\end{example}

\section{더 많은 사용자 정의 번호가 매겨진 환경}
예제 번호가 1에서 다시 시작되었음을 확인하세요:

\begin{example}
첫 번째 사용자 정의 번호가 매겨진 환경(번호 \theexample).
\end{example}

\begin{SampleEnv}
\verb|\newtheorem| 명령으로 만든 사용자 정의 환경.
\end{SampleEnv}
\end{document}
```

[이 예제를 Overleaf에서 열기](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Creating+a+numbered+environment\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Define+our+numbered+environment+within+the+preamble%0A%5Cnewcounter%7Bexample%7D%5Bsection%5D%0A%5Cnewenvironment%7Bexample%7D%5B1%5D%5B%5D%7B%5Crefstepcounter%7Bexample%7D%5Cpar%5Cmedskip%0A+++%5Cnoindent+%5Ctextbf%7BExample%7E%5Ctheexample.+%231%7D+%5Crmfamily%7D%7B%5Cmedskip%7D%0A%0A%25+Another+numbered+environment+defined+with+%5Cnewtheorem%0A%5Cusepackage%7Bamsmath%7D+%25+For+the+%5Cnewtheorem+command%0A%5Cnewtheorem%7BSampleEnv%7D%7BSample+Environment%7D%5Bsection%5D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Csection%7BUser-defined+numbered+environments%7D%0A%0A%5Cbegin%7Bexample%7D%0AFirst+user-defined+numbered+environment+%28number+%5Ctheexample%29.%0A%5Cend%7Bexample%7D%0A%0A%5Cbegin%7Bexample%7D%0ASecond+user-defined+numbered+environment+%28number+%5Ctheexample%29.%0A%5Cend%7Bexample%7D%0A%0A%5Csection%7BMore+user-defined+numbered+environments%7D%0ANote+how+the+example+numbering+has+restarted+at+1%3A%0A%0A%5Cbegin%7Bexample%7D%0AFirst+user-defined+numbered+environment+%28number+%5Ctheexample%29.%0A%5Cend%7Bexample%7D%0A%0A%5Cbegin%7BSampleEnv%7D%0AUser-defined+environment+created+with+the+%5Cverb%7C%5Cnewtheorem%7C+command.%0A%5Cend%7BSampleEnv%7D%0A%5Cend%7Bdocument%7D)

이 예제는 다음과 같은 출력을 생성합니다:

![사용자 정의 번호가 매겨진 환경 예시](/files/060842d84cddaccd04ffc992474094c12eb9fb99)

#### 몇 가지 참고 사항

* 수동으로 정의한 `example` 환경에서 명령 `\newcounter{example}[section]` 를 사용하면 카운터가 생성되는데, 이것도 `example`로 알려져 있습니다.  `example` 카운터는 다음과 같습니다:
  * 다음을 사용하여 1씩 증가합니다 `\refstepcounter{example}` 환경 정의 안에서;
  * 새 `\section{...}` 이 시작될 때마다 재설정됩니다;
  * 현재 값을 다음을 사용해 조판할 수 있는 변수입니다 `\theexample`. 다음을 참조하세요 [카운터에 대한 글을](/latex/ko/formatting/10-counters.md) 더 알아보세요.
* 명령 `\newtheorem` 는 번호가 매겨진 환경을 직접 만들며, 세 개의 매개변수를 받습니다:
  * 새 환경의 이름: `SampleEnv` 가 우리의 예입니다;
  * 줄의 시작 부분에 굵게 출력할 텍스트: `Sample Environment` 가 우리의 예입니다;
  * 카운터를 언제 재설정할지 결정하는 선택적 매개변수이며, 이를 사용하면 카운터 앞에 재설정 카운터의 값이 붙습니다: `section` 가 우리의 예입니다.

이 [`amsthm` 패키지](https://ctan.org/pkg/amsthm?lang=en), 다음과 함께 `amsmath`, 유용한 추가 정의를 제공합니다 `\newtheorem`; 자세한 내용은 [정리와 증명](/latex/ko/field-specific/01-theorems-and-proofs.md) 를 확인하세요.

## 기존 환경 다시 정의하기

환경은 다음을 사용해 다시 정의할 수 있습니다 `\renewenvironment` 그 구문은 `\newenvironment`과 동일합니다 — 다양한 매개변수에 대한 설명은 [새 환경 정의하기](#defining-a-new-environment) 섹션을 참조하세요:

```
\newenvironment{name}[numarg][optarg_default]{begin_def}{end_def}
```

다음 예제는 `itemize` 환경을 다시 정의합니다. 이는 과정을 설명하기 위한 예제일 뿐이며, 실제 문서에서 사용해야 한다는 뜻은 아닙니다. 새로운 `itemize` 환경은 더 이상 글머리표 목록을 만들지 않습니다. 대신, 그 안의 텍스트를 가운데 정렬하고 강조(기울임꼴)합니다(다음을 사용하여 `\em` 명령).

```latex
\documentclass{article}
% 프리앰블에서 환경을 다시 정의합니다
\renewenvironment{itemize}
{\begin{center}\em}
{\end{center}}
\begin{document}

\begin{itemize}
\texttt{itemize} 환경을 다시 정의하여 그 안의 모든 텍스트가
가운데 정렬되고 강조(기울임꼴)되도록 했습니다. 더 이상
글머리표 목록을 만들지 않습니다---이는 단지 예일 뿐이며
실제 문서에서 사용하려는 것이 아닙니다!
\end{itemize}
\end{document}
```

[이 예제를 Overleaf에서 열어 보세요.](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Redefining+an+existing+environment\&snip=%5Cdocumentclass%7Barticle%7D%0A%25+Redefine+the+environment+in+the+preamble%0A%5Crenewenvironment%7Bitemize%7D%0A%7B%5Cbegin%7Bcenter%7D%5Cem%7D%0A%7B%5Cend%7Bcenter%7D%7D%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cbegin%7Bitemize%7D%0AWe+have+redefined+the+%5Ctexttt%7Bitemize%7D+environment+so+that+any+text+%0Awithin+it+is+centred+and+emphasised+%28italicized%29.+It+no+longer+creates%0Aa+bulleted+list---this+is+only+an+example+and+not+intended+for+use+%0Ain+real+documents%21%0A%5Cend%7Bitemize%7D%0A%5Cend%7Bdocument%7D)

이 예제는 다음과 같은 출력을 생성합니다:

![다시 정의된 itemize 환경의 예](/files/4b624519d965a6342da589bc916789c8fceb356d)

## 추가 읽을거리

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

* [명령](/latex/ko/commands/01-commands.md)
* [패키지와 클래스 파일 이해하기](/latex/ko/class-files/01-understanding-packages-and-class-files.md)
* [자신만의 패키지 작성하기](/latex/ko/class-files/03-writing-your-own-package.md)
* [자신만의 클래스 작성하기](/latex/ko/class-files/04-writing-your-own-class.md)
* [LaTeX의 길이](/latex/ko/formatting/01-lengths-in-latex.md)
* [LaTeX에서 색상 사용하기](/latex/ko/formatting/13-using-colors-in-latex.md)
* [페이지 크기와 여백](/latex/ko/formatting/07-page-size-and-margins.md)
* [패키지 및 클래스 파일 목록](/latex/ko/class-files/02-overleaf-and-tex-live.md)
* [LaTeX2ε에 대한 그리 짧지 않은 소개](http://www.ctan.org/tex-archive/info/lshort/)
* [WikiBooks의 LaTeX/Creating\_Packages](http://en.wikibooks.org/wiki/LaTeX/Creating_Packages)


---

# 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/commands/02-environments.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.
