4

Alright, so I'm using fancyhdr with the default options. I have some sections, where I'd like it to appear different in the TOC. This is accomplished like so:

\section[test (in the TOC)]{test}

In the header made by fancyhdr, the section is shown in the same way as in the TOC (test (in the TOC)) and not the way it's shown at the section itself (test).

MWE:

\documentclass{article}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{0pt}
\setlength{\headheight}{15pt}

\begin{document}

\thispagestyle{empty}

\tableofcontents

\newpage

\section[test (in the TOC)]{test}

test

\end{document}

I'd like the header to say test not test (in the TOC).

2 Answers 2

4

You can change the mark by

\markboth{\thesection.\ test}{}

Code:

\documentclass{article}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{0pt}
\setlength{\headheight}{15pt}

\begin{document}

\thispagestyle{empty}

\tableofcontents

\newpage


\section[test (in the TOC)]{test}
\markboth{\thesection.\ test}{}


test

\end{document}

enter image description here

1
  • Perfect! Just what I needed.
    – Argo
    Commented Dec 12, 2014 at 13:28
2

An alternative would be to switch to a class with this feature built in.

The appearence is a bit different, KOMA-script aims to provide nice defaults for the non-north-american world.

\documentclass[headings=optiontotoc]{scrartcl}
\usepackage[automark]{scrlayer-scrpage}%KOMA-budle
\usepackage{blindtext}
\begin{document}
\tableofcontents
\clearpage
\section[test (in the TOC)]{test}
\blindtext
\end{document}

You must log in to answer this question.

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