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.

Starting from the following code:

\documentclass{book}
\usepackage{lipsum}
\usepackage{fancyhdr}
\fancypagestyle{standardstyle}{%
    \fancyhf{}
    \fancyhead[RO]{\large\raisebox{.1cm}{\leftmark}}
    \fancyhead[LE]{\large\raisebox{.1cm}{\rightmark}}
    \fancyfoot[RE]{\thepage}
    \renewcommand{\headrulewidth}{0pt}
    \fancyfoot[LO]{\thepage}
    \renewcommand{\headrulewidth}{0pt}
}
\begin{document}
\pagestyle{standardstyle}
\renewcommand{\chaptermark}[1]{\markboth{\thechapter. #1}{}}
\chapter{test chapter}
\section{test section}
\subsection{test subsection}
   \lipsum\lipsum\lipsum
\end{document}

How can I put the subsection number and name into the even header instead of the section name?

share|improve this question
1  
novermind, found it, it's: \renewcommand{\subsectionmark}[1]{\thesubsection. \markright{#1}{}}. Still, could someone explain this code? –  Michelangelo May 16 at 20:27

1 Answer 1

The contents of \leftmark and \rightmark is determined by the commands \markboth and \markright, that usually are issued by sectioning commands such as \chapter or \section.

There is an additional level, though. When you do \chapter{Title}, among other things LaTeX issues \chaptermark{Title}; similarly \section{Title} and \subsectiontitle issue \sectionmark{Title} and \subsectionmark{Title}.

Usually the definition of \chaptermark contains \markboth{<code>}{} which sets the \leftmark to <code> (the second argument would set the \rightmark), while \sectionmark usually contains \markright{<code>}.

The standard definition of \subsectionmark is “do nothing”.

Thus, if you want the current subsection number and title in the header, you should define

\renewcommand{\subsectionmark}[1]{\markright{\thesubsection. #1}}

You probably should have also

\renewcommand{\sectionmark}[1]{\markright{\thesection. #1}}

in order not to have an empty header if there is no current subsection, but there is a current section.

share|improve this answer

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.