# How do I insert section and first subsection in the header using scrartcl?

I have a scartcl document and I would like to add a header, with the section aligned to the left, and the first subsection on the page aligned to the right. The header should not be in italic. How should I go about doing so?

UPDATE

Based on the answer to this question and using scrpage2 I have found the following:

\documentclass{scrartcl}

\usepackage[autooneside]{scrpage2}
\automark{section}
\renewcommand\subsectionmark[1]{\markright{\MakeMarkcase {\thesubsection\hskip .5em\relax#1}}}

\usepackage{lipsum}

\begin{document}

\section{Section}
\subsection{Subsection1}
\lipsum
\subsection{Subsection2}
\lipsum

\end{document}


I still have three problems: * The header is in italic * The section is not aligned on the right * On the first page the section is displayed twice instead of the section and the subsection.

Can someone help me out?

SOLUTION: This is what I used from esdd answer, thanks!

\documentclass[headsepline]{scrartcl}
\usepackage[
autooneside=false,% use left and right marks with a onesided document
automark% set \leftmark and \rightmark automatically by \section and \subsection
]{scrlayer-scrpage}
\clearpairofpagestyles
\ihead{\leftmark}% section on the inner (oneside: right) side
\ohead{\ifstr{\leftmark}{\rightmark}{}{\rightmark}}% subsection on the outer (oneside: left) side
\cfoot{\thepage}

\usepackage{lipsum}

\begin{document}
\section{Section}
\subsection{Subsection1}
\lipsum
\subsection{Subsection2}
\lipsum
\end{document}


It is recommended to use scrlayer-scrpage with a KOMA-Script class.

\documentclass{scrartcl}
\usepackage[
autooneside=false,% use left and right marks with a onesided document
automark% set \leftmark and \rightmark automatically by \section and \subsection
]{scrlayer-scrpage}
\clearpairofpagestyles
\ihead{\leftmark}% section on the inner (oneside: right) side
\ohead{\rightmark}% subsection on the outer (oneside: left) side

\usepackage{lipsum}

\begin{document}
\section{Section}
\subsection{Subsection1}
\lipsum
\subsection{Subsection2}
\lipsum
\end{document}


solves your first and second problem:

But the third one is still remaining:

To understand the problem:

In your example both \section and \subsection set a bipartite mark: \section sets the right part and the left part to the current section entry. \subsection sets the right part to the current subsection and saves the left part unchanged.

There are three kinds of marks: \botmark is the last valid mark on a page, \firstmark is the first mark set on a page and \topmark is the content of \botmark from the last page. If there is no new mark on a page \botmark and \firstmark have the same content as \topmark.

Notice that \leftmark uses \botmark and \rightmark uses \firstmark.

In your example the first mark on page 1 is set by \section{Section} so the right part of this first mark on this page is also "Section".

It is possible to remove the left entry in the header if it is the same as the right entry:

\ohead{\ifstr{\leftmark}{\rightmark}{}{\rightmark}}


Or to use \rightbotmark if \leftmark and \rightmark are equal:

\ohead{\ifstr{\leftmark}{\rightmark}{\rightbotmark}{\rightmark}}


But then the last subsection on such pages is used. Additionally your problem is not really solved:

\documentclass{scrartcl}
\usepackage[
autooneside=false,
automark
]{scrlayer-scrpage}
\clearpairofpagestyles

\usepackage{lipsum}

\begin{document}
\section{Section1}
\subsection{Subsection1}
\lipsum
\section{Section2}
\lipsum
\end{document}


Now you could use \righttopmark on such pages

\documentclass{scrartcl}

\usepackage[autooneside=false,automark]{scrlayer-scrpage}
\clearpairofpagestyles
\ifstr{\leftmark}{\rightmark}
{\ifstr{\leftmark}{\rightbotmark}
{\righttopmark}
{\rightbotmark}}
{\rightmark}
}

\usepackage{lipsum}
\begin{document}
\section{Section1}
\subsection{Subsection1}
\lipsum
\section{Section2}
\lipsum
\end{document}


to get

But I think that is not useful.

I would recommend to set only the sections in the header if an article class is used.

You can use the titlesec package to design your heading style. The titlesec provides many interfaces and command to change the title's style.

• This specifically refers to the header/footer in a document. Can you show how you can use your suggested titlesec solution together with the KOMA-script class to update headers/footers according to the specification of the OP? – Werner Dec 1 '15 at 1:13
• Oh,actually I haven't used the KOMA-script class and don'yt know how :( I have only used the titlesec package to design the header's style for standard class article – Ice0cean Dec 1 '15 at 1:31
• It's usually not recommended to use both KOMA and titlesec – user31729 Dec 1 '15 at 7:34