Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

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

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

share|improve this answer
    
I need this for description. –  user14416 Nov 27 '12 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 '12 at 23:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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