[Tex/LaTex] Description numbering

descriptionlistsnumbering

I have an article document. In this document I have sections and subsections. In a subsection there are nested 'description' lists. I want that items of this description have numbers which use the number of the subsection and nested case the number of the parent description.

4.1. Subsection
  4.1.1. Item 1 of Description 1
    4.1.1.1. Item 1 of Description 2
    4.1.1.2. Item 2 of Description 2
  4.1.2. Item 2 of Description 1

How I can achieve that?

Best Answer

I have no idea why you would do this using a description environment and not an enumerate (as in the other answer), but who am I to question? :)

In the code below, I've borrowed some ideas from Enumerated description list and have introduced a couple of new counters descriptcounti and descriptcountii; if you plan to have deeper lists, just keep going (descriptcountiii, etc)

screenshot

\documentclass{article}

\usepackage{enumitem}

% first level
\newcounter{descriptcounti}
\setlist[description]{%
  before={\setcounter{descriptcounti}{0}},%
  ,font=\bfseries\refstepcounter{descriptcounti}\thesubsection.\thedescriptcounti~}

% second level
\newcounter{descriptcountii}
\setlist[description,2]{%
  before={\setcounter{descriptcountii}{0}},%
  ,font=\bfseries\refstepcounter{descriptcountii}\thesubsection.\thedescriptcounti.\thedescriptcountii~}
\begin{document}


\setcounter{section}{4} % just for demonstration
\subsection{Sub section}
\begin{description}
    \item item one
    \item item two
    \item item three
    \begin{description}
        \item item one
        \item item two
        \item item three
    \end{description}
\end{description}

\end{document}

Following the comments, you can easily apply this to a custom description, say mydesc, by using \newlist

\documentclass{article}

\usepackage{enumitem}

\newlist{mydesc}{description}{5}

% first level
\newcounter{descriptcounti}
\setlist[mydesc]{%
  before={\setcounter{descriptcounti}{0}},%
  ,font=\bfseries\refstepcounter{descriptcounti}\thesubsection.\thedescriptcounti~}

% second level
\newcounter{descriptcountii}
\setlist[mydesc,2]{%
  before={\setcounter{descriptcountii}{0}},%
  ,font=\bfseries\refstepcounter{descriptcountii}\thesubsection.\thedescriptcounti.\thedescriptcountii~}
\begin{document}


\setcounter{section}{4} % just for demonstration
\subsection{Sub section}
\begin{mydesc}
    \item item one
    \item item two
    \item item three
    \begin{mydesc}
        \item item one
        \item item two
        \item item three
    \end{mydesc}
\end{mydesc}

\end{document}
Related Question