[Tex/LaTex] How to change section numbering formatting

sectioning

I’m looking for a way (or a package) to change or control the formatting of the numbers of a section. By formatting, I mean the fonts and the like, not the formatting of the number

As far as I can see, the only way seems to redefine the @sect command, for example. But I’d prefer to avoid this: as you can see, I’m not a TeX expert.

Best Answer

For extensive changes to the sectional titles, titlesec is the package to go. For less extensive changes, you can go with internals.

\documentclass{article}

\makeatletter
\renewcommand{\@seccntformat}[1]{%
  \begingroup
  \@nameuse{additional@cntformat#1}%
  {\@nameuse{the#1}}%
  \endgroup
  \quad
}
\newcommand{\setformat}[2]{%
  \@namedef{additional@cntformat#1}{#2}%
}
\makeatother

\setformat{section}{\itshape}
\setformat{subsection}{\normalfont}
\setformat{subsubsection}{\fbox}

\begin{document}

\section{Example of section}

\subsection{Example of subsection}

\subsubsection{Example of subsubsection}

\end{document}

The last token in the second argument to \setformat can take an argument, like in the example for \subsubsection.

enter image description here