# \end{Document} No Line Here to End

I keep getting an error:

line 44: There's no line here to end. \end{document}


This error does not happen when I use the \maketitle command instead of \begin{document}environment.

Can anyone suggest what I need to change please?

%Preamble
\documentclass[british]{report}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{graphicx} %Allows images
\graphicspath{ {images/} } %Sets image folder location
\usepackage[useregional,showdow]{datetime2} %Allows dynamically updating date
\definecolor{lightblue}{RGB}{91,155,213} %Defines Light Blue colour for use
\pagestyle{fancy}
\title{\bfseries{XXX: Xxxx 12 Xxxxxxxxx Xxxxxxxxxxx - Xxxxxxxxx 1}}\\
\author{Xxxx Xxxx Xxxxxx Xxxxx}\\
XXX: 12345678 $\vert$ XXX: 12345678}}
\fancyfoot[C]{\sffamily{$\thepage$ of $\pageref{LastPage}$}}

\fancypagestyle{empty}{\renewcommand{\headrulewidth}{0pt}\fancyhead{} \fancyfoot[C]{$\thepage$ of $\pageref{LastPage}$}}

\renewcommand{\familydefault}{\sfdefault} %Changes document default font to Helvetica

%Document Information
\title{XXX: Xxxx 12 Xxxxxxxxx Xxxxxxxxxxx - Xxxxxxxxx 1}
\author{Xxxx Xxxx Xxxxxx Xxxxx}

%Document Content
\begin{document}
\begin{titlepage}
Some Text
\end{titlepage}

%\maketitle
%\clearpage

\section*{Question 1}
\setcounter{page}{2}
test

\section*{Question 2}
test

\section*{Question 3}
test
\end{document}

• The problem is the \fancyhead statement. Note that the \title and \author commands do not typeset anything, they just define author and title for later use by \maketitle. So your \\  commands both end lines containing nothing (there is no line to end). – gernot Dec 14 '16 at 13:04

The reason for the missing line to end is already explained by Jan's answer. \title and \author does not set their argument, they store the settings in internal macros \@title and \@author, which are later used and cleared by \maketitle.

Since the title and author are used at several places, macros can be used to avoid redundancy.

Further remarks:

• \bfseries and \sffamily are font switch commands, which does not take arguments. The argument forms are \textbf{...} and \textsf{...}.

• I do not see a reason to put the page numbers in math mode. Page numbers are usually set in text mode.

• Since the default font family is set to the non-serif font, \sffamily is not needed in the fancy headers/footers.

Full example:

\documentclass[british]{report}
\usepackage[utf8]{inputenc}
\usepackage[
a4paper,
left=25mm,
right=25mm,
top=30mm,
bottom=25mm,
]{geometry} %Formats page
\usepackage{babel}
\usepackage{graphicx} %Allows images
\graphicspath{ {images/} } %Sets image folder location
\usepackage[useregional,showdow]{datetime2} %Allows dynamically updating date
\definecolor{lightblue}{RGB}{91,155,213} %Defines Light Blue colour for use

%Document Information
\newcommand*{\MyTitle}{XXX: Xxxx 12 Xxxxxxxxx Xxxxxxxxxxx - Xxxxxxxxx 1}
\newcommand*{\MyAuthor}{Xxxx Xxxx Xxxxxx Xxxxx}
\title{\MyTitle}
\author{\MyAuthor}

\pagestyle{fancy}
\textcolor{lightblue}{%
\textbf{\MyTitle}\\
\MyAuthor\\
XXX: 12345678 $\vert$ XXX: 12345678%
}%
}
\fancyfoot[C]{\thepage\ of \pageref{LastPage}}

\fancypagestyle{empty}{%
\fancyfoot[C]{\thepage\ of \pageref{LastPage}}%
}

\renewcommand{\familydefault}{\sfdefault}

%Document Content
\begin{document}
\begin{titlepage}
Some Text
\end{titlepage}

%\maketitle
%\clearpage

\section*{Question 1}
\setcounter{page}{2}
test

\section*{Question 2}
test

\section*{Question 3}
test

\end{document}


I tink, that your error is, to define the \title and \author within the definition of your fancyhead.

\fancyhead[C]{\textcolor{lightblue}{
\title{\bfseries{XXX: Xxxx 12 Xxxxxxxxx Xxxxxxxxxxx - Xxxxxxxxx 1}}\\
\author{Xxxx Xxxx Xxxxxx Xxxxx}\\
XXX: 12345678 $\vert$ XXX: 12345678}}


This are definitions, which shouldn't be defined within the defintion of your fancy head. (Some lines later, you use those two commands again.)

While setting the \title in \fancyhead, you don't produce a line of output. Instead, you store the contents of {} into a variable, which will be used later on. Hence, you can't use \\ as linebreak. There is no such line before the \\!

Bye

Jan