3

I have more than ten sections that I want to list in the ToC as the following:

enter image description here

Which means I need to prepend 0s to sections of \ifnum\thesection<10. How do I do this in the ToC?

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
1

This is my try by redefining \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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.