自定义描述环境

自定义描述环境

我想定义一个induction类似于description环境的环境。我想到的是

\begin{induction}{A}
\item[a1] Part $a1$ of the induction proof.
\item[a2] Part $a2$ of the induction proof. This one needs a further induction argument over $B$.
\begin{induction}{B}
\item[b1] Part $b1$ of the induction proof.
\end{induction}
\end{induction}

应该

\begin{enumerate}
\item[($A$-induction, $a1$)] Part $a1$ of the induction proof.
\item[($A$-induction, $a2$)] Part $a2$ of the induction proof. This one needs a further induction argument over $B$.
\begin{enumerate}
\item[($B$-induction, $b1$)] Part $b1$ of the induction proof.
\end{enumerate}
\end{enumerate}

我曾尝试重新定义,\descriptionlabel但我这样做的方式却遇到了嵌套感应环​​境的麻烦。

答案1

这是一种可能性,通过重新定义每个环境\descriptionlabel开始时的工作方式:induction

在此处输入图片描述

\documentclass{article}

\newenvironment{induction}[1]
  {\renewcommand{\descriptionlabel}[1]{\hspace\labelsep\normalfont\bfseries$#1$-induction, $##1$}%
   \begin{description}}
  {\end{description}}
\begin{document}

\begin{induction}{A}
  \item[a1] Part~$a1$ of the induction proof.
  \item[a2] Part~$a2$ of the induction proof. This one needs a further induction argument over~$B$.
  \begin{induction}{B}
    \item[b1] Part~$b1$ of the induction proof.
  \end{induction}
\end{induction}

\end{document}

在您的使用中我可能会改变的一件事是提供$A$而不是A;也就是说,删除自动数学模式插入induction和的参数\item


description上述解决方案在环境中重用了环境induction。如果您希望混合使用两者,最好将其定义induction为完全独立于description

在此处输入图片描述

\documentclass{article}

\providecommand*\inductionlabel{}

\makeatletter
\newenvironment{induction}[1]
  {\renewcommand{\inductionlabel}[1]{\hspace\labelsep\normalfont\bfseries$#1$-induction, $##1$}%
   \list{}{\labelwidth\z@ \itemindent-\leftmargin
          \let\makelabel\inductionlabel}}
  {\endlist}
\makeatother

\begin{document}

\begin{induction}{A}
  \item[a1] Part~$a1$ of the induction proof.
  \item[a2] Part~$a2$ of the induction proof. This one needs a further induction argument over~$B$.
  \begin{induction}{B}
    \item[b1] Part~$b1$ of the induction proof.
    \begin{description}
      \item[something] something else
    \end{description}
  \end{induction}
\end{induction}

\end{document}

答案2

您可以使用以下方法获取所需内容,并在类似枚举的环境中自动对项目进行编号enumitem

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{enumitem}

\newlist{induction}{enumerate}{4}%% up to 4 levels for this new list
\setlist[induction]{wide=0pt, leftmargin =3em}
\setlist[induction, 1]{label=\bfseries\boldmath$A\textup{-induction}${,} $a\arabic* $:}
\setlist[induction, 2]{label=\bfseries\boldmath$B\textup{-induction}${, }$b\arabic* $:}

\begin{document}

Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.

\begin{induction}%{A}
  \item Part~$a1$ of the induction proof.
  \item Part~$a2$ of the induction proof. This one needs a further induction argument over~$B$.
  \begin{induction}%{B}
    \item Part~$b1$ of the induction proof. This part of the induction proof can be very very long.
  \end{induction}
\end{induction}

\end{document} 

在此处输入图片描述

相关内容