
私は誰かのために文書をフォーマットしているのですが、その人は各セクション番号を 000 から始まる 3 桁の数字にして、必要に応じてゼロを埋め込むことを希望しています。
同様の質問を見つけたので、例を当てはめてみました、しかしそれは私に
! 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
そこには存在しないカーネルデフォルトでは、定義することができます。また、セクションの目次関連の番号間隔も調整する必要があります。
\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}}
言う。
カウンターにゼロを埋め込む方法の詳細については、先頭にゼロが付いたカウンターを出力するにはどうすればよいでしょうか?