5

I'd like to make the headings of my article look like this:

<Section name>                        <Subsection number> <Subsection name> | <Page number>

and I wrote this code:

\pagestyle{fancy}

\fancyhf{}

\lhead{\fancyplain{} {\sectionmark}}
\rhead{\fancyplain{} {\subsectionmark} $|$ \thepage}
\renewcommand{\headrulewidth} {0pt}
\renewcommand{\footrulewidth} {0pt}

But it just doesn't show the names of sections and subsections.

This is what I get:

                                                                            | 2

How can I fix it?

1
4

For capturing the section unit titles and have fancyhdr-style headings, Javier Bezos' titleps package provides an easy alternative:

enter image description here

\documentclass{article}
\usepackage{titleps,lipsum}% http://ctan.org/pkg/{titleps,lipsum}
\newpagestyle{main}{%
  \setheadrule{0pt}%
  \sethead{\sectiontitle}                                 % header left
    {}                                                    % header center
    {\thesubsection~\subsectiontitle\quad$|$\quad\thepage}% header right
}
\pagestyle{main}
\begin{document}
\section{A section}\lipsum[1-2]
\subsection{A subsection}\lipsum[3-4]
\subsection{Another subsection}\lipsum[5-6]
\subsection{A subsection}\lipsum[7-8]
\subsection{Another subsection}\lipsum[9-10]
\section{Another section}\lipsum[1-2]
\subsection{A subsection}\lipsum[3-4]
\subsection{Another subsection}\lipsum[5-6]
\subsection{A subsection}\lipsum[7-8]
\subsection{Another subsection}\lipsum[9-10]
\end{document}

Within twoside mode, you could use

\sethead[<even-left>][<even-center>][<even-right>]
  {<odd-left>}{hodd-center>}{<odd-right>}
\setfoot[<even-left>][<even-center>][<even-right>]
  {<odd-left>}{<odd-center>}{<odd-right>}

for setting different headers/footers on even/odd pages.

You have to decide which \subsection to include in your headers. titleps uses the last-defined sectional heading. However, see the titleps documentation for more options (section 4. Marks, p 4 onwards).

1
  • Great, it works. Thanks very much, Werner. Your example is wonderful, too
    – fpiro07
    Jan 24 '13 at 17:42

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.