Page LayoutHow to make headrule spans across marginpar?

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
latexian
Posts: 19
Joined: Wed Aug 05, 2009 7:57 am

How to make headrule spans across marginpar?

Post by latexian »

Hi all,

I want to redefine \headrule such that there is a ruler in the header. The width of the ruler = text area width + marginparsep + marginparwidth.

I don't know how to make the head rule spans across marginpar.

Here is my minimal code snippet. In the code, I also implement \MARKER to be an example as which the ruler should be the same.

Code: Select all

\documentclass{book}
\usepackage{xcolor}
\usepackage{fancyhdr}
\renewcommand{\headrule}
{\strut\vrule%
	\hrulefill~{\color{red}\scriptsize text area}~\hrulefill\vrule}
	
\newcommand*{\MARKER}{%
	\noindent\strut\vrule%
	\hrulefill~{\color{red}\scriptsize text area}~\hrulefill\vrule%
	\marginpar{\strut\vrule\hrulefill~{\color{green}\scriptsize margin area}~\hrulefill\vrule}\\}

\usepackage{lipsum}

\pagestyle{fancy}\fancyhf{}
\begin{document}
\lipsum[1]


\MARKER

\lipsum[1-10]
\end{document}
Any comment is appreciated.

Thank you.

regards,

LATEXIAN

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

How to make headrule spans across marginpar?

Post by gmedina »

Hi,

the idea is to use the \fancyheadoffset command; take a look at the following example:

Code: Select all

\documentclass{book}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{lipsum}

\newlength\mylen
\addtolength\mylen{\marginparsep}
\addtolength\mylen{\marginparwidth}

\fancyheadoffset[OR,EL]{\the\mylen}
\renewcommand{\headrule}{\hrule width\headwidth height\headrulewidth \vskip-\headrulewidth}

\pagestyle{fancy}
\fancyhf{}

\begin{document}
\lipsum[1-10]
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
latexian
Posts: 19
Joined: Wed Aug 05, 2009 7:57 am

Re: How to make headrule spans across marginpar?

Post by latexian »

thank you gmedia for your hint about using \fancyheadoffset.
Post Reply