# How does scrpage2's automark work?

I'm trying to define a header style for my paper based on the scrartcl class. After digging through some documentation I came along the scrpage2 package to create the headings. I get the layout as I want it, which is great, but I don't get the automark command. It puts in a heading, which is great, but it seems strange.

By strange I mean that it puts Contents as the header for Contents, which is what I expect, but on the next page (notice the \vfill and \pagebreak) it puts 3 Third as the heading, which is not what I expected.

I expect it to put the very first section or subsection it finds on a page in the header.

Have I misunderstood how the automark command works or do I need to put in extra options? (Like \automark[subsection]{section})

EDIT: Double weird: it works when I replace all \sections in the example with a \blinddocument. I'm sorry I am so unclear, though, I just have no clue at all.

\documentclass[twoside,titlepage=true]{scrartcl}
\usepackage[]{geometry}

\usepackage[english]{babel}
\usepackage{blindtext}

\usepackage[automark]{scrpage2} % This should be set AFTER setting up the page geometry

\begin{document}

\title{A Minimal Working Example}
\author{Zsub}

\maketitle

\tableofcontents
\vfill
\pagebreak

\section{First}
\blindtext[2]
\section{Second}
\blindtext[2]
\section{Third}
\blindtext[2]
\section{Fourth}
\blindtext[2]
\subsection{First of Fourth}
\blindtext[1]
\section{Fifth}
\blindtext[2]
\section{Sixth}
\blindtext[2]
\end{document}


P.S. It's been a few years since I last used latex and a bit of a struggle to get re-acquainted, but my classmates are already jealous of the layout. So thanks for the help, everyone!

Page headings in Latex are given in terms of "left marks" and "right marks". Typing \markboth{left}{right} means that the heading on the left (even) page should be left, and the heading on the right (odd) page should be right, from now until it is changed again.

If more than one \markboth happens on the same page, then Latex takes the last left mark and the first right mark. You can see this behavior in the following example:

\documentclass[twoside]{article}
\begin{document}

This is the first page
\markboth{left1}{right1}\markboth{left2}{right2}\newpage

This is the second page
\markboth{left3}{right3}\markboth{left4}{right4}

\end{document}


To answer your question, then: automark sets it up so that calling new chapters and sections automatically calls \markboth (or equivalent). In your case, sections are being put on the left page as the left mark, and this is why you see what you do.

The key to changing this is the command

\automark[right side]{left side}


One thing you might want to do is just put sections on the odd pages and the author on even pages. You could accomplish this by

\automark[section]{section} % section at top of every page
\lehead{Zsub}               % but overwrite even pages with the author


Of course, you could put anything you want inside lehead. If you really want to put the section at the top of every page you can use the right mark on the left page.

\automark[section]{section}

For more information on automark, lehead, and how to further customize the headers, you can see the scrpage2 chapter in the KOMA-Script guide (English version).