3

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?

1 Answer 1

3

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

4
  • Thank you very much @Jubobs. Do have an idea how to solve the problem with the head separation line that is way to long? Commented Mar 25, 2013 at 10:52
  • What do you mean? Does it extend to much into the margin for your taste?
    – jub0bs
    Commented Mar 25, 2013 at 10:54
  • Yes. I wanted it to only be from the left start of the text to the vertical line before the page number (or vice versa on a even page in twosided printing). I think it's happening because of the \setheadwidth command in the \AfterCalculatingTypearea hook but I have no idea how to fix it for the line to make it work in both one- and twosided printings Commented Mar 25, 2013 at 10:57
  • I'm not very familiar with KOMA-script classes and their mechanics. Wait for someone more competent to address that particular issue.
    – jub0bs
    Commented Mar 25, 2013 at 12:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .