[Tex/LaTex] Adjustment of header placement in fancyhdr

fancyhdr

I'm using the fancyhdr package with the book class, and I need to not only lengthen the header to be wider than \textwidth (e.g., using \fancyheadoffset) but also to control its position.

[EDITED TO REPLACE IMAGE WITH MWE]

For example, the following sample shows that I have section titles that start well to the left of the main text. I would like to extend the header so that its left edge aligns with the section number while preserving the alignment with the text on the right edge. And I need this to work for both odd and even pages.

\documentclass{book}
\usepackage{fancyhdr}
\usepackage{kantlipsum}
\usepackage[calcwidth]{titlesec}

\setlength{\textwidth}{5.0in}
\setlength{\oddsidemargin}{1.5in}
\setlength{\evensidemargin}{1.5in}

\titleformat{\section}
  {\Large\bfseries}{\hspace*{-1in}\thesection}{1em}{}

\pagestyle{fancy}
\fancyhf{}

\renewcommand{\sectionmark}[1]{\markright{{\it #1}}}
\fancyhead[LE,RO]{\thepage}
\fancyhead[CE]{\leftmark}
\fancyhead[CO]{\rightmark}


\begin{document}
\section{Section One}
\kant[1]
\section{Section Two}
\kant[2]
\section{Section Three}
\kant[3]
\section{Section Four}
\kant[4]

\end{document}

Best Answer

If you just want the command to have inner/outer-sensitive offset, you just add the options to \fancyhoffset. For example:

\documentclass[a4paper]{book}
\usepackage{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyheadoffset[loh,reh]{20mm}
% \fancyheadoffset[leh,roh]{20mm}
\fancyhf{}
\fancyhf[loh,reh]{Left Odd Right Even}
\fancyhf[leh,roh]{Left Even Right Odd}
\fancyhf[cf]{\thepage}
\usepackage{kantlipsum}
\begin{document}
  \kant[1-20]
\end{document}

Way One

Replacing

\fancyheadoffset[loh,reh]{20mm}
% \fancyheadoffset[leh,roh]{20mm}

with

% \fancyheadoffset[loh,reh]{20mm}
\fancyheadoffset[leh,roh]{20mm}

flips the effect:

Way Two

EDIT

Since you want the offset always on the left of the page, it is even easier (if a bit odd for a book):

\documentclass{book}
\usepackage{fancyhdr}
\usepackage{kantlipsum}
\usepackage[calcwidth]{titlesec}

% Note that setting these manually is not at all wise use e.g. geometry instead
\setlength{\textwidth}{5.0in}
\setlength{\oddsidemargin}{1.5in}
\setlength{\evensidemargin}{1.5in}

\titleformat{\section}
  {\Large\bfseries}{\hspace*{-1in}\thesection}{1em}{}

\pagestyle{fancy}
\fancyhf{}

\renewcommand{\sectionmark}[1]{\markright{{\itshape #1}}}% \it ought not be used with LaTeX 2e!!
\fancyhead[LE,RO]{\thepage}
\fancyhead[CE]{\leftmark}
\fancyhead[CO]{\rightmark}
\fancyheadoffset[lh]{25.4mm}

\begin{document}
\section{Section One}
\kant[1]
\section{Section Two}
\kant[2]
\section{Section Three}
\kant[3]
\section{Section Four}
\kant[4-8]

\end{document}

keep to the left