
Я форматирую документ для одного человека, и он хочет, чтобы каждый номер раздела состоял из трех цифр, начиная с 000, и при необходимости дополнялся нулями.
Я нашел похожий вопрос и попытался адаптировать пример., но это дает мне
! 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.
Мой 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}
решение1
Там не существует \three@digits
вядропо умолчанию. Однако вы можете определить его, и вам также нужно будет настроить интервал между цифрами, связанный с ToC, для разделов:
\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}
Интервал, связанный с ToC, регулируется с помощьюetoolbox
патч. Вы также можете захотеть настроить \subsection
интервал, который определяется как
\newcommand*\l@subsection{\@dottedtocline{2}{1.5em}{2.3em}}
по умолчанию (изarticle.cls
). Вот 1.5em
отступ и 2.3em
место для цифр. Так что вы можете пойти с
\renewcommand*\l@subsection{\@dottedtocline{2}{2em}{3em}}
сказать.
Подробнее о заполнении счетчиков нулями см.Как вывести счетчик с ведущими нулями?