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

share|improve this question
1  
Do you use twoside mode? Do you use the article document class? Do you use hyperref? Please create a minimal working example (MWE). –  Werner Jan 23 '13 at 19:20
add comment

1 Answer

up vote 3 down vote accepted

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

share|improve this answer
    
Great, it works. Thanks very much, Werner. Your example is wonderful, too –  fpiro07 Jan 24 '13 at 17:42
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.