描述编号

描述编号

我有一份article文件。这份文件中有章节和子章节。在子章节中有嵌套的“描述”列表。我希望此描述中的项目具有使用子章节编号的编号,嵌套情况下使用父描述的编号。

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

我怎样才能实现这个目标?

答案1

我不知道为什么您要使用description环境而不是enumerate(如其他答案中所述)来执行此操作,但我又有什么资格质疑呢?:)

在下面的代码中,我借鉴了一些想法枚举描述列表并引入了几个新的计数器descriptcountidescriptcountii;如果您打算有更深的列表,请继续(descriptcountiii,等)

截屏

\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}

按照评论,您可以轻松地将其应用于自定义描述,例如mydesc,通过使用\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

这对你有什么用处?

\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}

在此处输入图片描述

相关内容