
考慮這個例子:
\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}
編譯時,長表的標題位於一頁上,而表本身位於另一頁:
我該如何避免這種尷尬的情況呢?
對答案發表評論
\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 行。