4

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?

2 Answers 2

4

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}
2
  • Is it possible to left description as it was, but create the same list with another name (for ex., mydesc)?
    – user14416
    Nov 28, 2012 at 14:52
  • @user14416 yes, absolutely :) see my updated answer
    – cmhughes
    Nov 28, 2012 at 16:13
1

How does this work for you?

\documentclass{article}
\begin{document}
\renewcommand{\labelenumi}{\bfseries\arabic{enumi}} 
\renewcommand{\labelenumii}{\bfseries\arabic{enumi}.%
                            \arabic{enumii}} 
\renewcommand{\labelenumiii}{\bfseries\arabic{enumi}.%
                             \arabic{enumii}.\arabic{enumiii}} 
\renewcommand{\labelenumiv}{\bfseries\arabic{enumi}.%
                            \arabic{enumii}.\arabic{enumiii}.%
                            \arabic{enumiv}}

  \begin{enumerate}
  \item Starting at the first level
        \begin{enumerate}
          \item Now we're at the second level
          \item This is the second item on the second level
                \begin{enumerate}
                  \item Now we're three levels deep.
                  \item Let's go deeper with an itemized list.  
                        Let's list fruits.
                        \begin{enumerate}
                          \item Bananas
                          \item Oranges
                          \item Apples
                        \end{enumerate}
                \end{enumerate}
          \item We're back to the second level.
        \end{enumerate}
  \item Back to the first level
  \end{enumerate}

\end{document}

enter image description here

2
  • I need this for description.
    – user14416
    Nov 27, 2012 at 22:25
  • 1
    I'm a bit confused then. You're description shows what is essentially an enumerated list. I'm unclear about what effect you want from description.
    – A.Ellett
    Nov 27, 2012 at 23:35

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.