0

I've been starting to use the \fancyhdr package now, using next commands:

\newgeometry{left=1.5in,right=1.5cm,top=3cm,bottom=2.5cm,headheight=1cm}

(after \begin{document} and after the input of the title page; the 3 cm top margin is to make the header look good, not too much on the top)

\pagestyle{fancy}
%\fancyhf{}
\fancyheadoffset{0cm}
%\renewcommand{\headrulewidth}{0pt} 
\renewcommand{\footrulewidth}{0pt}
%\renewcommand{\headheight}{13.6pt}
\fancyfoot[R]{\thepage}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \fancyfoot[R]{\thepage}
  \renewcommand{\headrulewidth}{0pt}
 \newgeometry{left=1.5in,right=1.5cm,top=2cm,bottom=2.5cm,headheight=1cm}
}

Now the problem is, as you may've noticed, that the top margin of 3 cm is ideal for pages with header. However, 3 cm is just too much space on pages with the plain style (new chapter title pages, e.g.).

How could I easily solve this?

MWE:

\documentclass[11pt]{report}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{fancyhdr}           %mooiere hoofding en voettekst
\begin{document}
\tableofcontents
\pagestyle{fancy}
\fancyheadoffset{0cm}
\renewcommand{\footrulewidth}{0pt}
\fancyfoot[R]{\thepage}
\fancypagestyle{plain}{%
    \fancyhf{}%
    \fancyfoot[R]{\thepage}
    \renewcommand{\headrulewidth}{0pt}
    \newgeometry{top=2cm}
}
\chapter{Inleiding}
\lipsum
\end{document}
  • Please consider providing us with a minimal working example (meta.tex.stackexchange.com/questions/228/…), to make it easier for us to help you. – dgoodmaniii Jun 1 '15 at 3:58
  • Are you really sure you want to do this? Typically the text block should be the same size regardless of page style. – dgoodmaniii Jun 1 '15 at 4:01
  • There must be a way to get the chapter titles at the same height as the otherwise heading :/ – FSJ963 Jun 1 '15 at 4:05
  • If you highlight your code and hit the curly bracket button, the site will nicely format it. – dgoodmaniii Jun 1 '15 at 4:07
  • Ah okay, sorry. – FSJ963 Jun 1 '15 at 4:10
2

Don't do this the hard way. Using \newgeometry like this is not going to work - not, at least, without an awful lot more gymnastics than you are using at the moment. (How are you planning to restore the original geometry given that the command to do so will start another new page?)

You are using titlesec already, it seems. [It has been removed from the MWE along with some other useful and needful things, unfortunately. However, it is still there in the revision history. One advantage of minimising your own code is that you can make sure it really demonstrates the problem you want help with.]

You really should consider using titleps if you are using titlesec. I expect Bernard will illustrate the best way to do it if you hold on for a bit. It cooperates with titlesec in a way that fancyhdr is never going to since it is by a different author. Note, too, that titletoc is the third package in the trilogy. I tend to avoid them, but if you are using them, you might as well make the most of the lot.

The best approach, as far as I can figure out, is to format your chapter titles appropriately. In particular, you can use a negative vertical space before the chapter title in order to negate some of the 3cm gap. I've used 2cm here - adjust to suit.

You should also minimise the spacing in the format of the sectioning commands and use \titlespacing with its stretchable short-cuts. Or you should include stretch in the vertical spacing the old-fashioned way i.e. explicitly. I've taken the road with less typing here.

I've also removed what is, I think, a spurious second page number in your footer. Obviously if you really wanted both, you can put it back.

The code below is patched together from the MWE now in the question and the extremely non-minimal code you posted earlier.

Try to keep page styles etc. in your preamble. If you need an additional style, define it there and then apply it if necessary manually. (Shouldn't usually be needed.)

In this case, I've just stuck to fancy and plain. The plain style is simplified by dropping the \newgeometry instruction which, as I say, is just not going to work here.

This means you have a standard page geometry for all styles of pages but your chapter headings are styled as I think you want them. This catches the table of contents, too, and should catch things like the bibliography or index or whatever. Unless you are doing something quite different there. This is because \chapter and \chapter* invoke the plain pagestyle and commands such as \tableofcontents invoke \chapter*. Again, unless you are explicitly asking for something different.

I've simplified the code for the headers as I don't have your fonts and I didn't see any particular reason to keep the colour for purposes of demonstration. But note that you should try to keep formatting and content separate as much as you possibly can as it makes it easy to ensure consistency, provides greater flexibility and is easier to troubleshoot when things go wrong. (And they always go wrong, of course. That happens however cleanly you code. Well, as far as I can tell. The cleanness just makes it easier to find out how sod's law has impacted you specifically on this particular occasion.)

raised chapters with titlesec

\documentclass[11pt]{report}
\usepackage[left=1.5in,right=1.5cm,top=3cm,bottom=2.5cm,headheight=1cm]{geometry}
\usepackage{kantlipsum}% more philosophically sophisticated filler text
\usepackage{fancyhdr}
\pagestyle{fancy}% the default page style for the document
\fancyheadoffset{0cm}
\renewcommand{\footrulewidth}{0pt}
\fancyhf[cf]{}% unless you really want the page number in the footer twice...
\fancyfoot[R]{\thepage}
\fancypagestyle{plain}{% not a place to change the geometry of the page...
  \fancyhf{}%
  \fancyfoot[R]{\thepage}%
  \renewcommand{\headrulewidth}{0pt}%
}
\usepackage[explicit]{titlesec}
\titleformat{\chapter}[display]% where possible avoid spacing here which should be handled by \titlespacing and should include **strech**; remove code which does nothing; colour and fonts-I-don't-have removed for demo
  {\bfseries\Huge}% format applies to label and body of title
  {\filright\thechapter}% the label
  {1ex}% vertical separation
  {\titlerule\filleft #1}% code before body of title
  [\titlerule]% code after body of title
\titlespacing{\chapter}{0cm}{\dimexpr\topskip-20mm}{*6}[0pt]% spacing: change the 20mm if you want the titles of chapters raised by a different amount; note the *6 which includes stretch - may need adjusting as I just eye-balled something roughly like the output the original code produced
\begin{document}% no need to define page styles or change geometry etc. within the document itself
\tableofcontents
\chapter{Inleiding}
\kant[1-10]
\chapter{Next}
\kant[11-15]
\end{document}
  • Thank you very much for your very thorough explanations. – FSJ963 Jun 2 '15 at 7:27
0

I've edited your post to contain a clearly minimal example. The MWE you posted wouldn't compile on my machine, for a variety of reasons, most especially that I don't have your fonts. Once it was minimized, the problem became pretty apparent quickly. Since I couldn't compile the example you gave, I can only speculate that nothing else in your document is interfering with this solution; but that's the point of a MWE: for you to whittle your problem down until you have the smallest, compiling document that demonstrates it.

When you redefine the plain pagestyle using fancyhdr, you said:

\newgeometry{...top=2cm...}

The ellipses indicate various other parameters you reset. I think this one is the problem, though. If you instead say:

\newgeometry{...top=0cm...}

I think you'll get what you want. With top=2cm, you get this:

Chapter head not as desired

But with top=0cm, you get this:

Chapter head as desired

Of course, your other formatting isn't present here, but it doesn't need to be; we're trying to solve one very limited problem.

Hope that helps.

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.