I have a (onesided) document with fancyhdr and pagestyle fancy so it displays the section-title on the right header and the subsection-title on the left header. If section and subsection titles are lengthy they start to overlap each other.
Example:
\documentclass[a4paper,10pt]{scrartcl}
\usepackage[utf8x]{inputenc}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\begin{document}
\section{some section with quite a lengthy title}
\lipsum
\subsection{very very very long title of subsection}
\lipsum
\end{document}
I know of two solutions:
-
give short section/subsection headings like in
\documentclass[a4paper,10pt]{scrartcl} \usepackage[utf8x]{inputenc} \usepackage{lipsum} \usepackage{fancyhdr} \pagestyle{fancy} \begin{document} \section[short section]{some section with quite a lengthy title} \lipsum \subsection[short subsection]{very very very long title of subsection} \lipsum \end{document}
I don't like this because I don't want to have the short version in my toc.
-
use
\sectionmark
like in\documentclass[a4paper,10pt]{scrartcl} \usepackage[utf8x]{inputenc} \usepackage{lipsum} \usepackage{fancyhdr} \pagestyle{fancy} \begin{document} \section{some section with quite a lengthy title} \sectionmark{short section} \lipsum \subsection{very very very long title of subsection} \subsectionmark{short subsection} \lipsum \end{document}
But this just doesn't work right – the short subsection mark is not obeyed on page 2, but is used correctly on page 3. That feels just really wrong.
So, how can I make version 2 work 'right'?
Best Answer
This is answered in the TeX FAQ. On the left-hand pages the text used in the title is that of the first mark on the page, so your
\subsectionmark
is coming too late. This can be solved by adding this command again in the title itself:Because of the way the writing to the table of contents works you will also have to add the full title to the optional argument of the
\(sub)section
command, as above. As this is rather clumsy, it is reasonable to introduced commands such as\markedsection
to achieve this:For the standard cases, you can still use the ordinary commands.
If your are prepared to switch to the
memoir
class, then you will have sectioning commands that help this proceedure as they have two optional arguments: one for the head and one for the table of contents.