[Tex/LaTex] KOMA-Script Headlines: Problem with underlining and pagestyle on onesided-print

header-footerkoma-scriptscrpage2

I've got some code provided by Markus Kohm (KOMA-Script author) in „Die TeXnische Komödie“ (members journal of german TeX users group) volume 3/2012. He's showing how to easily modify the headlines with KOMA-Script. I now have the following code which is basically copied from the journal (so it's Markus', not mine)

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{blindtext}
\usepackage{scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot
\setheadsepline{0.5pt}
\lehead[\pagemark]{\makebox[\marginparwidth][l]{\pagemark}\hspace{\marginparsep}\headmark}
\rohead[\pagemark]{\headmark\hspace{\marginparsep}\makebox[\marginparwidth][r]{\pagemark}}
\renewcommand*{\pagemark}{%
  \usekomafont{pagenumber}%
  \ifodd\value{page}\makebox[\marginparwidth][l]{\pnumbar\enskip\thepage}%
  \else\makebox[\marginparwidth][r]{\thepage\enskip\pnumbar}%
  \fi
}%
\newcommand*{\pnumbar}{%
  \raisebox{0pt}[\ht\strutbox][\dp\strutbox]{%
    \rule[-\dp\strutbox]{1.5pt}{1.1\baselineskip}%
  }%
}
\AfterCalculatingTypearea{%
  \setheadwidth[0pt]{%
    \dimexpr\textwidth+\marginparsep+\marginparwidth\relax
  }%
}%
\recalctypearea
\begin{document}
\Blindtext
\end{document}

When adding the twoside-option to \documentclass I get the page numbers positioned as expected (screenshots cut together):
Result of twosided print

While with oneside the positioning of the page number on even pages is wrong:
Result of onesided print

I can image that the problem is happening due to the \ifodd check. Is there a possibility to react on whether twoside or oneside option is set to fix this and have all pages with oneside to be the same?

As—as you can see—the seperation line between the head and the main text is way to long. This was added by me but I don't know how to make it shorter, so it has only the length of the text width (and maybe stopping at the vertical marker next to the page number). How can I achieve that?

Best Answer

That template doesn't seem to accommodate for oneside, but can be modified to.

EDIT: I think I fixed your problem with the length of the head separation line.

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{blindtext}
\usepackage{scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot
\setheadsepline{0.5pt}
\lehead[\pagemark]{\makebox[\marginparwidth][l]{\pagemark}\hspace{\marginparsep}\headmark}
\rohead[\pagemark]{\headmark\hspace{\marginparsep}\makebox[\marginparwidth][r]{\pagemark}}

\makeatletter
\if@twoside%
    \renewcommand*{\pagemark}{%
    \usekomafont{pagenumber}%
    \ifodd\value{page}\makebox[0pt][l]{\pnumbar\enskip\thepage}%
    \else\makebox[0pt][r]{\thepage\enskip\pnumbar}%
    \fi%
}%
\else%
\renewcommand*{\pagemark}{%
    \usekomafont{pagenumber}%
    \makebox[0pt][l]{\pnumbar\enskip\thepage}%
}%
\fi%
\makeatother


\newcommand*{\pnumbar}{%
  \raisebox{0pt}[\ht\strutbox][\dp\strutbox]{%
    \rule[-\dp\strutbox]{1.5pt}{1.1\baselineskip}%
  }%
}
\AfterCalculatingTypearea{%
  \setheadwidth[0pt]{%
    \dimexpr\textwidth+\marginparsep\relax%+\marginparwidth\relax
  }%
}%
\recalctypearea
\begin{document}
\Blindtext \Blindtext
\end{document}

If the twoside option is loaded:

enter image description here enter image description here

If the twoside option is not loaded:

enter image description here enter image description here

Related Question