# How to get the subsection and subsubsection automatically in the header using scrheadings?

## How to get the subsection and subsubsection automatically in the header using scrheadings?

Complete MWE:

\documentclass[
paper=128mm:96mm,
fontsize=12pt,
pagesize,
parskip=half-,
]{scrartcl}
\usepackage[ % Page margins settings
top=3.5mm,
bottom=3.5mm,
left=5.5mm,
right=5.5mm,
footskip=8.5mm
]{geometry}

\usepackage[automark]{scrpage2}
\usepackage{tikz,lipsum}
\usepackage{xcolor}

\definecolor{mygreen}{RGB}{44,85,17}

\begin{document}
\section{This should appear in the header until it reaches a subsection}
\lipsum[1]
\clearpage
\subsection{Once the subsectin is reached this only should appear in the header}
\lipsum[3]
\end{document}


In the place of \rightmark, I want some comments which give subsections in the header.

## What I want?

In the header whatever the section or subsection or subsubsection appears that only should appear in the header not the section or chapter name which I introduced long back.

• Your question is rather unclear. The title says you want subsection and subsubsection, the example wants section and subsection, your final remark mentions three levels and chapter, while the class scrartcl has no chapter. – Ulrike Fischer Apr 3 '16 at 11:57

I would suggest to use scrlayer-scrpage. This package is the successor of the deprecated scrpage2. With both packages you can use \automark to define a section level that sets a right mark. But scrlayer-scrpage provides a starred version \automark* to define an additional section level that sets a right mark too.

\documentclass[
paper=128mm:96mm,
fontsize=12pt,
pagesize,
parskip=half-,
]{scrartcl}
\usepackage[ % Page margins settings
top=3.5mm,
bottom=3.5mm,
left=5.5mm,
right=5.5mm,
footskip=8.5mm,
]{geometry}

\automark{section}
\automark*{subsection}
\clearpairofpagestyles

\usepackage{lipsum}
\begin{document}
\section{This should appear in the header untill it reaches a subsection}
\lipsum[1]
\clearpage
\subsection{Once subsection is reached this should appear in header}
\lipsum[3]
\end{document}


Result:

This can be extended for subsubsections:

\usepackage[automark]{scrlayer-scrpage}
\automark{section}
\automark*{subsection}
\automark*{subsubsection}
\clearpairofpagestyles
