단계 2 · 텍스트와 문서 구조 16 / 48 ≈ 20 분 분량

LaTeX 쪽 레이아웃: 여백·용지 크기·줄간격

TeX이 배치하는 상자는 하나이고, 쪽의 나머지는 모두 용지 모서리에서 그 상자까지의 거리입니다 — 다만 TeX이 혼자 잡아 둔 1인치를 넘긴 지점에서 재는 거리지요. 이 강의는 가로와 세로로 겹친 길이 더미, 그 값에 글을 써 넣는 geometry의 키들, 인쇄기로 나가는 것을 결정하는 용지 옵션과 드라이버의 상호 작용, 그리고 쪽을 마감하는 줄간격과 벌점 레지스터를 차례로 훑습니다.

    쪽은 상자의 겹이고 TeX이 배치하는 것은 그중 하나뿐

    TeX이 아는 것은 본문 상자 하나뿐입니다. \textwidth 곱하기 \textheight 크기의 직사각형이고, 2단 조판에서는 \columnsep가 그 안을 다시 가릅니다. 용지 크기와 머리글과 바닥글, 여백 쪽 메모 같은 나머지는 전부 그 상자 변에서 떨어진 거리로 표현되고요. 문서 배열이 그리고 싶은 화판이 아니라 길이 몇 개로 정해지는 이유, 레이아웃 패키지가 숫자 다섯 개로 쪽 전체를 다시 쓸 수 있는 이유가 여기에 있습니다.

    가로로, 용지 왼쪽 끝에서 본문 상자 왼쪽까지의 거리는 1in + \hoffset + \oddsidemargin이고 양면 문서의 짝수 쪽에서는 \evensidemargin를 씁니다. 세로로, 머리글 상자 윗변은 1in + \voffset + \topmargin에 앉고 그 아래로 \headheight, \headsep, 본문 상자, 그리고 \footskip이 따릅니다. footskip은 상자 아래변에서 재지 않고 본문의 마지막 기준선에서 바닥글 기준선까지 잽니다.

    이 1인치가 LaTeX 쪽 기하에 관한 사실 가운데 오해가 가장 큰 항목이고, 출력물이 1인치 안쪽으로 물린 가상의 쪽에서 조판사의 기계에 올라간다는 TeX의 오래된 가정에서 물려받은 값입니다. 그래서 \oddsidemargin=0pt는 글을 용지 끝으로 보내지 못하고 25.4mm 안쪽에 내려 놓을 뿐이며, 손으로 지정한 여백은 1인치를 빼 본 뒤에야 비로소 균형이 맞아 보입니다. 오래된 클래스 파일과 템플릿이 음수를 끌어다 붙이는 모습은 전부 이 상수와 벌인 싸움의 흔적이지요.

    만지기 전에 알아 둘 결과가 하나 있습니다. 세로 구성 요소의 합이 용지보다 크면 TeX은 도형에 대해 불평하지 않고 넘치는 각 쪽에 대해 불평합니다. 로그에는 Height too large를 담은 badbox 줄, 아니면 거대한 Overfull \vbox 한 줄이 남고 — 고전적인 숫자가 115.7pt too high입니다 — 고칠 대상도 단락이 아니라 기하입니다. geometry의 heightrounded 옵션이 막아 주는 사고가 정확히 이것이며, 방식은 \textheight를 \baselineskip의 정수배로 아래로 반올림하는 것입니다.

    \begin{array}{rcl}\text{left edge to text} & = & \text{one inch} + \texttt{hoffset} + \texttt{oddsidemargin} \\ \text{top edge to header} & = & \text{one inch} + \texttt{voffset} + \texttt{topmargin}\end{array}
    \begin{array}{rcl}\text{left edge to text} & = & \text{one inch} + \texttt{hoffset} + \texttt{oddsidemargin} \\ \text{top edge to header} & = & \text{one inch} + \texttt{voffset} + \texttt{topmargin}\end{array}
    The box model of a TeX page: the one-inch origin, the vertical stack of topmargin, headheight, headsep, textheight and footskip, and the horizontal oddsidemargin plus textwidth TEX LAYS OUT ONE RECTANGLE — EVERY OTHER NUMBER IS A DISTANCE FROM AN EDGE OF THE PAPER TO IT the paper: \paperwidth × \paperheight — a4paper is 210 × 297mm 1in × 1in the origin TeX assumes \textheight last baseline 1in + \voffset + \topmargin down to the top of the header box, if there is one \headheight \headsep \textheight — the block \footskip from the LAST baseline to the footer's own baseline bottom margin: no register header and footer sit outside \textheight. THE HORIZONTAL STACK, LEFT TO RIGHT — IT ADDS UP TO \paperwidth 1in \hoffset \oddsidemargin \textwidth — the block the remainder twoside swaps in \evensidemargin on even pages · in two columns \columnsep is taken out of \textwidth \marginparwidth and \marginparsep cut the marginal box out of that remainder on the right schematic, not to scale WHY \oddsidemargin=0pt IS NOT FLUSH WITH THE EDGE The inch is in the box before you type anything — an inheritance from TeX's typesetter origin, not a 0pt → 25.4mm margin -5.4mm → 20mm GEOMETRY SUBTRACTS THE INCH FOR YOU top=3cm → \topmargin = 3cm - 1in and with includehead also headheight + headsep, which is why turning that key on moves the block down IF THE STACK IS TALLER THAN THE PAPER No geometry error — a message per page: Overfull \vbox (115.7pt too high). heightrounded is the prevention.
    TeX이 가정하는 1인치를 포함해, 본문 상자를 용지 위에 올려 놓는 가로·세로 길이들의 겹.

    geometry: 각 키가 실제로 고쳐 쓰는 것

    \usepackage[margin=2.5cm]{geometry}가 대체로 문서에 필요한 인터페이스의 전부이고, 이 패키지는 스위치라기보다 계산기에 가깝습니다. 중요하게 생각하는 거리를 적어 두면 \textheight와 \textwidth, 측면과 상단의 길이, 머리글·바닥글 스킙을 패키지가 풀어 내고, 선택한 값을 로그에 찍어 다시 읽을 수 있게 해 주지요.

    가장자리 계열 키는 네 변을 함께 주는 margin, 한 쌍을 주는 hmargin과 vmargin, 하나씩 지정하는 left/right/top/bottom, 그리고 문서가 twoside일 때 제본쪽과 바깥쪽을 뜻하는 inner/outer입니다. bindingoffset은 다른 것을 하나도 옮기지 않고 안쪽 가장자리에 여백을 더하며, 학위논문을 인쇄소에 넘기는 유일한 정답이 이것입니다. 상자 계열은 방향이 반대입니다: textwidth=/width=와 textheight=/height=는 상자 자체를 지정하고 여백은 패키지가 택하게 두며, total=은 머리글과 바닥글까지 상자에 포함해 지정합니다.

    혼란이 몰려 있는 곳은 포함 키입니다. top 같은 말의 뜻을 이 키들이 바꿔 놓기 때문이지요. 기본값에서 여백은 본문 상자에만 적용됩니다. 즉 top=3cm은 용지 끝에서 본문 첫 줄까지 3cm이고 머리글은 그 공간 안쪽에 들어가 있습니다. includehead를 켜면 머리글이 3cm 안에 들어가고 본문 상자는 더 아래에서 시작하며, includefoot는 바닥글에 같은 일을 하고 includeheadfoot은 둘 다 하지요. 따라서 \pagestyle{headings}를 켠 뒤 머리글이 본문과 부딪히는 문서에 필요한 것은 더 큰 \headsep가 아니라 includehead입니다.

    두 번째 계열의 키는 상자를 절대 측정 대신 비율로 정하는데, 고전적인 쪽 설계가 바로 이렇게 합니다. hdivide={*,12.5cm,*}와 vdivide={...}는 이름 붙인 띠들로 면을 짜고, ratio=9:16(또는 hratio, vmarginratio)은 용지에서 비율로 상자를 잘라 냅니다. vcenter/centering은 상자를 세로 가운데에 둘지를 결정하고, invertedmargin은 여백과 글을 뒤바꿔 기하를 한눈에 보이게 만드는 디버깅용 장난감입니다.

    \begin{array}{lll}\text{key} & \text{writes} & \text{counts the header?} \\\hline \texttt{top=3cm} & \texttt{topmargin} & \text{no, unless includehead} \\ \texttt{textwidth=12cm} & \texttt{textwidth} & \text{irrelevant} \\ \texttt{includefoot} & \text{reuses footskip} & \text{yes, the footer}\end{array}
    \begin{array}{lll}\text{key} & \text{writes} & \text{counts the header?} \\\hline \texttt{top=3cm} & \texttt{topmargin} & \text{no, unless includehead} \\ \texttt{textwidth=12cm} & \texttt{textwidth} & \text{irrelevant} \\ \texttt{includefoot} & \text{reuses footskip} & \text{yes, the footer}\end{array}
    A page annotated with the geometry package key that controls each edge, and a table of the TeX length each key actually writes WHAT YOU TYPE IS A KEY, WHAT TEX GETS IS A LENGTH — GEOMETRY SOLVES ONE FROM THE OTHER the paper itself: a4paper · letterpaper · b5paper → \paperwidth, \paperheight and the driver's media box top=3cm first line of text includehead headheight= headsep= footskip= includefoot bottom=3.5cm inner=3.5cm left=2.5cm if oneside bindingoffset right=2.5cm outer= if twoside includemp notes in left= textwidth=12.5cm state the block textheight= height= · total= scale= · ratio= schematic, not to scale — showframe draws these very boxes on your own page KEY LENGTH IT WRITES COUNTED? a4paper margin=2.5cm top=3cm bottom=3.5cm left=2.5cm right=2.5cm inner= outer= bindingoffset=10mm includehead includefoot includemp heightrounded \paperwidth \paperheight all four edges at once \topmargin solves \textheight \oddsidemargin solves \textwidth \oddsidemargin \evensidemargin \hoffset + the inner side \topmargin, \headheight \textheight, \footskip \marginparwidth \marginparsep \textheight, rounded down + the driver box one-line answer not the header not the footer = 2.5cm − 1in paper − L − R only when twoside fore-edge unmoved counted in top= counted in bottom= counted in left= fits whole lines A CALCULATOR, NOT A SWITCH: IT SHOWS ITS WORK it prints the lengths it chose into the .log, so read them there instead of guessing what top= became. DO NOT MIX THE TWO LANGUAGES geometry overwrites \oddsidemargin and \topmargin, and \newgeometry clears the page before it applies
    왼쪽에는 geometry의 키, 오른쪽에는 그 키가 고쳐 쓰는 TeX 길이, 그리고 머리글이나 바닥글이 여백에 포함되는지가 담겼습니다.
    \documentclass[11pt]{article}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    
    % The one package that owns page geometry. Options at load time are the same
    % as \geometry{...} in the preamble, split over lines here for legibility.
    \usepackage[%
      a4paper,                    % paper: letterpaper, b5paper, a5paper, ...
      margin=2.5cm,               % all four edges at once
      headheight=14pt,            % fancyhdr will ask for this explicitly
      headsep=16pt,
      footskip=28pt,
      includeheadfoot,            % the header/footer live INSIDE the 2.5cm
      bindingoffset=8mm,          % extra room on the inner side, for printing
      twoside,                    % inner/outer instead of left/right
      heightrounded,              % an whole number of lines per page
      showframe,                  % draw the box edges -- remove for the final build
    ]{geometry}
    
    \begin{document}
    
    % What the keys resolved to: look for these lines in the .log file.
    \typeout{geometry gave: textwidth=\the\textwidth, textheight=\the\textheight,
      topmargin=\the\topmargin, oddsidemargin=\the\oddsidemargin}
    
    \section*{A page is a decision, not a canvas}
    
    The text block is the only thing TeX lays out; everything else on this page
    is a distance from an edge of the paper to a side of that block. Load
    \texttt{geometry}, state the block once, and stop touching it: any
    \texttt{\textbackslash vspace} or \texttt{\textbackslash enlargethispage} used
    to repair one bad page will move two pages later, because the reflow changes
    line breaking from there on.
    
    \end{document}

    문서 일부만 다른 geometry, 그리고 종이로 확인하기

    패키지 인터페이스는 로드 시점에 얼어붙지 않습니다. 도입부에 둔 \geometry{headheight=15pt}는 설정을 더하거나 고치고, \newgeometry{...} / \restoregeometry는 자기 배열을 가진 구간을 감싸는데 — 넓은 표 쪽, 가로로 눕힌 그림, 행폭을 좁히려는 시 한 수처럼요 — \newgeometry는 \clearpage를 알아서 발행하므로 쪽 경계에서만 시작할 수 있습니다. 구간이 다음 쪽 맨 위에서 시작된다는 사실을, 중간에서 시작하리라 기대한 사람은 자주 놓칩니다.

    \savegeometry{wide}과 \loadgeometry{wide}는 설정에 이름을 붙여 줍니다. 긴 부록이 여섯 개 키를 매번 다시 적는 대신, 알고 있는 두 상태 사이를 오가면 되지요. 변경이 diff 안에서 검토 가능한 형태로 남는 것도 이 명령들의 소득입니다. 레이아웃을 설계 결정으로 다루는 태도와 쪽과의 말다툼으로 다루는 태도의 경계가 여기 있습니다.

    지금 가진 배열을 확인하는 도구는 셋입니다. showframe은 본문 상자와 머리글, 바닥글, 여백 메모 상자, 용지 가장자리라는 모든 경계에 선을 긋기 때문에, 무언가 그 자리에 있는 이유를 찾는 가장 빠른 길입니다. layout 패키지는 상자·줄·여백·마지막 쪽의 깊이까지 표시한 가짜 쪽을 한 장 뽑아 주어, 인쇄소에 규격을 넘길 때 파일철에 넣어 둘 도식이 됩니다. 그리고 \typeout{\the\textwidth, \the\textheight}는 로그에 실제 숫자를 써 넣습니다. 소스에 margin=2.5cm라고 적힌 순간에는 geometry가 아직 그것들을 확정하지 않았기 때문이지요.

    해서 안 되는 일들을, 시도 빈도가 높은 순대로 적어 둡니다. 도입부 이후에 \textwidth를 바꿔 쪽이 제대로 다시 배치되리라 기대하는 것(플로트와 머리글 선, 캡션 너비는 이미 계산이 끝난 뒤입니다), \oddsidemargin으로 여백을 정하면서 1인치를 잊는 것, \enlargethispage를 간격 도구처럼 쓰고 쪽 하나의 수리로 두지 않는 것, 그리고 geometry를 올린 문서에서 클래스의 원시 길이로 손을 뻗는 것 — 패키지가 그냥 덮어써 버립니다.

    용지 크기, 그리고 반드시 합의해야 하는 드라이버

    표준 클래스에서 용지 크기는 클래스 옵션입니다 — \documentclass[a4paper]{article}, 그리고 letterpaper(미국 설치의 기본값), a5paper, b5paper, legalpaper, executivepaper, 여기에 상자를 회전시키는 landscape까지 — 이 값은 동시에 geometry 키이기도 하며 양쪽에 적히면 geometry가 이깁니다. 어느 경로든 \paperwidth와 \paperheight를 세우고, geometry 키는 거기에 더해 여백까지 다시 계산합니다. 클래스 옵션 홀로는 그 계산까지 하지 않습니다.

    두 길이를 세우는 일과 출력 드라이버에 알리는 일은 별개입니다. pdfTeX는 자기 원시 명령(\pdfpagewidth, \pdfpageheight)으로 미디어 상자를 쓰고, dvips 계열 경로는 papersize special을 읽습니다. 둘이 어긋나면 화면에서는 멀쩡한데 잘려 나오는 문서, 또는 letter 용지 한가운데 앉은 A4 상자를 받게 되지요. geometry에게 맡기면 드라이버 쪽까지 처리해 줍니다 — paper=/a4paper 키는 길이와 드라이버 크기를 함께 세우고, 자동 인식이 실패하는 경우에 대비해 pdftex, xetex, luatex, dvips, dvipdfm 옵션도 받습니다.

    결정의 나머지 절반은 클래스입니다. 클래스 파일을 내려 주는 출판사나 대학은 이미 상자와 줄간격, 대개는 글자체까지 골라 둔 상태이고, 문서는 a4paper를 넘길지 \geometry를 아예 쓸지까지 적어 둡니다. 사설 클래스 위에 자기 기하를 얹는 것은 저널 문헌 목록 스타일을 손으로 비껴 쓰는 일의 레이아웃판과 같지요. 클래스 파일이 없을 때의 표준 경로는 이렇습니다: 용지 크기는 클래스 옵션으로, 여백은 geometry로, 그 외에는 아무것도.

    단행본에는 geometry보다 오래된 두 번째 전통이 있습니다. KOMA-script의 typearea는 용지와 분할수에서 고전적으로 비례한 본문 상자를 계산합니다(\usepackage[DIV=9,BCOR=15mm]{typearea}에서 DIV가 클수록 상자는 작아지고 여백은 넓어지며, BCOR은 제본 보정치입니다). memoir는 자기 명령으로 같은 일을 하지요: \settypeblocksize{245mm}{145mm}{*}, \setlrmargins{*}{*}{1.4}, \setulmargins{*}{*}{1.2}를 주고 마지막에 \checkandfixthelayout을 부릅니다. 이 호출은 앞의 것을 무엇이든 고친 뒤 반드시 필요합니다. 패키지가 파생 길이를 전부 다시 뽑아내야 하기 때문이지요.

    % Two ways to get a classically proportioned page without geometry.
    \documentclass[12pt,a4paper,twoside,openright]{book}
    
    % Route A: KOMA-script's typearea computes the text block from the paper and
    % a division ratio (the bigger DIV, the smaller the block).
    \usepackage[DIV=9,BCOR=15mm]{typearea}
    
    % Route B: the raw TeX lengths, which is what every layout package writes.
    % Remember the one-inch assumption: \oddsidemargin is measured from 1in in.
    % \setlength{\textwidth}{14.5cm}
    % \setlength{\textheight}{24.5cm}
    % \setlength{\oddsidemargin}{-0.6cm}    % 1in - 0.6cm from the paper edge
    % \setlength{\topmargin}{0.5cm}         % 1in + 0.5cm down to the header
    % \setlength{\headheight}{14pt}
    % \setlength{\headsep}{18pt}
    % \setlength{\footskip}{26pt}
    % \addtolength{\textheight}{-\headheight}
    % \addtolength{\textheight}{-\headsep}
    
    \usepackage{setspace}
    \usepackage{microtype}
    
    \begin{document}
    
    \onehalfspacing           % \setstretch under the hood, applied for you
    \raggedbottom             % do not stretch the last page of a chapter
    
    \chapter{Why heightrounded matters}
    If \texttt{textheight} is not an exact multiple of \texttt{baselineskip}, TeX
    either overflows the page by a fraction of a line -- the log calls it
    \texttt{Height too large} in a \texttt{badbox} -- or leaves the last baseline
    short. Rounding the height to a whole number of lines is the difference
    between a stable page grid and one that shifts when you edit a paragraph.
    
    \end{document}

    줄간격: 레지스터와 배율, 그리고 패키지

    기준선에서 기준선까지의 거리는 \baselineskip이고, 이 값을 고르는 것은 현재 효력을 가진 크기 스위치입니다. 표준 article 클래스에서 10pt 글자는 12pt 줄간격에 앉고, 12pt 기본에서는 12pt 글자가 14.5pt 간격에 있지요. 문서가 너무 빡빡하다고 말할 때 사람들은 거의 언제나 그 비율을 이야기하는 것이지 글자 크기가 아닙니다. 바꿔야 할 대상은 줄간격이고, 한 번에, 전역에서 바꿔야 합니다.

    원시 메커니즘은 \linespread{factor}\selectfont입니다. \linespread는 배율을 저장하기만 하고 새 값은 다음에 글자 크기가 선택될 때 적용되는데, 그래서 \selectfont 없는 \linespread{1.05}는 눈에 띄는 변화를 만들지 못하고, 이 두 개는 클래스가 어차피 \normalfont를 선택하는 도입부에 가야 합니다. \selectfont는 장식이 아니며, 그것을 빼는 것이 줄간격 변경이 무시된 것처럼 보이는 가장 흔한 이유입니다.

    setspace 패키지는 같은 메커니즘을 감싸고 맨 배율이 놓치는 부분까지 더합니다. \setstretch{1.18}은 배율을 대신 적용하고, \onehalfspacing과 \doublespacing은 워드프로세서 관례 두 가지를 주며, spacing/doublespace 환경은 변경을 한 블록으로 좁힙니다. 이름 붙은 값들은 일부러 1.5와 2.0이 아닙니다 — 클래스가 이미 공급하는 줄간격을 기준으로 튜닝한 값이라, 두 배 줄간격의 LaTeX가 워드프로세서 출력보다 더 헐겁게 보이면서도 제출 지침의 요건은 그대로 채웁니다. setspace는 캡션과 각주를 본문보다 빡빡한 자기 간격에 유지하므로, 본문을 두 배로 늘려도 여백의 글까지 두 배가 되지는 않습니다.

    인접한 두 레지스터가 세로 이야기를 마감합니다. \parskip은 단락 사이 틈으로, 앞 강의에서 내린 단락 스타일 결정에 속하지 줄간격에 속하지 않습니다. 그 안에 든 신축(0.45\baselineskip plus 2pt minus 1pt)이 쪽들을 숨 쉬게 하는 요소이지요. 그리고 \lineskip과 \lineskiplimit은 인접 두 줄이 명목 기준선 거리로 떨어질 수 없을 만큼 키 클 때 바통을 이어받습니다 — 중첩 분수가 이어진 쪽만 울퉁불퉁하고 문서 나머지는 멀쩡해 보이는 이유입니다.

    \begin{array}{c}\texttt{topmargin}\;(\text{from one inch down}) \\ \hline \texttt{headheight} \to \texttt{headsep} \to \underbrace{\texttt{textheight}}_{\text{the text block}} \\ \hline \texttt{footskip}\;(\text{last baseline to the footer baseline})\end{array}
    \begin{array}{c}\texttt{topmargin}\;(\text{from one inch down}) \\ \hline \texttt{headheight} \to \texttt{headsep} \to \underbrace{\texttt{textheight}}_{\text{the text block}} \\ \hline \texttt{footskip}\;(\text{last baseline to the footer baseline})\end{array}
    The vertical stack of a paragraph: baselineskip between lines, lineskip when a line is tall, parskip between paragraphs, the named skips, and the linespread factor applied at font selection EVERY VERTICAL GAP HAS AN OWNER — NAMING THE OWNER IS HOW A SPACING PROBLEM GETS FIXED GLOBALLY ONE PARAGRAPH, MEASURED BASELINE TO BASELINE The quick brown fox jumps over lazy glyphs and leaves no descender below it. one tall line holds a b+1 A new paragraph starts here \parskip + one \baselineskip \[ \frac{a}{b} = c \] indented by \parindent — or a gap, no indent \baselineskip 12pt at a 10pt base, 14.5pt at a 12pt base \lineskip and \lineskiplimit: too-tall neighbours \parskip a blank line in the source is what buys it \abovedisplayskip short variant, then \belowdisplayshortskip WHO OWNS WHICH GAP \baselineskip \lineskip \lineskiplimit \parskip \abovedisplayskip \topsep \itemsep \floatsep \textfloatsep \abovecaptionskip \smallskipamount one line of a paragraph to the next two lines carrying tall material paragraph to paragraph — a style choice text to a displayed formula, and back around a list, and between its items a float to the text above and below it a caption to the float it belongs to the three named glues — see below THE FACTOR, APPLIED ONCE \linespread{1.05}\selectfont linespread stores a multiplier only: it lands when a size is next selected, so dropping \selectfont is the reason a leading change "does nothing" at all. setspace: \setstretch{1.18} does both GLUE, NOT HARD SPACE \smallskip 1pt plus 3pt minus 1pt \medskip 6pt plus 12pt minus 4pt \bigskip 12pt plus 16pt minus 4pt they stretch and shrink, so a page break can absorb them: \vspace{6pt} cannot. WHAT YOU ACTUALLY WANT the page feels tight → leading, once: \linespread{1.05}\selectfont paragraphs need air → a style, not a gap: \usepackage{parskip} one gap here, once → \medskip, not \vspace{6pt} Vertical glue has no meaning inside a line: a \vspace typed mid-line waits for the next break or is dropped, and at the top of a page plain \vspace is discarded while \vspace* survives. The three named skips keep their manners at a page break for the same reason — they are glue. Last vertical decision, a switch not a length: \raggedbottom lets a short page end short (article); \flushbottom stretches the interline glue.
    기준선에서 다음 기준선까지: 그 거리를 어느 레지스터가 소유하는지, 줄이 키 클 때는 어느 레지스터가 대신 나서는지를 보여 줍니다.

    양면 쪽, running head, 그리고 여백 메모

    twoside 문서에서는 본문 위치가 두 가지라서, 클래스는 \oddsidemargin과 \evensidemargin를 따로 묻고 geometry는 대신 inner와 outer로 말합니다. 이 분리를 낳은 타이포그래피 이유는 제본입니다. 안쪽 여백은 독자의 손가락과 싸우는 자리이므로 더 넓어야 하고, 제본된 문서에 좌우 대칭 배열을 얹으면 좁아 보이지요. 시각적 여백이 아니라 구체적인 접착 여유를 요구하는 인쇄소에게는 bindingoffset=10mm를 더하면 됩니다.

    running head는 \markboth{left-side text}{right-side text}(또는 \markright)가 만들고 \pagestyle{headings}가 그것을 꺼내 씁니다. 클래스는 장과 절의 제목 위치에서 두 표식을 모두 채웁지요. 양면 문서에서 왼쪽 머리글은 보통 장을, 오른쪽은 절을 실으니, 클래스가 모든 제목에서 두 표식을 다 쓰는 이유가 여기 있고 — 바꿀 때 정직한 방법이 \fancyhead[LE,RO]{\nouppercase{\leftmark}}형 슬롯을 갖춘 fancyhdr인 이유이기도 합니다. 이 패키지의 유명한 경고 headheight is too small (12.0pt)는 성가신 소음이 아닙니다. geometry가 예약한 상자에 머리글 내용이 안 들어간다는 뜻이고, 고칠 곳은 geometry에 headheight=14pt를 적어 본문 상자와 함께 내려 앉히는 것입니다.

    여백 메모는 자기 길이가 세 개 있는 상자입니다 — \marginparwidth, \marginparsep, \marginparpush — 양면 쪽에서는 쓸 수 있는 너비가 좌우로 다르므로, 홀수 쪽에 들어맞던 메모가 짝수 쪽에서 흘러내릴 수 있습니다. 맨 \marginpar는 메모를 현재 줄에 두고 충돌을 잘 끌어모으는데, marginnote 패키지는 메모를 줄 바꾸기와 무관하게 배치하고 marginfix는 순서를 다시 모아 겹침을 없앱니다. KOMA-script의 \marginline{...}는 정렬까지 대신 해 주지요.

    여백에 진짜 단락을 두고 본문과 같은 세로 위치에 메모를 세우고 싶다면, 그것은 아예 다른 레이아웃 — 투프트 스타일 — 이고 그 세계의 주인은 tufte-latex 또는 KOMA의 넓은 여백 클래스입니다. 그 아래에서는 쪽의 기하와 \marginpar의 동작이 설계 단계부터 얽혀 있어서, 둘 중 하나의 길이만 손으로 잡으면 다른 하나가 깨집니다.

    \documentclass[10pt,a4paper]{article}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    \usepackage[a4paper,top=3cm,bottom=3.5cm,left=2.5cm,right=2.5cm]{geometry}
    \usepackage{setspace}
    \usepackage{needspace}
    \usepackage{marginnote}
    \usepackage{fancyhdr}
    
    \setstretch{1.18}
    \setlength{\parskip}{0.45\baselineskip plus 2pt minus 1pt}
    \setlength{\parindent}{0pt}
    
    % widows and clubs: one line of a paragraph left behind is worth a page break
    \widowpenalty=10000
    \clubpenalty=10000
    
    \pagestyle{fancy}
    \fancyhf{}
    \fancyhead[LE,RO]{\small\nouppercase{\leftmark}}
    \fancyfoot[C]{\thepage}
    \renewcommand{\headrulewidth}{0.4pt}
    
    \begin{document}
    
    % \newgeometry issues a \clearpage of its own, so it can only be used after
    % \begin{document} -- never in the preamble, where \geometry{...} belongs.
    \newgeometry{left=4cm,right=2cm}   % a wide-inner region for asides
    
    \section{Margins are set once}
    
    A wide-margin region for a quotation, then the document geometry back again:
    \marginnote{Margin notes are a box of their own: \texttt{marginparwidth}
    sets the width, \texttt{marginparsep} the gap to the text, and
    \texttt{marginparpush} the minimum distance between two of them.}
    
    \begin{quote}
    Quoted material inherits the text block, not the page. If the quote wants
    different margins, that is an environment with its own \leftmargin,
    not a change to the geometry.
    \end{quote}
    
    \restoregeometry
    
    \section{Space that must not collapse}
    
    \needspace{7\baselineskip}
    This heading and the six lines below it belong together; \texttt{needspace}
    starts a new page rather than splitting them, which is what
    \verb|\nopagebreak| and a chain of forced breaks only imitate.
    
    \end{document}

    벌점: 쪽이 끝날 자리를 스스로 정하는 방법

    페이지 나누기는 최적화 문제이고, 최적화되는 숫자는 공개되어 있습니다. \widowpenalty는 다음 쪽 맨 위에 홀로 남는 줄에 값을 매기고, \clubpenalty는 이전 쪽 맨 아래에 갇히는 첫 줄, \displaywidowpenalty는 디스플레이 수식 바로 앞의 줄, \brokenpenalty는 하이픈으로 나뉜 줄 뒤의 쪽 나눔, \interlinepenalty는 쪼개진 단락의 중간 줄마다 값을 매깁니다. TeX 자체의 기본값은 온순하고, 산문에 대한 표준 조언은 도입부에 \widowpenalty=10000과 \clubpenalty=10000을 두는 것이며, 그러면 두 경우 모두 사실상 불가능해지지요.

    벌점은 "이 블록은 갈라지면 안 된다"에 대한 답이기도 합니다. 줄 끝에 두는 \nopagebreak, 제목 앞에 두는 \needspace{6\baselineskip}, 단락과 그 그림을 감싸는 minipage, 움직여선 안 되는 이미지에 쓰는 [H]형 비플로트가 그것들입니다. 각각은 쪽에 대한 선언이고 글루 한 덩이가 아니므로 편집을 견딥니다 — 손으로 놓은 \vspace가 견디지 못하는 바로 그 지점입니다.

    플로트에는 자기 예산이 있고, "쪽 위가 빈 공간으로 가득"한 문서는 대개 여백이 아니라 플로트 배치의 문제입니다. 중요한 숫자 다섯은 \textfraction(한 쪽에서 글이 반드시 차지해야 하는 최소 비율), \topfraction과 \bottomfraction(위와 아래에서 플로트가 점유할 수 있는 분량), \floatpagefraction(순수 플로트 쪽이 얼마나 차 있어야 하는지), \totalnumber(한 쪽에 같이 살 수 있는 플로트 수)입니다. \topfraction을 0.85로, \floatpagefraction을 0.8로 올리는 것이 표준 쌍이며, 도입부에서 \topfraction 계열에 \renewcommand를 써서 고치고, \clearpage를 흩뿌리는 대신 placeins 패키지의 \FloatBarrier를 택하십시오.

    마지막 세로 결정은 이렇습니다. \raggedbottom은 짧은 쪽이 그 지점에서 끝나게 내버려 두고, \flushbottom은 줄 사이 글루를 늘려 마지막 기준선을 정해진 높이에 착지시킵니다. article은 기본이 ragged, report와 book은 flush이고, 그래서 학위논문에서 장의 마지막 쪽이 나머지보다 헐겁게 보이지요. 신경 쓰인다면 도입부 한 줄로 고칠 문제이고, 해선 안 될 일은 그 쪽에 손으로 공간을 더하는 것입니다.

    변호 가능한 레이아웃, 다섯 줄로

    인상부터 시작하지 말고 요건부터 시작하십시오. 학위과정 사무실이 "A4, 여백 2.5cm, 줄간격 1.5배, 제본 여유 15mm"를 요구하면 그대로 \documentclass[12pt,a4paper,twoside,openright]{report}와 \usepackage[a4paper,inner=2.5cm,outer=2.5cm,top=3cm,bottom=3.5cm,bindingoffset=15mm,includeheadfoot,headheight=14pt,heightrounded]{geometry}, 그리고 setspace의 \onehalfspacing으로 번역됩니다. 쪽에서 그 밖의 선택은 레이아웃 결정이 아니라 타이포그래피 결정이고, 타이포그래피는 따로 싸울 문제이지요.

    그다음에는 결과물을 읽을 기계에서 확인합니다. showframe을 켜고 한 번 컴파일해 첫 쪽과 디스플레이 수식을 품은 쪽을 보고, 로그에서 Overfull \vbox (…pt too high)를 찾습니다 — heightrounded가 불가능하게 만들었을 그 메시지 말이지요 — 그리고 머리글 상자를 넣을 크기로 만든 적이 없음을 알려 주는 headheight is too small 경고도 함께 봅니다.

    가득 찬 쪽의 줄 수와 가득 찬 줄의 문자 수를 세어 보세요. 한 단 본문 글자체에서 읽기 좋은 행폭은 대략 60자에서 75자이고, 이 숫자는 \textwidth를 쓰는 크기의 평균 글자 너비로 나누면 떨어집니다. 그래서 \typeout{\the\textwidth}와 본문 한 줄 관찰은 여백에 대한 개인적 견해보다 나은 설계 도구가 되지요. 행폭이 넓다면 고칠 곳은 상자 너비 또는 2단 배열(twocolumn, 또는 multicol 패키지에 \columnsep과 \columnseprule)이고, 글자를 줄이는 것이 아닙니다.

    이 전체를 유지 가능하게 지키는 규칙은 하나입니다. 기하는 도입부에, 간격은 패키지에, 나눔은 벌점에 속하고, 쪽별로 쓰는 도구는 \enlargethispage가 유일합니다 — 한 쪽에서, 한 가지 이유로, 무엇을 위한 것인지 댓글을 달아 두고 쓰라는 것이지요. 쪽에 가하는 다른 모든 부분 처방은 다음 편집이 쪽 두 장을 망가뜨리리라는 약속과 같습니다.

    이 강의 요약표

    각 소절의 핵심 코드 한 줄씩. 소절 제목을 눌러 해당 위치로 이동하고 코드는 바로 복사하세요.

    소절 핵심 코드
    \begin{array}{rcl}\text{left edge to text} & = & \text{one inch} + \texttt{hoffset} + \texttt{oddsidemargin} \\ \text{top edge to header} & = & \text{one inch} + \texttt{voffset} + \texttt{topmargin}\end{array}
    \documentclass[11pt]{article}
    \documentclass[12pt,a4paper,twoside,openright]{book}
    \begin{array}{c}\texttt{topmargin}\;(\text{from one inch down}) \\ \hline \texttt{headheight} \to \texttt{headsep} \to \underbrace{\texttt{textheight}}_{\text{the text block}} \\ \hline \texttt{footskip}\;(\text{last baseline to the footer baseline})\end{array}
    \documentclass[10pt,a4paper]{article}

    자주 하는 실수

    • \oddsidemargin=0pt를 주고도 여전히 1인치 여백을 얻는 일. TeX은 상자를 용지 끝에서 1인치 안쪽 지점부터 재므로 진짜 2.5cm 여백은 -0.6cm입니다 — 또는 훨씬 좋게, 셈은 geometry에게 시키십시오.
    • \linespread{1.5} 뒤에 \selectfont를 두지 않고, 그 다음에 명령이 고장났다고 결론짓는 것. 배율은 크기가 선택되는 순간에만 읽히며, setspace는 이 쌍을 대신 처리해 줍니다.
    • 클래스에는 a4paper를 주고 geometry에는 다른 용지를 주거나, \paperwidth를 손으로 세우는 일. 드라이버는 미디어 상자를 하나만 쓰고, 인쇄기는 그 밖을 잘라 버립니다.
    • includehead/includefoot를 뒤늦게, 혹은 아예 넣지 않아 위 여백 안으로 파고드는 머리글과 싸우는 것. 그 키들이 없으면 여백은 본문 상자에만 적용됩니다.
    • 고아 줄이나 갈라진 블록을 \\나 \vspace, 빈 단락으로 막지 말고 \widowpenalty와 \clubpenalty로 잡으십시오. 블록을 minipage로 감싸거나 \needspace로 공간을 요청하는 방법도 있지요.
    • Overfull \vbox ... (badness)와 headheight is too small를 그냥 경고로 넘기는 것. 둘 다 얼마만큼 틀렸는지 길이 이름을 짚어 주고, 둘 다 쪽에서가 아니라 도입부에서 고쳐집니다.
    • \newgeometry로 문서 중간에서 기하를 바꾸면서 현재 줄부터 적용되리라 기대하는 실수. 본문 상자는 쪽 도중에 바뀔 수 없으므로, 이 명령은 먼저 쪽을 끝냅니다.
    • 안 좋은 쪽 하나를 \enlargethispage로 손질해 두고 그대로 데리고 다니는 일. 그것은 쪽 하나의 수리일 뿐이고, 위쪽 텍스트가 다시 배치되고 나면 두 절 뒤에 이유 없이 벌어진 틈이 됩니다.

    이 강의에 대한 질문

    LaTeX에서 여백은 어떻게 바꾸나요?
    geometry를 원하는 거리와 함께 로드하십시오: \usepackage[margin=2.5cm]{geometry}, 또는 left/right/top/bottom를 하나씩, 양면 문서라면 inner/outer로요. TeX이 가정하는 1인치를 의도적으로 우회하는 게 아니라면 \oddsidemargin과 \topmargin을 손으로 잡지 마세요 — 그 셈을 대신 하라고 있는 패키지가 geometry입니다.
    LaTeX에서 두 배 줄간격은 어떻게 하나요?
    setspace를 로드하고 도입부에 \doublespacing을 쓰면 됩니다. 지침이 자주 요구하는 1.5배는 \onehalfspacing이 주고, 원하는 배율은 \setstretch{1.18}로 넣을 수 있습니다. 클래스가 이미 줄간격을 공급하고 있으므로 doublespace 값은 문자 그대로 2배가 아니며, 패키지는 캡션과 각주를 본문보다 빡빡하게 유지합니다.
    A4 용지는 어떻게 지정하나요?
    클래스 옵션 \documentclass[a4paper]{article}로도, geometry 키 \usepackage[a4paper]{geometry}로도 됩니다. 여백까지 함께 정한다면 geometry를 쓰세요. 용지와 상자, 출력 드라이버에 전해지는 크기까지 한꺼번에 맞춰 주지만, 클래스 옵션 홀로는 길이만 고칩니다.
    textheight와 textwidth는 무엇을 뜻하나요?
    둘은 본문 상자, 곧 TeX이 배치하는 유일한 직사각형의 높이와 너비입니다. 쪽의 나머지는 전부 그 상자 변까지의 거리이지요: 위쪽에는 \topmargin, \headheight, \headsep이, 아래쪽에는 \footskip이, 왼쪽에는 \oddsidemargin 또는 \evensidemargin이 놓입니다. 한 쪽에 들어가는 줄 수는 textheight를 baselineskip으로 나눈 값이고, 그래서 geometry에 heightrounded 옵션이 있습니다.
    LaTeX 쪽의 아래쪽이 거의 빈 채로 나오는 이유는?
    대개 자리를 못 잡은 플로트 때문입니다. TeX은 각 쪽의 최소 비율을 글(\textfraction)에게, 위와 아래에서 플로트가 쓸 최대 비율(\topfraction, \bottomfraction)을 정해 두기 때문에, 버티는 그림이 본문을 아래로 밀어냅니다. \topfraction과 \floatpagefraction을 살짝 올리거나 placeins 패키지의 \FloatBarrier로 그림을 옮기면 여백을 건드리지 않고 쪽들이 돌아옵니다.
    제목과 뒤따르는 글을 한 쪽에 붙이려면?
    먼저 공간을 요청하십시오. needspace 패키지의 \needspace{4\baselineskip}은 네 줄이 남아 있지 않으면 새 쪽을 시작합니다. 클래스는 이미 \@afterheading으로 제목을 뒤내용에 붙여 두므로, 쪽 마지막 줄에 고아 제목이 남는 사례는 거의 언제나 뒤 블록이 평범한 텍스트가 아니라 플로트나 표인 경우입니다.

    실시간 놀이터: LaTeX를 편집하고 바로 렌더링

    입력하면 미리보기가 즉시 갱신됩니다. 일부러 깨뜨려서 오류가 어떻게 보이는지도 확인해 보세요.

    KaTeX 오류
    예제 사용해 보기

    이어서 읽기

    같은 주제로 들어가는 세 갈래: 표기 자체, 그것을 가르치는 강의, 그리고 실제로 쓰는 글.