# Changing section number format without changing ToC

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

\renewcommand{\thesection}{\opensans\arabic{section}}
\renewcommand{\thesubsection}{\hspace{2em}\bfseries\thesection.\alph{subsection}}
\renewcommand{\thesubsubsection}{\hspace{2em}\thesubsection.\roman{subsubsection}}


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 '14 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 '14 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 '14 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 '14 at 20:55
• @Bernard exactly. I was trying to indent the subsections in a bit – Jason Jun 25 '14 at 21:17

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.

\documentclass[11pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{heuristica}
\usepackage{ebgaramond}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage[dotinlabels]{titletoc}
\titleformat{\section}[hang]{\sffamily\bfseries\Large}{Section \thesection.}{0.4em}{}
\titlespacing*{\section}{0pt}{2\baselineskip}{1.25\baselineskip}
\titleformat{\subsection}[hang]{\sffamily\bfseries\large}{\thesubsection}{0.4em}{}
\titlespacing*{\subsection}{2em}{1\baselineskip}{1\baselineskip}
\dottedcontents{section}[3.8em]{}{2.3em}{1pc}
\usepackage{cleveref}

\begin{document}

\tableofcontents

\section{Preliminaries}\label{sec:prelim}
\subsection{A subsection}
\lipsum[1]
\subsection{Another subsection}
\lipsum[2]

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

\end{document}


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.

• 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 '14 at 0:31
• Yes of course. I'll do that in a moment. – Bernard Jun 26 '14 at 0:56