6

I have a line of code to hide "Chapter" and just head every chapter in the format "ChapterNumber" + "." + "ChapterTitle". However, the Table of Contents is assumed to be "Chapter 0", so it shows "0. Contents". Is there any way to hide this "0." so it shows "Contents" only?

Code used:

\documentclass[a4paper,12pt,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}
\titleformat{\chapter}{}{}{0em}{\bf\LARGE\thechapter.~}

How the zero appears in the Contents table

1
  • 1
    In the KOMA-Script classes your wish is the default behaviour, you might want to have a look. scrreprt is the corresponding class to standard report. Also note that usage of \bf is deprecated since 1994
    – MaxNoe
    Feb 23, 2015 at 12:47

2 Answers 2

3

Note that I used \bfseries instead of the long, long deprecated \bf and used \arabic{chapter} to format the number, you might also want to try \Roman{chapter} for example.

Update: second version (thanks to egreg)

As this answer is the checked one, I'll include egregs more correct one, which uses correctly the possibilities of \titleformat, which has 4 mandatory arguments:

\titleformat{<command>}{<format>}{<label>}{<sep>}{<before-code>}

  • <command> is the sectioning command you want to change, in your case \chapter.
  • <format> are text formatting commands to be applied, you want to use \bfseries\Large
  • <label> formats the label if the chapter is numbered, it is left out when not. You want \arabic{chapter}.~
  • <sep> is the hspace between <label> and the actual title, set it to {0pt}
  • <before-code> is arbitrary code that should be called before the title is typeset

So your version of \titleformat should be:

\titleformat{\chapter}{\bfseries\Large}{\arabic{chapter}.~}{0pt}{}

First Version, you should not use this:

You can check if \thechapter is greater than zero:

\documentclass[a4paper,12pt,twoside]{report}

\usepackage{titlesec}

\titleformat{\chapter}{}{}{0em}{\bfseries\LARGE\ifnum\value{chapter}>0\relax\arabic{chapter}.~\fi}

\begin{document}
\tableofcontents
\chapter{Test I}
\chapter{Test II}
\end{document}

Output: Table of contents:

Table of Contents

First Chapter with some blindtext:

Chapter 1

4
  • This is not the right way... Feb 23, 2015 at 13:19
  • I see, i will delete this and upvote egregs answer, if this gets unchecked.
    – MaxNoe
    Feb 23, 2015 at 13:21
  • @MaxNoe It should be \ifnum\value{chapter}>0, not \ifnum\thechapter, as you don't know whether \thechapter expands to a number.
    – egreg
    Feb 23, 2015 at 13:22
  • Your answer is far more elegent anywasys ;)
    – MaxNoe
    Feb 23, 2015 at 13:24
6

You want a different way to use \titleformat. The third mandatory argument to \titleformat specifies what's used for numbered chapters, while the final argument specifies the title proper; in this case nothing apart printing the title should be done.

\documentclass[a4paper,12pt,twoside]{report}

\usepackage{titlesec}

\titleformat{\chapter}{\LARGE\bfseries}{\thechapter.\ }{0em}{}

\begin{document}
\tableofcontents
\chapter{Test I}
\chapter{Test II}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .