# Including section titles in fancyhf headers

I would like to include the section name of the page's displayed section in my header tags in the fancyhdr package, something like

\fancyhf[HR]{SECTION NAME}
\fancyhf[HL]{SUBSECTION NAME}


How can I go about doing this?

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – Speravir Mar 21 '14 at 4:40

titleps provides this out-of-the-box and is not that different in interface/usage from fancyhdr. You might be interested in reading titleps for fancyhdr users.

If you wish to do this straight with fancyhdr, you'll have to patch the sectional unit constructions to store the titles, or use the title marks with some massaging.

You would use

\usepackage{titleps}% http://ctan.org/pkg/titleps
\newpagestyle{main}{
{}%                 center
{\sectiontitle}%    right
}
\pagestyle{main}


Here's a very minimal example with the addition of the sectional unit number as well:

\documentclass{article}
\usepackage{titleps}% http://ctan.org/pkg/titleps
\newpagestyle{main}{
{}%                                 center
{\thesection\ \sectiontitle}%       right
}
\pagestyle{main}
\begin{document}
\section{A section}
\subsection{A subsection}
\subsubsection{A subsubsection}
\end{document}

• Thank you! This is exactly the answer I was looking for. I will upvote you when I have the reputation to do so. – encircled Mar 26 '14 at 2:15

I use the fancyhdr package for this task. I usually prepare several new commands to have full control of what will be shown in the header and footer. I enclose a small demonstration.

\documentclass[a4paper]{article}
\parindent=0pt
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}