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 would like to have a footer on every page containing the main section (always the name of the current \section, not \subsection) and the current page, e.g.

My section heading | 42

Bonus level: Pages with a \section should only contain the page, not the heading or |

This is what I've got so far. Not really what I want but at least a starting point.

\documentclass{scrartcl}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{fancyhdr}

\fancyhf{}
\renewcommand{\sectionmark}[1]{\markright{#1{\bfseries~|~}}}
\renewcommand{\subsectionmark}[1]{\markright{#1{\bfseries~|~}}}
\renewcommand{\subsubsectionmark}[1]{\markright{#1{\bfseries~|~}}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancyfoot[R]{\sffamily{\small\rightmark}{\bfseries\thepage}}

\pagestyle{fancy}

\begin{document}
\Blinddocument
\end{document}
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Here's one possibility using the titleps package:

\documentclass{scrartcl}
\usepackage{titleps}
\usepackage{etoolbox}
\usepackage{lipsum}

\newpagestyle{mystyle}{\setfoot{}{}{\sectiontitle~$\mid$~\thepage}}
\newpagestyle{mypage}{\setfoot{}{}{\thepage}}
\pagestyle{mystyle}
\makeatletter
\patchcmd{\section}{\@startsection}{\thispagestyle{mypage}\@startsection}{}{}
\makeatother

\begin{document}

\section{Test Section One}
\lipsum[1-20]
\section{Test Section Two}
\lipsum[1-20]
\end{document}

And here's the same, but with fancyhdr:

\documentclass{scrartcl}
\usepackage{fancyhdr}
\usepackage{etoolbox}
\usepackage{lipsum}

\fancyhf{}
\fancyfoot[R]{\rightmark~$\mid$~\thepage}
\renewcommand{\headrulewidth}{0pt}
\fancypagestyle{mypage}{
  \fancyhf{}
  \fancyfoot[R]{\thepage}
  \renewcommand{\headrulewidth}{0pt}
}

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

\makeatletter
\patchcmd{\section}{\@startsection}{\thispagestyle{mypage}\@startsection}{}{}
\makeatother

\pagestyle{fancy}

\begin{document}

\section{Test Section One}
\lipsum[1-20]
\section{Test Section Two}
\lipsum[1-20]
\end{document}
share|improve this answer
    
The fancyhdr approach doesn't print a section heading for me, only | 42 but I am absolutely happy with your titleps solution. Thank you so much! –  Matthias Nov 23 '12 at 10:02
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.