Generalfancyhdr: long titles in toc and short one in headers

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
toufalk
Posts: 1
Joined: Tue Apr 15, 2008 12:07 pm

fancyhdr: long titles in toc and short one in headers

Post by toufalk »

Hello World :mrgreen:

It's the first time that i post something on an English forum...

Here is my problem:
I use fancyhdr for my headers and footers. I have long titles for chapters and sections.
So with \pagestyle{fancy}, they mix in the headers.

The solution for that is to use \section[short]{very very long}.
But then, the short title appears in the table of contents... and i want to see the long title here!

I tried

Code: Select all

\let\stdsection=\section
\renewcommand{\section}[2][]{%
    \ifthenelse{\equal{#1}{}}
        {}
        {\sectionmark{#1}}%
    \stdsection{#2}%
    \ifthenelse{\equal{#1}{}}
        {}
        {\sectionmark{#1}}%
    }
This works fine for section, but not for chapter... and \section*{} don't work properly!

There's also this

Code: Select all

\newcommand{\mychapter}[2][]{%
    \ifthenelse{\equal{#1}{}}
        {}
        {\chaptermark{#1}}%
    \chapter{#2}%
    \ifthenelse{\equal{#1}{}}
        {}
        {\chaptermark{#1}}%
    }
But I have to modify all the chapter into mychapter...

all this is not very convincing.
Any idea to help me ??

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10347
Joined: Mon Mar 10, 2008 9:44 pm

fancyhdr: long titles in toc and short one in headers

Post by Stefan Kottwitz »

Hi toufalk,

welcome to the board!
One idea for \chapter:

Code: Select all

\makeatletter
\newcommand*\std@chapter{}
\let\std@chapter=\@chapter
\renewcommand*\@chapter[2][]{\std@chapter[#2]{#2}\chaptermark{#1}}
\makeatother
Stefan
texuser
Posts: 1
Joined: Wed Apr 30, 2008 11:02 am

Re: fancyhdr: long titles in toc and short one in headers

Post by texuser »

Thank you! This works great for me!
arnoques
Posts: 3
Joined: Sun Oct 19, 2008 7:23 am

Re: fancyhdr: long titles in toc and short one in headers

Post by arnoques »

Thank you both! Those codes were very useful, as I had the same problem.
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: fancyhdr: long titles in toc and short one in headers

Post by daleif »

why don't you just use the memoir class instead. It is a lot easier to use than the standard classes and includes the functionality of some 40+ packages, all documented in one manual.

In memoir we use

\chapter[toc][header]{text}

just one optional sends both to header and toc, and no optional sends text to all three.

It is a better investment to go away from the standard classes.
Post Reply