I am trying to stylize the numbering of sections/subsections/subsubsections using renewcommand like this:


This works great for the main matter; however, it alters the formatting for the table of contents as well. How can I avoid having these changes roll over to the table of contents?

EDIT: This is for a LaTeX book, and it is divided into \frontmatter and \mainmatter if that makes a difference.

  • The assumption is that you're open to package-wise alternatives, rather than manually adjusting the counter representations. That is, you're not limited to just using your approach...
    – Werner
    Jun 25, 2014 at 19:50
  • Indeed, I am open to any alternative. I simply don't know of any :\ . I'm quite new at LaTeX, so I apologize if this seems trivial.
    – Jason
    Jun 25, 2014 at 19:54
  • @Werner I have tried to add \makeatletter with a \if@mainmatter statement, but that didn't seem to work.
    – Jason
    Jun 25, 2014 at 19:59
  • I don't see what the \hspace{2em} is here for. Shifting (sub)subsections titles with respect to section titles?
    – Bernard
    Jun 25, 2014 at 20:55
  • @Bernard exactly. I was trying to indent the subsections in a bit
    – Jason
    Jun 25, 2014 at 21:17

1 Answer 1


What you should do is reformatting the sections, subsections, &c. Redefining numbering as you do changes the section numbers are printed everywhere in the document (incl. title of contents and referencing in the text!).

Here is a way, using the titlesec package. As OpenSans is not installed on my system, I repplaced it with cabin – another sansserif font.


\titleformat{\section}[hang]{\sffamily\bfseries\Large}{Section \thesection.}{0.4em}{}



\subsection{A subsection}
\subsection{Another subsection}

\section{Another section}
See \Cref{sec:prelim}.


In this code, in short the first argument of \titleformat is the name of the sectioning command, the second (between brackets) is its style . The third argument is made of commands that are applied to both the label and the title, the fourth formats the label, the fifth is the spacing between label and title and in the sixth are commands that are applied before the title; with option explicit, the title can be referred to as #1. There is a seventh (optiaanl) argument, unused here, that contains code to be applied after the title.

The spacing command has the same first argument; the second is the increase of the left margin, the third is vertical space before the title and the fourth is the spacing between title and the following text.

The interpretation of the different parameters can vary according to the style of the sectioning command, and mamy more details are explained in the documentation, § 3.

enter image description here

  • That works great! Would you mind explaining how the titleformat and titlespacing works? I've seen them before, but the notation is seems pretty daunting.
    – Jason
    Jun 26, 2014 at 0:31
  • Yes of course. I'll do that in a moment.
    – Bernard
    Jun 26, 2014 at 0:56

You must log in to answer this question.

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