# Header with doublesided document

This is already quite close to what I need.

The only issue with this solution is that it shows the sections on the odd pages and the subsections on the even pages. However, for the first time the section appears it should always be printed. Indifferent if it is an odd or an even page. After the section is mentioned for the first time in the header the subsection and section should be alternately in the header. If there is a chapter without subsections and only one section the section should be always displayed in the header.

Moreover, the pagenumber should be displayed in the bottom right of the page.

Hopefully by the following exemple it should become clearer:

\section{1}
\subsection{1.1}
\subsection{1.2}
\subsection{1.3}
\section{2}
\section{3}
\subsection{3.1}
\subsection{3.2}


This should give the follwing output:

p.1 1
p.2 1.1
p.3 1
p.4 1.3
p.5 1
p.6 2
p.7 2
p.8 3
p.9 3.1
p.10 3

 \documentclass[12pt, twoside=semi]{scrartcl}
\usepackage{scrlayer-scrpage}
\usepackage[left=2.5cm, right=2.5cm, top=2.5cm, bottom=2cm,]{geometry}
\automark[section]{section}
\automark*[subsection]{}
\clearpairofpagestyles
\rofoot*{\pagemark}
\refoot*{\pagemark}

\BeforeStartingTOC[toc]{\pagestyle{plain}}
\AfterStartingTOC[toc]{\clearpage}

\begin{document}
\section{1}
\newpage
\subsection{1.1}
\newpage
\subsection{1.2}
\newpage
\subsection{1.3}
\newpage
d
\newpage
\section{2}
\newpage
d
\newpage
\section{3}
\newpage
\subsection{3.1}
\newpage
\subsection{3.2}
\end{document}

• Please -- as usual here -- show us a short compilable code you have so far ... – Kurt Jan 5 at 0:41
• If you want the page number in the foot, you should not use \rohead*{\pagemark} and \rehead*{\pagemark} but \rofoot*{\pagemark} and \refoot*{\pagemark}. I cannot say anything to your other question because the code example shows only two pages but your numbering example talks about ten pages. So IMHO the code does not show the problem. However, have a look to the additional \right…mark and \left…mark commands in the KOMA-Script manual. – Schweinebacke Jan 5 at 11:13
• @Schweinebacke Thanks for your comment. I already had a look at the \rightmark command but it didn't answer my question how to establish a hierarchy that the section is always displayed for the first time and then the subsection and section alternating. (Except if there is no subsection in the section) You're right about the code. I added \newpage so it spreads over several pages. – danik Jan 5 at 11:28
• Your code example still does not correspond with your numbering example. However: Is it correct, that in the page head you always want the first section or subsection heading that is shown on a page? And please note, my recommendation to have a look to \right…mark means not only \rightmark but also \righttopmark, \rightfirstmark and \rightbotmark (and same for \left…mark). One more note: \newpage\newpage make no sense and is the same like only one \newpage. – Schweinebacke Jan 5 at 11:36

If you just want the first section or subsection heading printed on a page to have also in the page header, you do not need twoside=semi. In single-side mode \headmark is always \rightmark which is the same like \rightfirstmark (see the KOMA-Script manual for more information about these marks). So with

\documentclass[12pt]{scrartcl}
\usepackage{scrlayer-scrpage}
\usepackage[left=2.5cm, right=2.5cm, top=2.5cm, bottom=2cm,]{geometry}
\automark{section}
\automark*{subsection}
\clearpairofpagestyles
\ofoot*{\pagemark}

\BeforeStartingTOC[toc]{\pagestyle{plain}}
\AfterStartingTOC[toc]{\clearpage}

\begin{document}
\tableofcontents
\section{section 1}
\newpage
\subsection{subsection 1.1}
\newpage
\subsection{subsection 1.2}
\newpage
\subsection{subsection 1.3}
\newpage Test
\newpage
\section{section 2}
\newpage Test
\newpage
\section{section 3}
\newpage
\subsection{subsection 3.1}
\newpage
\subsection{subsection 3.2}
\end{document}


you get the heading sequence:

• page 1: empty
• page 2: 1 section 1
• page 3: 1.1 subsection 1.1
• page 4: 1.2 subsection 1.2
• page 5: 1.3 subsection 1.3
• page 6: 1.3 subsection 1.3
• page 7: 2 section 2
• page 8: 2 section 2
• page 9: 3 section 3
• page 10: 3.1 subsection 3.1
• page 11: 3.2 subsection 3.2

To your moreover question: If you want to place something in the page footer you have to use a \…foot-command instead a \…head-command. See figure 5.2 in the KOMA-Script manual and the explanation of the commands in section 5.4 of the KOMA-Script manual.

If you want the same result with twoside=semi (or twoside=true) it would be better to explicitly use \rightfirstmark instead of \headmark, because in this case \headmark would be \rightmark on odd pages but \leftmark (same like \leftbotmark) on even pages. And in this case you need indeed the optional argument of \automark and \automark* and, if the elements in the head and foot should not alter their alignment, you cannot use \ohead and \ofoot:

\documentclass[12pt,twoside=semi]{scrartcl}
\usepackage{scrlayer-scrpage}
\usepackage[left=2.5cm, right=2.5cm, top=2.5cm, bottom=2cm,]{geometry}
\automark[section]{section}
\automark*[subsection]{subsection}
\clearpairofpagestyles
\rofoot*{\pagemark}
\refoot*{\pagemark}

\BeforeStartingTOC[toc]{\pagestyle{plain}}
\AfterStartingTOC[toc]{\clearpage}

\begin{document}
\tableofcontents
\section{section 1}
\newpage
\subsection{subsection 1.1}
\newpage
\subsection{subsection 1.2}
\newpage
\subsection{subsection 1.3}
\newpage Test
\newpage
\section{section 2}
\newpage Test
\newpage
\section{section 3}
\newpage
\subsection{subsection 3.1}
\newpage
\subsection{subsection 3.2}
\end{document}

• Thanks for your answer. twoside=demi is needed for BCOR and I wasn't sure if this influences my question so I just added it to the MWE. Your answer does not fully address my question. I'm fully aware that the question is not clear enough as I struggle quite a bit with describing the desired result and I'm sorry for that. So I edited the question. The difference from your answer to my desired result is that the section and subsection should be alternaly. – danik Jan 5 at 11:53
• @danik I think you mean twoside=semi. I've added an example with it. However, with alternating BCOR IMHO alternating alignment of the elements in the page head and foot would make more sense. – Schweinebacke Jan 5 at 11:56
• What do you mean by alternating alignment? And is it now clearer how the output from your answer differs from the desired result? – danik Jan 5 at 12:00
• @danik With twoside=semi the BCOR is added to the right margin on left pages and to the left margin on right pages. So twoside=semi is made for double-sided printing. But with double-sided printing, it makes not sense to have, e.g., the page number always aligned to the right margin (using \refoot and \rofoot). Instead it would make more sense to have the page number always aligned to the outer margin (this what \ofoot makes). Similar to the head: It would make more sense to still use \ohead instead of \rohead and \rehead. – Schweinebacke Jan 5 at 12:43
• @danik … On the other hand for a single-sided document it makes more sense to have BCOR always added to the left margin, so twoside=false would be better. – Schweinebacke Jan 5 at 12:44

Your desired result is unusual, but maybe the following does what you want.

\documentclass[12pt,twoside=semi]{scrartcl}
\usepackage{scrlayer-scrpage}
\usepackage[left=2.5cm, right=2.5cm, top=2.5cm, bottom=2cm,]{geometry}
\automark[section]{section}
\automark*[subsection]{}
\clearpairofpagestyles
\rofoot*{\pagemark}
\refoot*{\pagemark}

}
}

\BeforeStartingTOC[toc]{\pagestyle{plain}}
\AfterStartingTOC[toc]{\clearpage}

\usepackage{lipsum}% only for dummy text
\begin{document}
\tableofcontents
\section{section 1}
\lipsum[1-7]
\subsection{subsection 1.1}
\lipsum[8-14]
\subsection{subsection 1.2}
\lipsum[15-20]
\subsection{subsection 1.3}
\lipsum[21-28]
\section{section 2}
\lipsum[29-35]
\section{section 3}
\lipsum[36-40]
\subsection{subsection 3.1}
\lipsum[41-44]
\subsection{subsection 3.2}
\lipsum[45-50]
\end{document}


Result:

• page 1: empty
• page 2: section 1
• page 3: subsection 1.1
• page 4: section 1
• page 5: subsection 1.3
• page 6: section 2
• page 7: section 3
• page 8: subsection 3.1
• page 9: section 3
• page 10: subsection 3.2