Las subsecciones invisibles pierden el número de página en el TOC

Las subsecciones invisibles pierden el número de página en el TOC

Las subsecciones invisibles pierden el número de página en el TOC; más precisamente, todas apuntan a la misma página, que es la página donde se aplicó la macro por primera vez.

Mi necesidad es similar a lo que me preguntaron en ¿Hacer invisibles los títulos de las secciones?

Por lo tanto, experimenté con la siguiente macro, que tomé de una de las respuestas allí dadas y la adapté.

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

Todo lo demás funciona, excepto la numeración de páginas en el TOC. ¿Qué puedo hacer?

Editar:A petición suya, he escrito el ejemplo a continuación. Sin embargo, el comportamiento ha cambiado aquí: los números de línea ahora se muestran correctamente, pero se inserta una página en blanco después de cada tabla.

\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}

Respuesta1

Este código resuelve el problema utilizando b!como especificador de ubicación flotante para las tablas.

Cuando !se utiliza como modificador para el especificador de ubicación, anulará cualquier restricción de las reglas de ubicación predeterminadas para los flotantes. Con b!LaTeX se esforzará más en poner el flotador al final de la página.

El \clearpagecomando obliga a LaTeX a finalizar la página actual y comenzar una nueva. Si hay flotadores esperando a ser colocados, se colocarán en la nueva página de acuerdo con las reglas de colocación predeterminadas. Sin embargo, si ha utilizado el "!" modificador, cualquier flotador que esté esperando ser colocado se colocará en la parte inferior de la página flotante.

VerCómo influir en la posición de los flotadores.

b

\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}

información relacionada