Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

  1. 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.

  2. 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'?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

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:

\documentclass[a4paper,10pt]{scrartcl}
\usepackage[utf8x]{inputenc}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}
\tableofcontents

\section[some section with quite a lengthy title]{some section with quite 
a lengthy title%
\sectionmark{short section}}
\sectionmark{short section}
\lipsum

\subsection[very very very long title of subsection]{very very very long
title of subsection%
\subsectionmark{short subsection}}
\subsectionmark{short subsection}

\lipsum

\end{document}

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:

\documentclass[a4paper,10pt]{scrartcl}
\usepackage[utf8x]{inputenc}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}

\newcommand{\markedsection}[2]{\section[#2]{#2%
\sectionmark{#1}}
\sectionmark{#1}}

\newcommand{\markedsubsection}[2]{\subsection[#2]{#2%
\subsectionmark{#1}}
\subsectionmark{#1}}

\begin{document}
\tableofcontents

\markedsection{short section}{Some section with quite a lengthy title}

\lipsum

\markedsubsection{short subsection}{Very very very long title of subsection}

\lipsum

\end{document}

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.

share|improve this answer
    
Thanks for your answer. I stumbled across that faq before, but i did not read it very carefully so i did move my \subsectionmark{} into the \subsection{} instead of repeating it. This lead to a fatal error on compilation. –  Sunday Jan 23 '13 at 14:39
    
Another thing I would like to point out is the need to also repeat the long version of the title as an optional argument (as stated in aforementioned faq) in order to not confuse things for the table of contents if there is one. If one puts everything together one has to repeat both titles: \subsection[very very very long title of subsection]{very very very long title of subsection\subsectionmark{short subsection}} \subsectionmark{short subsection} –  Sunday Jan 23 '13 at 14:42
    
@Sunday Thank you for pointing out the error. It is now fixed, and some macros provided. –  Andrew Swann Jan 23 '13 at 18:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.