更改頁碼樣式比預期早一頁?

更改頁碼樣式比預期早一頁?

我希望我的報告的前幾節採用羅馬編號(i、ii、iii...),報告正文的頁碼採用阿拉伯編號(1、2、3...)。

問題是切換發生的時間似乎比我對程式碼的預期早了一個頁面:

\documentclass{report}
\begin{document}
% === Abstract etc ===
\pagenumbering{roman}
\section*{first section}
Want this to be page i
\pagebreak
\section*{second section} 
Want this to be page ii, but it appears as 1 instead
\pagebreak
% === Body of report ===
\pagenumbering{arabic} %change to arabic for final page
\section*{third section}
Want this to be page 1, but it appears as 2 instead
\section*{fourth section}
\end{document}

我可以看到,如果我將命令放在\pagenumbering{arabic}第三部分下面的行上,那麼它可以解決問題,但這很不方便,因為如果我有一個模組化文件並註解掉一個部分,那麼我必須不斷更改\pagenumbering{arabic}.

% === Body of report ===此外,如果我在它修復我的 MWE 中的問題之前放置一個換行符(但由於某種原因不是我的實際報告)。對這種行為非常困惑。

這是一個錯誤嗎?有解決辦法嗎?

答案1

\pagebreak當在段落內或段落之間(即前面有一個空行)給出該命令時,該命令的工作方式有所不同。

在您的情況下,第二個\pagebreak屬於具有文本的段落

Want this to be page ii, but it appears as 1 instead

只有在段落被分成幾行之後它才會生效,這種情況發生在 LaTeX 掃描\section*{third section}並且已經將頁碼更改為時arabic

不要害怕留下空行,但可以\clearpage在這樣的情況下使用;這樣的指令會結束目前段落(如果前面沒有空白行),因此它解決了問題。

\documentclass{report}

\begin{document}

% === Abstract etc ===
\pagenumbering{roman}

\section*{first section}

This is page i

\clearpage


\section*{second section} 

This is page ii

\clearpage

% === Body of report ===
\pagenumbering{arabic} %change to arabic for final page

\section*{third section}

This is page 1


\section*{fourth section}

\end{document}

\pagebreak和之間還有另一個區別\clearpage:如果\flushbottom有效(它在book類別中),\pagebreak將嘗試用可用文字填充頁面,而\clearpage用空白填充頁面。

so\pagebreak最好用於微調分頁符,而\clearpage或 則\cleardoublepage在請求「在此結束頁面」時使用。

相關內容