0

Invisible subsections lose the page number in the TOC, more precisely, they all point to the same page, which is the page where the macro was first applied.

My need is similar to what was asked in make section headings invisible?

Therefore I experimented with the following macro, which I took from one of the answers given there and adapted.

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

Everything else works, except for the page numbering in the TOC. What can I do?

Edit: At your request I have written the example below. However, the behavior has changed here: The line numbers are now displayed correctly, but a blank page is inserted after each table.

\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
  • 2
    Welcome to TeX.SE! Could you extend your code fragment into an example that can be compiled please, starting with your \documentclass{} and ending with \end{document}, helps or is needed in some cases to trial solutions
    – JamesT
    Commented Mar 15, 2023 at 12:46

1 Answer 1

0

This code solves the problem using b! as a float location specifier for the tables.

When the ! is used as a modifier for the location specifier, it will override any restrictions of the default location rules for floats. With b! LaTeX will try harder to put the float at the bottom of the page.

The \clearpage command forces LaTeX to end the current page and start a new one. If there are any floats waiting to be placed, they will be placed on the new page according to the default placement rules. However, if you have used the "!" modifier, any floats that are waiting to be placed will to be placed at at the bottom of the float page.

See How to influence the position of floats

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}
2
  • Thank you very much for this ingenious simple solution. How much time such small mistakes cost the occasional writer is not justifiable. I hope that artificial intelligence will soon be available to TeX writers. Commented Mar 16, 2023 at 0:10
  • That I am not allowed to vote up the answer accepted by me is quite absurd. Sorry. Commented Mar 16, 2023 at 0:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .