Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

After hours of debugging, I finally found out that the header of my bibliography's last page is changed by using spacing in the text. Now my world is turned upside down.

Please have a look at this correct example. Both \begin{spacing} and \end{spacing} are commented out:

\documentclass[12pt, a4paper, oneside, onecolumn]{book}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{setspace}
\usepackage[round]{natbib}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{%
\markright{\thesection\ #1}}
\fancyhf{} % delete current header and footer
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{0.5pt} % space for the rule
\newcommand{\plainplain}{%
  \fancypagestyle{plain}{%
      \renewcommand{\headrulewidth}{0pt}
      \fancyhead[LO]{}
      \fancyhead[RE]{}
}}
\newcommand{\myplain}{%
  \fancypagestyle{plain}{%
    \fancyhead[LO]{\bfseries\rightmark}
    \fancyhead[RE]{\bfseries\leftmark}
    \renewcommand{\headrulewidth}{0.5pt}
    }}
\plainplain
\pagestyle{plain}

\usepackage{lipsum, filecontents}

\begin{document}

\frontmatter
\pagenumbering{Roman}

\tableofcontents
\clearpage

\listoffigures
\clearpage

\listoftables
\clearpage

\mainmatter % implies arabic pagenumbering
\myplain
\pagestyle{plain}

% \begin{spacing}{1.5}

\chapter{Introduction}
\lipsum[1-7]

\section{New Section}
\lipsum[8-14]

\clearpage
\plainplain
\pagestyle{plain}

\backmatter
\pagenumbering{roman}
\setcounter{page}{5}

\nocite{mybook1}
\nocite{mybook2}
\nocite{mybook3}
\nocite{mybook5}
\nocite{mybook6}
\nocite{mybook7}
\nocite{mybook8}
\nocite{mybook10}

\bibliographystyle{plainnat}

\begin{filecontents}{bibliography.bib}
@book{mybook1,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook2,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook3,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook4,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook5,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook6,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook7,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook8,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook9,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook10,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
\end{filecontents}

\bibliography{bibliography}
% \end{spacing}
\end{document}

Note that there is only a small roman page number on the top right; the same applies to the previous bibliography pages.

enter image description here

This is the erroneous version where I use spacing; there are just two lines more (\begin{spacing} and \end{spacing}):

\documentclass[12pt, a4paper, oneside, onecolumn]{book}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{setspace}
\usepackage[round]{natbib}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{%
\markright{\thesection\ #1}}
\fancyhf{} % delete current header and footer
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{0.5pt} % space for the rule
\newcommand{\plainplain}{%
  \fancypagestyle{plain}{%
      \renewcommand{\headrulewidth}{0pt}
      \fancyhead[LO]{}
      \fancyhead[RE]{}
}}
\newcommand{\myplain}{%
  \fancypagestyle{plain}{%
    \fancyhead[LO]{\bfseries\rightmark}
    \fancyhead[RE]{\bfseries\leftmark}
    \renewcommand{\headrulewidth}{0.5pt}
    }}
\plainplain
\pagestyle{plain}

\usepackage{lipsum, filecontents}

\begin{document}

\frontmatter
\pagenumbering{Roman}

\tableofcontents
\clearpage

\listoffigures
\clearpage

\listoftables
\clearpage

\mainmatter % implies arabic pagenumbering
\myplain
\pagestyle{plain}

\begin{spacing}{1.5}

\chapter{Introduction}
\lipsum[1-7]

\section{New Section}
\lipsum[8-14]

\clearpage
\plainplain
\pagestyle{plain}

\backmatter
\pagenumbering{roman}
\setcounter{page}{5}

\nocite{mybook1}
\nocite{mybook2}
\nocite{mybook3}
\nocite{mybook5}
\nocite{mybook6}
\nocite{mybook7}
\nocite{mybook8}
\nocite{mybook10}

\bibliographystyle{plainnat}

\begin{filecontents}{bibliography.bib}
    \documentclass[12pt, a4paper, oneside, onecolumn]{book}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{setspace}
\usepackage[round]{natbib}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{%
\markright{\thesection\ #1}}
\fancyhf{} % delete current header and footer
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{0.5pt} % space for the rule
\newcommand{\plainplain}{%
  \fancypagestyle{plain}{%
      \renewcommand{\headrulewidth}{0pt}
      \fancyhead[LO]{}
      \fancyhead[RE]{}
}}
\newcommand{\myplain}{%
  \fancypagestyle{plain}{%
    \fancyhead[LO]{\bfseries\rightmark}
    \fancyhead[RE]{\bfseries\leftmark}
    \renewcommand{\headrulewidth}{0.5pt}
    }}
\plainplain
\pagestyle{plain}

\usepackage{lipsum, filecontents}

\begin{document}

\frontmatter
\pagenumbering{Roman}

\tableofcontents
\clearpage

\listoffigures
\clearpage

\listoftables
\clearpage

\mainmatter % implies arabic pagenumbering
\myplain
\pagestyle{plain}

\begin{spacing}{1.5}

\chapter{Introduction}
\lipsum[1-7]

\section{New Section}
\lipsum[8-14]

\clearpage
\plainplain
\pagestyle{plain}

\backmatter
\pagenumbering{roman}
\setcounter{page}{5}

\nocite{mybook1}
\nocite{mybook2}
\nocite{mybook3}
\nocite{mybook5}
\nocite{mybook6}
\nocite{mybook7}
\nocite{mybook8}
\nocite{mybook10}

\bibliographystyle{plainnat}

\begin{filecontents}{bibliography.bib}
@book{mybook1,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook2,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook3,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook4,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook5,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook6,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook7,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook8,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook9,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook10,
    title = {\lipsum[1]},
    author = {myauthor},
    year = {2010}
}
\end{filecontents}

\bibliography{bibliography}
\end{spacing}
\end{document}

Look at the incorrect result. It should not look like that. Also, the bibliography's last page is the only page that is wrong. All the other pages are like in my example of the correct version.

enter image description here

Question: Why does spacing change the header of my bibliography's last page?

share|improve this question
1  
Please, have a look at package lipsum or blindtext –  Johannes_B Feb 4 at 18:05
    
@Johannes_B Thank you for that hint. I already used lipsum for text, but I didn't know that I could use the command in my bibliography as well. Makes sense, though, as it is part of the tex file. I changed it, and now the code is shorter. –  Tobias Feb 4 at 18:11
1  
Quickfix: Put a \clearpage before \end{spacing} –  Johannes_B Feb 4 at 18:14
    
Thank you for that quickfix! It works! This is like magic. As I searched about one and a half hour for the reason behind the problem, would you be so kind to point into the direction where I can find out what happened? I always try to understand TeX, but for this I do not have an explanation. –  Tobias Feb 4 at 18:17
2  
You shouldn't be using the spacing environment to begin with. –  egreg Feb 4 at 18:23

1 Answer 1

up vote 3 down vote accepted

You shouldn't be using the spacing environment around the whole document to begin with; this is bound to give problems, and you found out one of them. Use the spacing environment only for small chunks of text. The correct way is (assuming you must use increased interline space) to declare \onehalfspacing.

You also shouldn't redefine the plain style several times: you can name how many page styles you desire.

\documentclass[12pt,a4paper]{book}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{setspace}
\usepackage[round]{natbib}
\usepackage{lipsum, filecontents}

\setlength{\headheight}{14.5pt}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}

\fancyhf{} % delete current header and footer
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}

\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}

\fancypagestyle{plainplain}{%
  \renewcommand{\headrulewidth}{0pt}%
  \fancyhead[LO]{}%
  \fancyhead[RE]{}%
}
\fancypagestyle{myplain}{%
  \fancyhead[LO]{\bfseries\rightmark}%
  \fancyhead[RE]{\bfseries\leftmark}%
    \renewcommand{\headrulewidth}{0.5pt}%
}

\pagestyle{plainplain}

\begin{document}

\frontmatter

\tableofcontents

\listoffigures

\listoftables

\mainmatter % implies arabic pagenumbering
\pagestyle{myplain}

\onehalfspacing

\chapter{Introduction}
\lipsum[1-7]

\section{New Section}
\lipsum[8-14]


\cleardoublepage

\backmatter
\pagestyle{plainplain}
\pagenumbering{roman}
\setcounter{page}{5}

\nocite{*}

\bibliographystyle{plainnat}

\begin{filecontents}{\jobname.bib}
@book{mybook1,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook2,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook3,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook4,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook5,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook6,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook7,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook8,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook9,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook10,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
\end{filecontents}

\bibliography{\jobname}

\end{document}

One half line spacing is a typographical sin, in Italian I would use the word obbrobrio. Also resuming the Roman numbering in the back matter has no justification (other than being a prescription of some institution prepared by bureaucrats who know nothing about typography).

I have removed the oneside option, otherwise the RE or LO options would make no sense. Note that adding only 0.5pt to \headheight is insufficient (but fancyhdr tells you the required length).

If you don't want the page style plain to reemerge when chapter are started, and also avoid doing explicit declarations in the body of the document, it's easier patching the relevant commands:

\documentclass[12pt,a4paper]{book}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{setspace}
\usepackage[round]{natbib}
\usepackage{lipsum, filecontents}

\usepackage{etoolbox}

% save the last frontmatter page number
\newcounter{savepage} % save the last frontmatter page number
% no plain style at chapter openings
\patchcmd{\chapter}{\thispagestyle{plain}}{}{}{}
% choose a page style for the frontmatter
\apptocmd{\frontmatter}{\pagestyle{frontback}}{}{}
% patch \mainmatter to save the page number and to choose a new page style
\patchcmd{\mainmatter}
  {\cleardoublepage}
  {\cleardoublepage
   \setcounter{savepage}{\value{page}}%
   \pagestyle{normal}%
  }{}{}
% patch \backmatter to choose a new page style and restore the page number
\apptocmd{\backmatter}
  {\pagestyle{frontback}%
   \pagenumbering{roman}%
   \setcounter{page}{\value{savepage}}%
  }{}{}

% set the headheight to a suitable value suggested by fancyhdr
\setlength{\headheight}{14.5pt}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}

\fancyhf{} % delete current header and footer
\fancyhead[LE,RO]{\bfseries\thepage}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}

\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0pt}

\fancypagestyle{frontback}{%
  \renewcommand{\headrulewidth}{0pt}%
  \fancyhead[LO]{}%
  \fancyhead[RE]{}%
}

\fancypagestyle{normal}{%
  \fancyhead[LO]{\bfseries\rightmark}%
  \fancyhead[RE]{\bfseries\leftmark}%
  \renewcommand{\headrulewidth}{0.5pt}%
}

\begin{document}

\frontmatter

\tableofcontents

\listoffigures

\listoftables

\mainmatter % implies arabic pagenumbering

\onehalfspacing

\chapter{Introduction}
\lipsum[1-7]

\section{New Section}
\lipsum[8-14]


\cleardoublepage

\backmatter

\nocite{*}

\bibliographystyle{plainnat}

\begin{filecontents}{\jobname.bib}
@book{mybook1,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook2,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook3,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook4,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook5,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook6,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook7,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook8,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook9,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
@book{mybook10,
    title = {\lipsum*[1]},
    author = {myauthor},
    year = {2010}
}
\end{filecontents}

\bibliography{\jobname}

\end{document}
share|improve this answer
    
Thank you very much for your time. Yes, I use this layout because of my institution's rules. Have you noticed that my chapter beginnings are now differently formatted in your version, although you solved my initial problem? The bibliography and every other "first page" now have the page number centered at the bottom. This is probably because of the missing redefinition of plain. Is there a way to fix this using your optimized solution? –  Tobias Feb 4 at 18:36
    
@Tobias What do you want for those first pages? –  egreg Feb 4 at 18:43
    
@egreg thanks for making some remarks on the matter. I really didn't have the time. –  Johannes_B Feb 4 at 18:45
1  
1  
@Tobias I've added a new version that should suit your needs. You have my sympathy for being forced to use such a horrible layout. –  egreg Feb 4 at 20:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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