5

I have defined the page margins and header as appears in the codes bellow, but I want the header to cover the page margin width too, in the pages after page 2 (all pages except the first page). I searched over the net but did not find any solution to it.

enter image description here enter image description here

\documentclass[standalone]{article}

\usepackage{marginnote}
\usepackage{fancyhdr}
\usepackage[pages=some]{background}
\usepackage{geometry}

\geometry{a4paper,
          total=          {210mm,297mm},
          left=            37.5mm,
          right=           12.5mm,
          top=             25mm,
          bottom=          25mm,
          bindingoffset=   0mm}

\pagestyle{fancy}

\lhead{\Huge \bf Title1}
\rhead{\Large \bf Title2}

\begin{document}

\noindent Some text here.Some text here.Some text here.
\reversemarginpar\marginpar{\raggedleft {\large \bf Subtitle} \\*[-.8pc]}
\\Some text here.Some text here.Some text here.

\end{document}
  • Could you please remove irrelevant parts of your preamble from the MWE? That makes it a lot easier for people to see what is going on quickly and to help you efficiently. – cfr Sep 12 '14 at 20:49
  • @cfr Sure, but which are irrelevant? – Enthusiastic Engineer Sep 12 '14 at 20:55
  • Which do you need to create the headers as they currently appear and which don't you? Do you have pictures in your headers? No. Hyperlinks? Symbols from marvosym? Surely most of your preamble is irrelevant. – cfr Sep 12 '14 at 20:57
  • @cfr I did remove all the irrelevant preamble, however, I could not remove the background package and I don't know why. – Enthusiastic Engineer Sep 12 '14 at 21:35
  • That's much better. I put the geometry back, though, as that will help people in this particular case. – cfr Sep 12 '14 at 21:36
6

I'm not entirely sure what you would like the result to look like. I assume one of the two images but which?

Here is a start using the offset option of fancyhdr:

\documentclass[a4paper]{article}

\usepackage{marginnote,calc,kantlipsum}
\usepackage{fancyhdr}
\usepackage{geometry}

\geometry{%
  left=37.5mm,
  right=12.5mm,
  top=25mm,
  bottom=25mm,
  bindingoffset=0mm,
  headheight=30pt,% output from geometry tells you what this needs to be set to as a minimum
}

\newlength{\myoddoffset}
\setlength{\myoddoffset}{\marginparwidth + \marginparsep}


\pagestyle{fancy}
\fancyheadoffset[leh,roh]{\marginparsep}
\fancyheadoffset[loh,reh]{\myoddoffset}
\lhead{\Huge \bfseries Title1}% Don't use \bf it is a LaTeX 2.09 command, long deprecated
\rhead{\Large \bfseries Title2}

\begin{document}

  \noindent Some text here.Some text here.Some text here.
  \reversemarginpar\marginpar{\raggedleft {\large \bfseries Subtitle} \\*[-.8pc]}
  \\Some text here.Some text here.Some text here.

  \kant[1-20]
\end{document}

offset headers

If you add the twoside option to geometry, you'll get something like this:

twoside offset

Update

This undoes the changes to the right offset. (You don't need to set it to zero - you just have to not change it as I did initially based on the images you posted.)

It also sets up a separate style for the first page which is applied at the beginning of the document using \thispagestyle{}. If you want no heading there, just use plain or empty rather than fancyfirst depending on whether you want a page number in the footer or not. In that case, you can dispense with the complexity introduced by defining two fancy styles.

\documentclass[a4paper]{article}

\usepackage{marginnote,calc,kantlipsum}
\usepackage{fancyhdr}
\usepackage{geometry}

\geometry{%
  left=37.5mm,
  right=12.5mm,
  top=25mm,
  bottom=25mm,
  bindingoffset=0mm,
  headheight=30pt,% output from geometry tells you what this needs to be set to as a minimum
}

\newlength{\myoddoffset}
\setlength{\myoddoffset}{\marginparwidth + \marginparsep}

\fancypagestyle{fancyfirst}{%
  \lhead{\Huge \bfseries Title1}% Don't use \bf it is a LaTeX 2.09 command, long deprecated
  \rhead{\Large \bfseries Title2}%
  \fancyheadoffset{0pt}}
\fancypagestyle{fancyoffset}{%
  \fancyheadoffset[loh,reh]{\myoddoffset}%
  \lhead{\Huge \bfseries Title1}% Don't use \bf it is a LaTeX 2.09 command, long deprecated
  \rhead{\Large \bfseries Title2}}
\pagestyle{fancyoffset}

\begin{document}

  \thispagestyle{fancyfirst}

  \noindent Some text here.Some text here.Some text here.
  \reversemarginpar\marginpar{\raggedleft {\large \bfseries Subtitle} \\*[-.8pc]}
  \\Some text here.Some text here.Some text here.

  \kant[1-20]
\end{document}

fancyoffset and fancyfirst

  • Thanks. I think this changes the header in the hole document. I want the first page remain unchanged. – Enthusiastic Engineer Sep 12 '14 at 22:11
  • @EnthusiasticStudent Don't you have a title on the first page? This will not affect the page on which you have the title. – cfr Sep 12 '14 at 22:13
  • No, I don't provide any title page. Also, I think by using this method, the length of the header is changed from the right side too; I don't want the right side to be changed. – Enthusiastic Engineer Sep 12 '14 at 22:19
  • 1
    @EnthusiasticStudent Glad that helped. Sure, let me know if you have questions. Note that I created the problem on the right because I didn't understand what you wanted from the images. You don't need to set them to 0 but only not to mess with them originally. Note that my code is commented a bit. In particular, don't use \bf etc. as those are deprecated. Use \bfseries or \textbf{} etc. instead. – cfr Sep 12 '14 at 22:45
  • 1
    @EnthusiasticStudent Yes. That is right. You can also put \fancyhf{} at the beginning of each definition to blank everything. That's what I usually do, actually. – cfr Sep 12 '14 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.