[Tex/LaTex] How to make invisible section header noticeable in the TOC

floatssectioningtable of contents

I used a nice solution from https://tex.stackexchange.com/a/68296/7435 to insert invisible section headers. However, my sections contain floats alone and invisible sectioning doesn't work properly. E.g., it sets all chapter's sections as having the same page in the TOC.

What could I put in the section to keep it visually clean (floats alone) and make the section appear in the TOC with the correct page number?

I have a common preamble:

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}
\usepackage[unicode=true,pdfusetitle,
 bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=3,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
 {hyperref}

\makeatletter
\newcommand\invisiblesection[1]{%
  \refstepcounter{section}%
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}%
  \sectionmark{#1}}

\makeatother

And two bodies.

One appears in the TOC:

\begin{document}
\tableofcontents{}\clearpage{}

\invisiblesection{One}

Line One.

\clearpage{}

\invisiblesection{Two}

Line Two.
\end{document}

The other one doesn't:

\begin{document}
\tableofcontents{}\clearpage{}

\invisiblesection{One}

\begin{figure}


\caption{\protect\includegraphics{logo}}


\end{figure}


\clearpage{}

\invisiblesection{Two}
\end{document}

Best Answer

In the former case there is some text where to anchor the "invisible" section. In the latter there isn't...

A way to circumvent this issue, if you really don't want to insert any text in the invisible section, is to insert a "phantom" text in its definition:

\makeatletter
\newcommand\invisiblesection[1]{%
  \refstepcounter{section}%
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}%
  \sectionmark{#1}\phantom{}}
\makeatother

MWE:

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}
\usepackage[unicode=true,pdfusetitle,
 bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=3,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
 {hyperref}
\usepackage[demo]{graphicx}

\makeatletter
\newcommand\invisiblesection[1]{%
  \refstepcounter{section}%
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}%
  \sectionmark{#1}\phantom{}}
\makeatother

\begin{document}
\tableofcontents{}\clearpage{}

\invisiblesection{One}

\begin{figure}


\caption{\protect\includegraphics{logo}}


\end{figure}


\clearpage{}

\invisiblesection{Two}
\end{document} 

Output (ToC):

enter image description here