段階 2 · テキストと文書構造 16 / 48 ≈ 20 分で読める

LaTeX のページレイアウト:余白・用紙サイズ・行送り

LaTeX でページを整えるとは、本文ブロックという箱を紙の上に置く作業です。TeX が知るのはその箱だけで、他はすべて紙の端から箱の辺までの距離——しかも TeX が勝手に仮定する 1 インチを差し引いた位置から測られます。この課では縦横に積もる長さの列、geometry のキーが実際に書き換えるレジスタ、用紙サイズと出力ドライバの噛み合い、行送りの仕組みとパッケージ、両面組で内側・外側が分かれる理由、そして頁の終端を数値で決める罰則までを順に追います。

    ページは箱の積層で、TeX が組むのはそのひとつだけ

    TeX が認識しているのは本文ブロックという矩形ただ一つで、寸法は \textwidth かける \textheight、二段組ではその間隔を \columnsep が決めます。用紙サイズもヘッダーもフッターも余白注釈も、この箱からの距離という形でしか書けません。文書のレイアウトが描き込み式のキャンバスではなく長さの束でしかないのはそのためで、レイアウト用パッケージは 5 つの数字から頁全体を組み直せてしまうのです。

    横では、紙の左端から本文ブロックの左辺までが 1in + \hoffset + \oddsidemargin、両面組の偶数頁なら \evensidemargin に読み替わります。縦は天からヘッダー箱のトップまでが 1in + \voffset + \topmargin、続いて \headheight、\headsep、本文ブロック本体、そして \footskip。ただしこれは箱の下端からの距離ではなく、本文最後の基準線からフッターの基準線まで測ります。

    この 1 インチこそ LaTeX の頁寸法でもっとも誤解されている定数で、由来は TeX が「1 インチ内側へ下げた仮想の紙」に組ませている前提まで遡ります。\oddsidemargin=0pt は紙端から 0 とは読まれず 25.4mm 内側です。手当て法で余白を据える人が例外なく 1 インチを差し引いてから数字を書き、古いクラスファイルやテンプレートが負の値を足し込みたがるのも、相手はみなこの定数です。

    触る前に知っておきたい帰結として、縦の部品を足した値が紙を超えても TeX は幾何そのものを咎めず、はみ出した頁ごとに文句を言います。ログに出るのは badbox を含む行、たとえば Height too large や大きな 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 の一組で、自分専用の組版を持つ領域を括り出せます——横長表の 1 頁、横向きに置く図、行幅を絞りたい詩など。\newgeometry は \clearpage を先に出すので、領域は必ず次の頁の頭から始まります。今ある行から切り替わると踏んでいる人はここで驚きます。

    \savegeometry{wide} と \loadgeometry{wide} は設定に名前を付ける組で、長い付録なら六つのキーをそのつど並べ替える代わりに既知の二状態を往復できます。変更が差分にも読める形になるので、設計としてレイアウトを書くことと、頁との押し合いにレイアウトが化けることの違いがここに現れます。

    手に入ったものを確かめる道具は三つ。showframe は本文ブロック・ヘッダー・フッター・余白注釈箱・紙の端まで罫で引いてくれるので、何がなぜその位置にあるのかを突き止める最速の手段です。layout パッケージは注釈付きの擬似頁(\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 のキーでもあり、両方に書いた場合は後者が優先です。どちらの経路でも \paperwidth と \paperheight は立ちますが、余白まで計算し直すのは geometry 側で、クラスオプションだけでは長さだけ動きます。

    長さ二本を立てるのは出力ドライバへの指示と同じことではありません。pdfTeX は自分のプリミティブ(\pdfpagewidth、\pdfpageheight)からメディアボックスを書き、dvips 系は papersize の special に従います。ここがずれると画面では正しく印刷すると切れる文書、あるいは letter 紙の真ん中に A4 の本文が居座る文書ができる。geometry へ任せてしまえばドライバ側も面倒を見てくれ、paper=/a4paper は長さとドライバ寸法を同時に立て、自動判定が外れた時のために pdftex、xetex、luatex、dvips、dvipdfm も受け付けます。

    決定の半分はクラス側の話です。出版社や大学がクラスファイルを配っている場合、ブロックも行送りも多くの場合フォントまで既に決められており、a4paper を渡すのか \geometry を使うのかはそのクラスの文書に書いてあります。自前の 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 がするのは乗数を退避するだけで、新しい値は次にサイズが選ばれる瞬間に反映されます。\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.
    一本の基準線から次へ至る距離をどのレジスタが握り、行が高くなった時に誰が乗り出すかの図。

    両面組、走り見出し、余白の注釈

    twoside の文書は本文の居場所が二通りあるため、クラスは \oddsidemargin と \evensidemargin を別々に尋ね、geometry の語彙では inner と outer になります。分けておく理由は、組版的には製本にあります。親指と押し合いになるのはノド側なのでそちらを大きく取ります。綴じた本で左右対称の余白にすると、読み味は詰まった方に落ちつくのです。糊しろとして具体的な数値を求められたら bindingoffset=10mm を足す側が正解です。

    走り見出しは \markboth{left-side text}{right-side text}(あるいは \markright)で受け渡し、\pagestyle{headings} がそれを読み取って章と節の見出しで埋めます。両面組では左頁に章、右頁に節というのがならわしで、両方の mark を毎回書くのはそのため。fancyhdr の \fancyhead[LE,RO]{\nouppercase{\leftmark}} 型のスロットで書き換えるのが筋の通った改め方です。あの有名な警告 headheight is too small (12.0pt) は邪魔者ではなく、確保済みの箱にヘッダーの中身が収まっていないという報告で、直しかたは geometry へ headheight=14pt を足すこと。本文ブロックごと下がります。

    余白注釈は自分専用の三つの長さを持つ箱で、それが \marginparwidth、\marginparsep、\marginparpush。両面組では使える幅が左右で違うので、奇数頁で収まった注釈が偶数頁では吊り下がることもあります。素の \marginpar は現在の行へ注釈を置く衝突の元で、marginnote は行折り返しに左右されず置き、marginfix は並び直して重なりを止めます。KOMA-script なら \marginline{...} が合わせ込みまで引き受けてくれます。

    本文と余白注釈を同じ縦位置に、しかも余白側にも本物の段落を置きたいなら、それはもう別のレイアウト、すなわち Tufte 流です。担当者も 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} と本文の一行を眺める方が、余白についての持論よりも良い設計道具なのはそのためです。行長が長すぎるときの解はブロックの幅か二段組(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} は四辺まとめて 2.5cm という意味で、細かく分けるなら left/right/top/bottom を一辺ずつ書き、綴じる側の文書なら inner/outer を使います。\oddsidemargin と \topmargin を手で置くのは、TeX が仮定する 1 インチをわざと捌きに行く場合に限ってください。geometry はあの算数を代わりにやるためにあるパッケージです。
    LaTeX で二倍行間にするには?
    setspace を読んで、前置きに \doublespacing を書けば済みます。多くの規定が求める 1.5 行分は \onehalfspacing、好きな倍率は \setstretch{1.18} が担当します。クラスが行送りを既に供給しているため、ここでの二倍は文字どおりの 2.0 倍ではなく、キャプションと脚注は本文より締まった間隔に保たれます。
    A4 用紙に設定するには?
    クラスオプションに \documentclass[a4paper]{article} と書くか、読み込み時のキーに \usepackage[a4paper]{geometry} と書くか、どちらでも構いません。余白も同時に決めるなら geometry 側を使ってください。用紙と本文ブロックをまとめて動かし、出力ドライバへも正しい寸法を渡します。クラスオプションだけでは長さだけが変わります。
    textheight と textwidth は?
    TeX が組む唯一の矩形、つまり本文ブロックの高さと幅です。頁の他はすべてそこからの距離で、上側が \topmargin、\headheight、\headsep、下側が \footskip、左が \oddsidemargin または \evensidemargin。一頁に収まる行数は textheight を baselineskip で割った値になるため、geometry には heightrounded という選択肢まで用意されています。
    頁の下がほぼ空白になってしまうのは?
    たいていは配置先を失ったフロートのせいです。TeX はテキスト用の最低割合(\textfraction)と天・地のフロート上限(\topfraction、\bottomfraction)を守るため、頑固な図が本文を押し下げます。\topfraction と \floatpagefraction を少し上げる、または placeins の \FloatBarrier で図を誘導すれば、余白に手を触れずに直せます。
    見出しを直後の本文に貼り付けておくには?
    見出しの前で空きを要求します。needspace の \needspace{4\baselineskip} は、4 行分が揃っていれば同じ頁に置き、無ければ先に新頁を作ります。クラスは \@afterheading で見出しを後続の本文へ既に結び付けているので、頁末に孤児化した見出しは、うしろの塊がテキストでなくフロートや表であるケースがほとんどです。

    ライブ playground:LaTeX を編集して即描画

    入力すると即座にプレビューが更新されます。わざと壊してエラーの見た目も確認しましょう。

    KaTeX エラー
    例を試す

    続けて読む

    同じ話題への三つの入口:記法そのもの、それを教える課、そして実際に使っている記事。