2

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}
\pagestyle{scrheadings}
\clearscrheadfoot
\automark{section}
\renewcommand\subsectionmark[1]{\markright{\MakeMarkcase {\thesubsection\hskip .5em\relax#1}}}
\rohead{\ifnum\pdfstrcmp\botmark=0 \rightmark\else\leftmark{} --- \rightmark\fi}

\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
\addtokomafont{pagehead}{\upshape}% header upshape instead italic
\cfoot{\thepage}
\addtokomafont{pagefoot}{\upshape}% header upshape instead italic

\usepackage{lipsum}

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

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
\addtokomafont{pagehead}{\upshape}% header upshape instead italic

\usepackage{lipsum}

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

solves your first and second problem:

enter image description here

But the third one is still remaining:

enter image description here


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}}

enter image description here

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

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

enter image description here

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
\ihead{\leftmark}
\ohead{\ifstr{\leftmark}{\rightmark}{\rightbotmark}{\rightmark}}
\addtokomafont{pagehead}{\upshape}

\usepackage{lipsum}

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

enter image description here

enter image description here

Now you could use \righttopmark on such pages

\documentclass{scrartcl}

\usepackage[autooneside=false,automark]{scrlayer-scrpage}
\clearpairofpagestyles
\ihead{\leftmark}
\ohead{%
  \ifstr{\leftmark}{\rightmark}
    {\ifstr{\leftmark}{\rightbotmark}
      {\righttopmark}
      {\rightbotmark}}
    {\rightmark}
  }
\addtokomafont{pageheadfoot}{\upshape}

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

to get

enter image description here

But I think that is not useful.

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

| improve this answer | |
0

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

| improve this answer | |
  • 1
    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
  • 1
    It's usually not recommended to use both KOMA and titlesec – user31729 Dec 1 '15 at 7:34

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.