Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I used a nice solution from http://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}
share|improve this question
1  
You don't have a float placement specifier. Your floats are probably placed after your invisible sections therefore they ARE on the same page. To avoid this, use float placement specifiers (like [h!]) or load the placeins package and apply FloatBarriers. (To enhance the figure placement you might need to use resizebox from the graphicx package.) –  masu Dec 14 '13 at 19:53

1 Answer 1

up vote 7 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.