2

By default, headers and footers span only the width of the text body, but I need them to span the width of the margin notes and the main text. The closest I've been able to get is the following, using the headwidth and paperwidth options.

\documentclass[a4paper,oneside]{article}

\usepackage{mwe}
\usepackage[margin=2cm,marginparwidth=4cm,includemp,reversemp]{geometry}
\usepackage[headwidth=paper, footwidth=paper]{scrlayer-scrpage}

\ihead{left header}
\chead{centre header}
\ohead{right header}

\ifoot{left footer}
\cfoot{centre footer}
\ofoot{right footer}

\begin{document}

\section{Some text}

\blindtext
\marginpar{This is a margin note}

\section{Some more text}

\blindtext

\end{document}

Now the header is properly left-aligned with the margin notes column. However, the "right header" runs off the edge of the page. Clearly I need to set the headwidth to something like marginwidth + marginparsep + textwidth. However, I can't find anything about how to do this in the KOMA-Script manual (at least the English language version, scrguide-en.pdf).

I'm open to a solution with or without scrlayer-scrpage. I would prefer to avoid manually placing the header elements (e.g. using textpos) because I think it will be more difficult for others to maintain the code.

enter image description here

2 Answers 2

2

The problem is the reversemp option to geometry. Because of this a simple headwidth=textwithmarginpar does not work. However, you can use an additional offset:

\documentclass[a4paper,oneside]{article}

\usepackage{mwe}
\usepackage[margin=2cm,marginparwidth=4cm,includemp,reversemp]{geometry}

\usepackage{scrlayer-scrpage}
\KOMAoptions{headwidth=textwithmarginpar:-\marginparsep-\marginparwidth,footwidth=textwithmarginpar:-\marginparsep-\marginparwidth}

\ihead{left header}
\chead{centre header}
\ohead{right header}

\ifoot{left footer}
\cfoot{centre footer}
\ofoot{right footer}

\begin{document}

\section{Some text}

\blindtext
\marginpar{This is a margin note}

\section{Some more text}

\blindtext

\end{document}

one page with head and foot

Providing an offset is documented in the English KOMA-Script manual, section 5.5.

Note: Using an offset like -\marginparwidth-\marginparsep does not work as optional argument of \usepackage but only using \KOMAoption or \KOMAoptions.

Edit: The author of KOMA-Script told me that from KOMA-Script 3.39 on,

\usepackage[headwidth=textwidthmarginpar,footwidth=head]{scrlayer-scrpage}

is sufficient if scrlayer-scrpage is loaded after geometry and geometry's option reversemp or \reversemarginpar is activated before loading scrlayer-scrpage.

1

Just for fun:

This redefines pagestyle plain to generate wide headers by overlapping the edges.

\documentclass[a4paper,oneside]{article}

\usepackage[margin=2cm,marginparwidth=4cm,includemp,reversemp,showframe]{geometry}
\usepackage{blindtext}

\makeatletter
\def\ps@plain{%
    \def\@oddhead{\hspace{\dimexpr -\marginparwidth-\marginparsep}%
      \rlap{\ihead}\hfill\chead\hfill\llap{\ohead}}
    \let\@evenhead\@oddhead% just in case
    \def\@oddfoot{\hspace{\dimexpr -\marginparwidth-\marginparsep}%
      \rlap{\ifoot}\hfill\cfoot\hfill\llap{\ofoot}}
    \let\@evenfoot\@oddfoot% just in case
    \let\@mkboth\@gobbletwo
    \let\sectionmark\@gobble
    \let\subsectionmark\@gobble
    }
\makeatother

\def\ihead{left header}
\def\chead{centre header}
\def\ohead{right header}

\def\ifoot{left footer}
\def\cfoot{centre footer}
\def\ofoot{right footer}

\pagestyle{plain}

\begin{document}

\section{Some text}

\blindtext
\marginpar{This is a margin note}

\section{Some more text}

\blindtext

\end{document}

This uses paracol to implement the marginpar area as a separate column. Note that one can only use \marginpar between paragraphs. OTOH, these marginpars will break over pages.

\documentclass[a4paper,oneside]{article}

\usepackage[margin=2cm,showframe]{geometry}
\usepackage{paracol}
\usepackage{fancyhdr}
\usepackage{blindtext}

\fancyhead[L]{left header}
\fancyhead[C]{centre header}
\fancyhead[R]{right header}

\fancyfoot[L]{left footer}
\fancyfoot[C]{centre footer}
\fancyfoot[R]{right footer}

\pagestyle{fancy}

\renewcommand{\marginpar}[1]{\switchcolumn*
  \vspace*{-\baselineskip}{\parindent=0pt\sloppy#1}%
  \switchcolumn}

\begin{document}
\setcolumnwidth{4cm}% uses \columnsep instead of \marginparsep
\begin{paracol}{2}
\switchcolumn% start in right column
\section{Some text}

\blindtext
\marginpar{This is a margin note}

\section{Some more text}

\blindtext

\end{paracol}
\end{document}

You must log in to answer this question.

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