3

I am trying to make it so that my chapters aren't labelled as 'chapter 1', 'chapter 2' etc. I just want it to have the number, with no 'chapter'. I want the word 'chapter' gone. A quick Google search showed me how to accomplish this with the titlesec package, namely

\usepackage{titlesec}

\titleformat{\chapter}{}{}{0em}{\bf\LARGE}

Which works for me. However, I don't like just using code without understanding it, can someone tell me what this means? I tried to read through the documentation but I had trouble understanding why that code above results in omission of 'chapter #' before chapters.

Johannes_B
  • 24,235
  • 10
  • 93
  • 248
hex93
  • 151
  • 3
  • 1
    The titlesec documentation is not clearly laid out, unfortunately. But here the answer is pretty simple: The first set of empty braces effectly tells titlesec to have no "format" (in the sense meant by the package); the next empty braces do the same for "label". Also, since you are using LaTeX, use \bfseries, not \bf. – jon Mar 07 '15 at 21:23
  • 1
    A complete guide would require rewriting the manual, which is not the object of this site. Can you narrow your request? – egreg Mar 07 '15 at 21:36
  • Sure, I was only really curious about this command in particular. – hex93 Mar 07 '15 at 22:41
  • ^^^ I'm pretty new to LaTeX, what does no label imply? Is that why LaTeX doesn't add the heading? – hex93 Mar 07 '15 at 22:42
  • 1
    Since you used an empty third argument, no label is used; in particular, no string "Chapter" (or "Appendix") will be used for the titles and no counter will appear; notice, however, that the counter won't print in the title but it is still there (it will be show in The ToC, for example). – Gonzalo Medina Mar 07 '15 at 23:14
  • @PratikSamant I added an answer below, let me know if you want some additional explanation. – Gonzalo Medina Mar 07 '15 at 23:41

2 Answers2

5

Since you used an empty third argument, no label is used; in particular, no string "Chapter" (or "Appendix") will be used for the chapter headings and no counter will appear; notice, however, that the counter won't print in the title but "it is still there" (it will be show in The ToC, for example).

No optional first argument was also used in your definition, so the <shape> will default to hang, which is the shape used by section headings in standard classes.

In your description you said that you only wanted to suppress the string "Chapter" (or "Appendix") but keeping the numbering, so a better option would be to use something like

\titleformat{\chapter}
  {\bfseries\LARGE}
  {\thechapter}
  {0.5em}
  {}

Notice that I added \thechapter in the third mandatory argument, so the counter will be typeset and also I moved \bfseries\LARGE from the fifth mandatory argument to the second one; in this way the formatting will affect both the label (the counter, in this case) and the title; with your settings (used in the fifth argument) it would only affect the title but not the label.

A complete example:

\documentclass{book}
\usepackage{titlesec}

\titleformat{\chapter}
  {\bfseries\LARGE}
  {\thechapter}
  {0.5em}
  {}

\begin{document}

\chapter{Test chapter}
Some test text

\end{document}

The result:

enter image description here

As a side note, \bf is a TeX command which shouldn't be used in LaTeX documents; use \bfseries instead in LaTeX2e documents.

The documentation of titlesec explains, in page 4, the general syntax and the meaning for the arguments of \titleformat. I see no point in repeating here what appears there.

Gonzalo Medina
  • 505,128
3

Right as I start this answer, I see Gonzalo's reference to page 4 of the documentation, which I was about to repeat and annotate here. Oh, well.

Your found code:

\titleformat{\chapter}{}{}{0em}{\bf\LARGE}

From page 4 of the titlesec documentation:

\titleformat{command}[shape]{format}{label}{sep}{before-code}[after-code]

The optional arguments shape and after-code were omitted from your example, so you've effectively run

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

with command of chapter, format and label empty, sep of 0em, and before-code of \bf\LARGE (which should be \bfseries\LARGE since around 1994).

  • format corresponds to commands used to format the entire division. In your case, it's empty, or the \bfseries\LARGE from before-code could be moved there.

  • label corresponds to commands typeset the division label and number. Yours is empty to suppress the label and number, but you could use any macros with \titlechaptername, \thechapter, or other commands or text.

  • sep is the separation between the document division label and the document division title. In your case, 0em keeps it aligned with the left margin of the body text. Other chapter shapes may use this to control the vertical space between the label and the title.

  • before-code is code preceding your division title. Yours is \bf\LARGE, but it could include decorative rules, vertical spaces, or other commands. It could also be empty if you put your format commands in the format parameter instead.

Mike Renfro
  • 20,550