# Table of Contents causes “! LaTeX Error: There's no line here to end.”

I'm trying to add a table of contents to a template which I found on Sharelatex.com, but upon adding \tableofcontents, I obtain the error "! LaTeX Error: There's no line here to end."

Anyone has a clue as to what went wrong? Thanks in advance!

\documentclass[11pt,a4paper,oldfontcommands]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage[dvips]{graphicx}
\usepackage{xcolor}
\usepackage{times}

\usepackage[
breaklinks=true,colorlinks=true,
%linkcolor=blue,urlcolor=blue,citecolor=blue,% PDF VIEW
linkcolor=black,urlcolor=black,citecolor=black,% PRINT
bookmarks=true,bookmarksopenlevel=2]{hyperref}

\usepackage{fix-cm}
\usepackage{xcolor}
\usepackage{titlesec}
\definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{0pt}}
\titleformat{\chapter}[hang]{\flushright
\fontseries{b}\fontsize{80}{100}\selectfont}{\fontseries{b}\fontsize{100}{130}\selectfont \textcolor{gray75}\thechapter\hsp}{0pt}{\\ \Huge\bfseries}[]

%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%

\begin{document}

%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%
%   TITLEPAGE
%
%   due to variety of titlepage schemes it is probably better to make titlepage manually
%
%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%
\thispagestyle{empty}

{%%%
\sffamily
\centering
\Large

~\vspace{\fill}

{\huge
Thesis title: may be long or short
}

\vspace{2.5cm}

{\LARGE
Your name
}

\vspace{3.5cm}

A thesis submitted in partial fulfillment for the\\
degree of Doctor of Philosophy\\[1em]
in the\\[1em]
Faculty Name\\
University Name

\vspace{3.5cm}

Supervisor: Prof. Joe Doe

\vspace{\fill}

May 2013

%%%
}%%%

\cleardoublepage
%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%
%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%
\tableofcontents

\clearpage

%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%
%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%---%%%

\chapter{Introduction}

\section{First section}

\bibliographystyle{unsrt}
\bibliography{references}

\end{document}

• Welcome to TeX.SX! \titleformat{\chapter}[hang]{\flushright \fontseries{b}\fontsize{80}{100}\selectfont}{\fontseries{b}\fontsize{100}{130}\selectfont \textcolor{gray75}\thechapter\hsp}{0pt}{\\ \Huge\bfseries}[] is causing the error. – Bobyandbob Jun 24 '18 at 9:27

## 2 Answers

The code to format chapter titles has an error – \\ in the last mandatory argument. Furthermore it is much too complicated. With the tools provided by titlesec, you obtain the correct result (a small difference in the height placement of the chapter number, which can be taken care of with \titlespacing if necessary):

\titleformat{\chapter}[display]{\filleft\Huge\bfseries}{\fontsize{100}{100}\selectfont\textcolor{gray75}\thechapter}{1ex}{}[]%


• Thank you! I am able to run the code to achieve the required format now. :) – Stoner Jun 24 '18 at 10:25

the error means you have mis-used \\ and in this case

{\\ \Huge\bfseries}[]


You can not start a title with a line break as, as the error says, there is no line to end at that point.

• Thank you for the help! It works fine now :) As @Bernard has solved the main issue of having the required format (chapter number above chapter title), I will mark his as the solution to my question. Really sorry about that.. – Stoner Jun 24 '18 at 10:25
• @Stoner don't worry, we both have enough points that 15 here or there will not ruin our day:-) – David Carlisle Jun 24 '18 at 10:26