3

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
includeheadfoot,
top=3.5mm,
bottom=3.5mm,
left=5.5mm,
right=5.5mm,
headsep=6.5mm,
footskip=8.5mm
]{geometry}


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

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

\ihead{\rightmark}
\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
5

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
  includeheadfoot,
  top=3.5mm,
  bottom=3.5mm,
  left=5.5mm,
  right=5.5mm,
  headsep=6.5mm,
  footskip=8.5mm,
]{geometry}

\usepackage[automark]{scrlayer-scrpage}% activates pagestyle scrheadings automatically
\automark{section}
\automark*{subsection}
\clearpairofpagestyles
\ihead{\rightmark}

\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:

enter image description here

This can be extended for subsubsections:

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

enter image description here

  • I like your answer and the answer image... How to get the png as four pages together?(like in your answer) could you please tell me@esdd – David Apr 3 '16 at 13:29
  • And how to remove the numbering in header?@esdd – David Apr 3 '16 at 13:48
  • 1
    In the "View" menu of a pdf viewer normally something like a "Two page" and a "Scrolling" or "Continuously" mode can be choosen and then I take a screenshot. – esdd Apr 3 '16 at 14:07
  • 1
    To remove the numbering in header use \renewcommand*\sectionmarkformat{} and \renewcommand*\subsectionmarkformat{}. – esdd Apr 3 '16 at 14:08

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.