5

I am working on my own recipe collection. I want to add sections to the TOC and maybe have them in the running head but I do not want them to be printed to the body of the page at all. Each page shall only display a recipe. The typical commands \section or \addsec do not have such functionality. The always print the section title to the body.

Is there such a command or is it necessary to create that on my own?

1 Answer 1

12

Something like this?

enter image description here

Code

\documentclass[a5paper]{article}
\usepackage[colorlinks]{hyperref}

\begin{document}
\tableofcontents
\newpage

\phantomsection
\addcontentsline{toc}{section}{Recipe 1}
This is recipe 1
\newpage

\phantomsection
\addcontentsline{toc}{section}{Recipe 2}
This is recipe 2
\newpage

\end{document} 

EDIT

In order to achieve what you've requested in the comment, you can modify the above code as follows (hope I haven't misunderstood)

\documentclass[a5paper]{article}
\usepackage[colorlinks]{hyperref}

\begin{document}
\tableofcontents
\newpage

\phantomsection
\stepcounter{section}
\addcontentsline{toc}{section}{\protect\numberline{\thesection}Recipe 1}
This is recipe 1
\newpage

\phantomsection
\stepcounter{section}
\addcontentsline{toc}{section}{\protect\numberline{\thesection}Recipe 2}
This is recipe 2
\newpage

\end{document} 

Output:

enter image description here

Something like

\newcommand{\invisiblesection}[1]{%
  \phantomsection%
  \stepcounter{section}%
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}%
  }

to be used as

\invisiblesection{Recipe 1}

could be useful...

2
  • No, I want them to be numbered as if they were normal section. I have chapters that are printed. And I want to add tocs for each chapter, so I need the normal numbering. Nov 24, 2013 at 20:05
  • It works, however the formatting is different to the format that koma-script uses. The default section has a visible separation between number and text which the new section command does not have. That is why I would rather reuse existing commands to preserve the formatting. Nov 25, 2013 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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