我有十多个部分想要在目录中列出,如下所示:
这意味着我需要0
在 的节前面添加 s \ifnum\thesection<10
。如何在目录中执行此操作?
MWE
:
\documentclass[10pt,a4paper]{article}
\usepackage{titlesec,titletoc}
\titleformat{\section}{\Large\bfseries}{
\ifnum\thesection<10 Q 0\thesection
\else Q \thesection \fi
}{0.5em}{}
\titlecontents{section}[0.5em]{}{
\large \textbf{Q\contentsmargin{20pt} \thecontentslabel\enspace} }
{\contentsmargin{20pt}\normalfont}{\titlerule*[1mm]{ $\cdot$}\contentspage}
[\addvspace{-2pt}]
\begin{document}
\tableofcontents
\section{}
% Returns "Q 1 ..." for ToC
% Returns "Q 01 ..." for Section Heading
\end{document}
答案1
这是我通过重新定义尝试\thesection
:
\documentclass[10pt,a4paper]{article}
%\makeatletter
\renewcommand{\thesection}{\ifnum\value{section}<10 Q~{0\arabic{section}}\else Q~\arabic{section}\fi}
%\makeatother
\usepackage{titlesec,titletoc}
\titleformat{\section}{\Large\bfseries}{\thesection}{0.5em}{}
\begin{document}
\tableofcontents
\section{}
\section{}
\section{}
\section{}
\section{}
\section{}
\section{}
\section{}
\section{}
\section{}
\section{}
\section{}
\subsection{}
\subsection{}
\subsection{}
\end{document}