
次の例を考えてみましょう。
\documentclass{report}
\usepackage{lipsum}
\usepackage{longtable}
\begin{document}
\lipsum[1-4]
another paragraph
another paragraph
another paragraph
another paragraph
anoteher paragraph
another paragraph
another paragraph
%anoteher paragraph
%another paragraph
\begin{longtable}{lr}
\caption{long table}\\
A&B\\
c&D
\end{longtable}
\end{document}
コンパイルすると、長い表のキャプションは 1 ページに表示され、表自体は別のページに表示されます。
このような気まずい状況を避けるにはどうすればいいでしょうか?
回答にコメントする
\hline
キャプションの直後に使用すると、追加の問題が発生します。
\documentclass{report}
\usepackage{lipsum}
\usepackage{longtable}
\usepackage{needspace}
\begin{document}
\lipsum[1-4]
another paragraph
another paragraph
another paragraph
another paragraph
anoteher paragraph
another paragraph
another paragraph
%anoteher paragraph
%another paragraph
%\Needspace{5\baselineskip}
\begin{longtable}{lr}
\caption{some table}\\*
\hline
A&B\\
c&D\\
E&F
\end{longtable}
\end{document}
使用しても、\\*
初期状態に戻ります。
この問題は、行のコメントを外すことで解決できるようです。%\Needspace{5\baselineskip}
\Needspace
ただし、複数行のキャプションの場合は手動での調整が必要になるようです。
次の例を考えてみましょう。
\documentclass{report}
\usepackage{lipsum}
\usepackage{longtable}
\usepackage{needspace}
\begin{document}
\lipsum[1-4]
another paragraph
another paragraph
another paragraph
another paragraph
anoteher paragraph
%another paragraph
%another paragraph
%anoteher paragraph
%another paragraph
\Needspace{5\baselineskip}
\begin{longtable}{lr}
\caption{\lipsum[1][1-3]}\\*
\hline
A&B\\
c&D\\
E&F
\end{longtable}
\end{document}
結果は再び同じです:
このケースは、を に5
変更することで修正されます。\Needspace{5\baselineskip}
6
答え1
の後に\\*
の代わりにを使用することもできます。マニュアルより:\\
\caption
\\*
: と同じです\\
が、行の後の改ページは許可されません。
longtable
には見出しを制御するマクロがいくつかあります (マニュアルのセクション 3 を参照)。ユースケースに応じて、\endhead
またはを参照してください\endfirsthead
。次のコードは私の環境ではうまくいきます:
\documentclass{report}
\usepackage{lipsum}
\usepackage{longtable}
\begin{document}
\lipsum[1-4]
another paragraph
another paragraph
another paragraph
another paragraph
anoteher paragraph
\begin{longtable}{lr}
\caption{\lipsum[1][1-3]}\\
\hline
\endfirsthead
A&B\\
c&D\\
E&F
\end{longtable}
\end{document}
答え2
longtable
改ページが許容されないと判断する前に、少なくとも3行を表示したい場合、needspace
パッケージをロードしてディレクティブを発行することができます。
\Needspace{5\baselineskip}
の直前に置きます\begin{longtable}
。こうすることで、ページの下部に 5 行以上のテキストが残っていない限り、longtable
次のページの先頭から が始まります。
なぜでしょうか5\baselineskip
? ロングテーブルのキャプションと、キャプションと本文の先頭の間の空白行がさらに 2 行を占めるからです。