不可見的小節會遺失目錄中的頁碼

不可見的小節會遺失目錄中的頁碼

不可見的小節會遺失目錄中的頁碼,更準確地說,它們都指向同一頁面,也就是首次套用巨集的頁面。

我的需求類似 使章節標題不可見?

因此,我嘗試了以下宏,我從那裡給出的答案之一中獲取並進行了調整。

\makeatletter
\newcommand\invisiblesubsection[1]{%
    \refstepcounter{subsection}%
    \addcontentsline{toc}{subsection}{\protect\numberline{\thesubsection}#1}%
    \subsectionmark{#1}\phantom{}}%
\makeatother

除了目錄中的頁碼之外,其他一切都有效。我能做些什麼?

編輯:應您的要求,我編寫了下面的範例。但是,此處的行為發生了變化:行號現在可以正確顯示,但每個表後都會插入一個空白頁。

\documentclass[10pt,a4paper,oneside]{article}
\makeatletter
\newcommand\invisiblesubsection[1]{%
\refstepcounter{subsection}%
\addcontentsline{toc}{subsection} 
{\protect\numberline{\thesubsection}#1}%
\subsectionmark{#1}\phantom{}}%
\makeatother
\newcommand\tex{\textbf{(0)} \begin{tabular}[c]{c|rrrrrr}
$0$ & $0$ & & & & & \\ $0$ & $0$ & $0$ & & & & \\ $0$ & $0$ & $0$ & 
$0$ & & & \\ $0$ & $0$ & $0$ & $0$ & $0$ & & \\ $0$ & $0$ & $0$ & 
$0$ & $0$ & $0$ & \\ $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ 
\end{tabular} \vspace{5mm} \newline }
\begin{document}
\section{One}
\invisiblesubsection{1} 
\begin{table}[b] \tex \tex \tex \tex \tex \caption{1} \end{table}
\clearpage \invisiblesubsection{2} 
\begin{table}[b] \tex \tex \tex \tex \tex \caption{2} \end{table}
\clearpage \invisiblesubsection{3} 
\begin{table}[b] \tex \tex \tex \tex \tex \caption{3} \end{table}
\clearpage \invisiblesubsection{4} 
\begin{table}[b] \tex \tex \tex \tex \tex \caption{4} \end{table}
\clearpage \invisiblesubsection{5} 
\begin{table}[b] \tex \tex \tex \tex \tex \caption{5} \end{table}
\clearpage \newpage \tableofcontents\label{toc}
\end{document}

答案1

b!此程式碼使用表的浮動位置說明符解決了該問題。

!用作位置說明符的修飾符時,它將覆蓋浮點數預設位置規則的任何限制。使用b!LaTeX 會更努力地將浮動放在頁面底部。

\clearpage指令強制 LaTeX 結束目前頁面並開始新頁面。如果有等待放置的浮動元素,它們將按照預設的放置規則放置在新頁面上。但是,如果您使用了“!”修飾符,任何等待放置的浮動將放置在浮動頁面的底部。

如何影響浮標的位置

乙

\documentclass[10pt,a4paper,oneside]{article}
\makeatletter
\newcommand\invisiblesubsection[1]{%
    \refstepcounter{subsection}%
    \addcontentsline{toc}{subsection} 
    {\protect\numberline{\thesubsection}#1}%
    \subsectionmark{#1}\phantom{}}%
\makeatother
\newcommand\tex{\textbf{(0)} \begin{tabular}[c]{c|rrrrrr}
        $0$ & $0$ & & & & & \\ $0$ & $0$ & $0$ & & & & \\ $0$ & $0$ & $0$ & 
        $0$ & & & \\ $0$ & $0$ & $0$ & $0$ & $0$ & & \\ $0$ & $0$ & $0$ & 
        $0$ & $0$ & $0$ & \\ $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ 
    \end{tabular} \vspace{5mm} \newline }
\begin{document}
    \section{One}       
    \invisiblesubsection{1} 
    \begin{table}[b!] \tex \tex \tex \tex \tex \caption{1} \end{table}
    \clearpage \invisiblesubsection{2} 
    \begin{table}[b!] \tex \tex \tex \tex \tex \caption{2} \end{table}
    \clearpage \invisiblesubsection{3} 
    \begin{table}[b!] \tex \tex \tex \tex \tex \caption{3} \end{table}
    \clearpage \invisiblesubsection{4} 
    \begin{table}[b!] \tex \tex \tex \tex \tex \caption{4} \end{table}
    \clearpage \invisiblesubsection{5} 
    \begin{table}[b!] \tex \tex \tex \tex \tex \caption{5} \end{table}
    \clearpage \newpage \tableofcontents\label{toc}
\end{document}

相關內容