Page LayoutChanging section number formatting

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
melwil
Posts: 2
Joined: Sat Feb 27, 2010 10:42 pm

Changing section number formatting

Post by melwil »

Hi,

I was wondering how I could change \section{section title} output from

"1 section title"

to

"001 section title"


I tried asking around a bit, and titlesec + fmtcount should do the job (somehow). I can not figure out how to do it though.
Anyone got a clue how to achieve it?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Changing section number formatting

Post by localghost »

It requires a redefinition of the command that formats the section counter. See code below for a complete example.

Code: Select all

\documentclass{article}

\makeatletter
\renewcommand{\thesection}{%
  \ifnum \c@section<100 0\fi \ifnum \c@section<10 0\fi \@arabic\c@section
}
\makeatother

\begin{document}
  \section{Test}

  \setcounter{section}{9}
  \section{Test}

  \setcounter{section}{99}
  \section{Test}
\end{document}

Best regards and welcome to the board
Thorsten
melwil
Posts: 2
Joined: Sat Feb 27, 2010 10:42 pm

Re: Changing section number formatting

Post by melwil »

wow, worked perfectly! =D

thanks for the welcome and help, that was a very good solution and a quick reply. I feel that I am going to love it here =)
Post Reply