2

I want to create a numbered list, where each item number is prefixed by the section number. This answer shows how to make customized prefixes using the enumitem package. But the problem is I have to hard code the section number. Is there a way to populate the section number automatically?

\documentclass{article}

\usepackage{enumitem}

\begin{document}

\begin{enumerate}[leftmargin=*,label=Q1.1.\arabic*]
\item First question
\item Second question
\end{enumerate}

\end{document}
5
  • 1
    Did you try label=\thesection.\arabic*?
    – Bernard
    Commented Feb 18, 2021 at 14:37
  • Perfect! I used label=\textbf{\thesubsection.\arabic*} to get the subsection number as well. If you write this as an answer, I will accept it Commented Feb 18, 2021 at 16:15
  • Thank you. I don't think it's necessary , as I'm pretty sure there already exists such an answer (albeit I don't know where, exactly).
    – Bernard
    Commented Feb 18, 2021 at 17:23
  • Should add \protect before label. Commented Jul 19, 2021 at 11:01
  • What will that do? Commented Jul 20, 2021 at 3:41

2 Answers 2

1

Bernand's suggestion worked. Below is the complete code

\documentclass{article}

\usepackage{enumitem}

\begin{document}

\begin{enumerate}[leftmargin=*,label=\thesubsection.\arabic*]
\item First question
\item Second question
\end{enumerate}

\end{document}
1

A global setting is as follows:

\documentclass{article}

\usepackage{enumitem}
\renewcommand{\labelenumi}{(\thesection.\theenumi)} %i,ii,iii,...

\title{A Test}
\begin{document}
\maketitle
    \section{Enumeration Numbers}
    \begin{enumerate}
        \item First question
        \item Second question
    \end{enumerate}
    
\end{document}

And the output is

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .