3

I have the following section title:

\subsection[Einfluss auf das Standardfranz.]{Einfluss auf das Standardfranzösisch}\label{standardFranz}

The text between the [...] is shorter, because I need a shorter title in the header of the page.

This works fine but I need the full section title to be in the table of contents. How can I achieve this? At the moment it takes the text between the [...] for the table of content but I want it to take the text between the {...}.

  • What \documentclass are you using? Are you using fancyhdr? – Werner Sep 20 '16 at 19:15
3

You can momentarily avoid your \sectioning to set the usual \sectionmark and then set it yourself manually just after the section:

enter image description here

\documentclass{article}

\usepackage{lipsum}
\pagestyle{headings}
\newcommand{\gobble}[1]{}% Similar to \@gobble

\begin{document}

\tableofcontents

\lipsum[1-7]

{\let\sectionmark\gobble% Avoid setting \sectionmark
\section{A section}}% Set \section
\sectionmark{A different sectional heading}% Set actual mark
\lipsum[1-20]

\end{document}

We group the placement of the \section together with a \gobble of the \sectionmark.

  • Now I got one problem. If I use \label{test} and later ~\ref{test} then the link works well, but the number of the chapter shown in the ref is in my case 2.6 but in real it is 2.7. Do you know how to fix that? – texNewbie Sep 21 '16 at 19:06
  • 1
    @texNewbie: You should place \label{test} immediately after \section{..} and still within the group. – Werner Sep 21 '16 at 19:11
2

This is one of the defects in the standard classes: in my opinion, the short title (optional argument to the sectional commands) should only be used for the headers, not for the table of contents.

Here's a set of patches for the standard classes (article, report and book). Other classes, such as memoir or KOMA have their own methods for solving the problem.

\documentclass{book}
\usepackage{etoolbox}
\usepackage{lipsum} % just for the example

\makeatletter
% the following three lines only if the class is report or book
\patchcmd{\@chapter}{#1}{#2}{}{} % #1 is the optional argument
\patchcmd{\@chapter}{#1}{#2}{}{} % #2 is the mandatory argument
\patchcmd{\@chapter}{#1}{#2}{}{}
%%%
\patchcmd{\@sect}{\fi#7}{\fi#8}{}{} % #7 is the optional argument
\patchcmd{\@sect}{\fi#7}{\fi#8}{}{} % #8 is the mandatory argument
\makeatother

\begin{document}

\tableofcontents

\chapter[Short chapter title]{A long long chapter title}

\section[Short title]{A long long section title}

\lipsum[1-20]

\end{document}

Here is a picture of the TOC:

enter image description here

Here is a picture of the headers:

enter image description here

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.