[Tex/LaTex] section to tableofcontents update

chapterssections-paragraphstable of contents

I'm using the following structure:

\section[short chapter]{my long long long long section}

I would like to use the long section name in my table of contents, because the short chapter is now used there. Is this possible?

UPDATE

My chapter and section overlap in my header, I'm using a fancyhead in a report style. As a solution I found the structure I described above to make a shorter chapter. That resulted in a shorter table of contents line. Now, I want to use the long long long section for my table of contents.

Best Answer

The following might be sufficient for your needs. It provides an additional, optional argument for \section that is used for typesetting the header in a similar way to the interface provided by memoir:

\documentclass[twoside]{report}

\usepackage{lipsum}% Just for this example
\usepackage{xpatch}

\let\oldsection\section
\RenewDocumentCommand{\section}{s o o m}{%
  \markright{}% Clear right mark
  \IfBooleanTF{#1}
    % \section*
    {\IfNoValueTF{#2}
       % \section*
       {\IfNoValueT{#3}
          % \section*{...}
          {\oldsection*{#4}}
       }
       % \section*[.]
       {\oldsection*{#4}%
       \addcontentsline{toc}{section}{\protect\numberline{}#2}%
       \IfNoValueF{#3}
          % \section*[.][..]{...}
          {\markright{#3}}
       }
    }
    % \section
    {\IfNoValueTF{#2}
       % \section
       {\oldsection{#4}}
       % \section[.]
       {\oldsection[#2]{#4}
        \IfNoValueF{#3}
          % \section[.][..]{...}
          {\markright{#3}}
       }
    }
}

\pagestyle{headings}
\sloppy% Just for this example

\begin{document}

\tableofcontents

\chapter{A chapter}
\lipsum[1-20]

\section{A section}
\lipsum[1-20]

\section[ToC entry][Header entry]{Another section}
\lipsum[1-20]

\section*{A starred section}
\lipsum[1-20]

\section*[Starred ToC section]{Another starred section}
\lipsum[1-20]

\end{document}

You can use

\section[*][<ToC>][<header>]{<title>}

Of course, some conditioning is not necessary, as you can't have only the second optional argument and not the first (using the default [..] notation).

Related Question