3

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
3

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}{
\setheadrule{.4pt}% Header rule
\sethead{\subsectiontitle}% left
        {}%                 center
        {\sectiontitle}%    right
}
\pagestyle{main}

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

enter image description here

\documentclass{article}
\usepackage{titleps}% http://ctan.org/pkg/titleps
\newpagestyle{main}{
\setheadrule{.4pt}% Header rule
\sethead{\thesubsection\ \subsectiontitle}% left
        {}%                                 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
0

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{}
\fancyhead[L]{\myleft}
\fancyhead[C]{\thepage}
\fancyhead[R]{\myright}
\def\tomyleft#1{\def\myleft{#1}}
\def\tomyright#1{\def\myright{#1}}
\def\mysection#1#2{\section{#1}\tomyleft{#2}}
\def\mysubsection#1#2{\subsection{#1}\tomyright{#2}}
\begin{document}
\mysection{Welcome}{My welcome\ldots}
\mysubsection{Hello World!}{\ldots My Hello World!}
My first page.\newpage 
My second page.
\end{document}

page 1

page 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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