
在這份文件中\thepage
給我錯誤的號碼(在每頁的第一段)
\documentclass{article}
\textheight5\baselineskip
\begin{document}
test -\thepage-
test -\thepage-
test -\thepage-
test -\thepage-
test -\thepage-
test -\thepage-
test -\thepage-
test -\thepage-
test -\thepage-
test -\thepage-
test -\thepage-\\
test -\thepage-\\
test -\thepage-\\
test -\thepage-\\
test -\thepage-\\
test -\thepage-
test -\thepage-
\end{document}
答案1
在您的範例中,您有一個六行段落,而頁面中最多只能容納五行。
該段落已完全排版,然後將行(作為水平框)發送到“最近貢獻列表”並執行“頁面構建器”,即將最近貢獻中的材料移動到主垂直列表和 TeX進行內部計算以確定是否必鬚髮出分頁符號以及在何處發出分頁符號。
在這種情況下,顯然必須分頁,因此剛剛排版的段落的一部分將出現在頁面上n,而其他部分將出現在頁面上n+1。然而,所有\thepage
命令都已完全擴展到該值n沒有什麼可以改變這一點,因為該段落已經排版完畢。
如果您使用\pageref
,則頁碼將從收集的值中分配以前的LaTeX 運行,因此除非分頁符號同時發生更改,否則它們將是正確的。再次運行 LaTeX 將解決此問題。
您可以信賴的價值\thepage
僅有的緊接在\newpage
命令之後,因為這樣的命令可能會結束正在建置的段落並使 TeX 運行頁面建構器。
好吧,人們可以考慮邊緣情況,即使在這種情況下也不\thepage
可靠(例如大浮動)。