
Estou formatando um documento para alguém e ele deseja que cada número de seção tenha três dígitos, começando com 000 e com preenchimento de zeros quando necessário.
Encontrei uma pergunta semelhante e tentei adaptar o exemplo, mas isso me dá uma
! TeX capacity exceeded, sorry [input stack size=5000].
\thesection ->\thesection
.\three@digits {\value {section}}
l.11 \section{Synopsis}
If you really absolutely need more capacity,
you can ask a wizard to enlarge me.
Meu MNWE é:
\documentclass[letterpaper]{article}
%Padding the leading zeros \makeatletter
\renewcommand\thesection{\thesection.\three@digits{\value{section}}}
\makeatother
\begin{document} \setcounter{section}{-1} \tableofcontents
\section{Synopsis} foo
\section{Language} bar
\section{Legal} baz
\end{document}
Responder1
Não existe \three@digits
nonúcleopor padrão. No entanto, você pode defini-lo e também precisa ajustar o espaçamento numérico relacionado ao ToC para as seções:
\documentclass[letterpaper]{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
%Padding the leading zeros
\makeatletter
\patchcmd{\l@section}{1.5em}{2em}{}{}% Adjust section ToC number width
%\def\two@digits#1{\ifnum#1<10 0\fi\number#1}% http://mirrors.ctan.org/macros/latex/unpacked/latex.ltx
\def\three@digits#1{\ifnum#1>99\else\ifnum#1>9 0\else00\fi\fi\number#1}
\renewcommand\thesection{\three@digits{\value{section}}}
\makeatother
\begin{document}
\setcounter{section}{-1}
\tableofcontents
\section{Synopsis} foo
\section{Language} bar
\section{Legal} baz
\end{document}
O espaçamento relacionado ao ToC é ajustado usando umetoolbox
correção. Você \subsection
também pode querer ajustar o espaçamento, que é definido como
\newcommand*\l@subsection{\@dottedtocline{2}{1.5em}{2.3em}}
por padrão (dearticle.cls
). Aqui 1.5em
está o recuo e 2.3em
o espaço para os números. Então você pode ir com
\renewcommand*\l@subsection{\@dottedtocline{2}{2em}{3em}}
dizer.
Para obter mais informações sobre preenchimento de contadores com zeros, consulteComo gerar um contador com zeros à esquerda?