循序渐进的环境

循序渐进的环境

我想获得以下输出:

Bla, bla, here are the actions to do.

    Action 1
        Bla, bla, bla...

    Action 2
        Bla, bla, bla...

    Action 3
        Bla, bla, bla...

When the preceding actions have been done, you must do the following things.

    Thing 1
        Bla, bla, bla...

    Thing 2
        Bla, bla, bla...

    Thing 3
        Bla, bla, bla...

LaTeX 代码可能如下所示:

Bla, bla, here are the actions to do.

\begin[Action]{step}
    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...
\end{step}

When the preceding actions have been done, you must do the following things.

\begin[Thing]{step}
    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...
\end{step}

答案1

您可以使用\newenvironment它来逐步创建环境steps

\documentclass{article}

\usepackage{enumitem}

\newenvironment{steps}[1]{\begin{enumerate}[label=#1 \arabic*]}{\end{enumerate}}

\makeatletter% http://tex.stackexchange.com/questions/29517/forcing-new-line-after-item-number-in-enumerate-environment/29518#29518
\def\step{%
   \@ifnextchar[ \@step{\@noitemargtrue\@step[\@itemlabel]}}
\def\@step[#1]{\item[#1]\mbox{}\\\hspace*{\dimexpr-\labelwidth-\labelsep}}
\makeatother

\begin{document}

\begin{steps}{Action}
\step Bla, bla, bla...
\step Bla, bla, bla...
\step Bla, bla, bla...
\end{steps}

\begin{steps}{Thing}
\step Bla, bla, bla...
\step Bla, bla, bla...
\step Bla, bla, bla...
\end{steps}

\end{document}

输出

为了进一步完善此方法,您可以使用 LaTeX3 函数 声明环境\DeclareDocumentEnvironment。它允许您指定可选参数并为其设置默认值。以下声明了一个新环境,steps如果没有给出任何参数,则默认为标签“Steps”:

\documentclass{article}

\usepackage{enumitem}
\usepackage{xparse}

\DeclareDocumentEnvironment{steps}%
{O{Step}}% If no argument is given the label defaults to 'Step'
{\begin{enumerate}[label=#1 \arabic*]}%
{\end{enumerate}}

\makeatletter% http://tex.stackexchange.com/questions/29517/forcing-new-line-after-item-number-in-enumerate-environment/29518#29518
\def\step{%
   \@ifnextchar[ \@step{\@noitemargtrue\@step[\@itemlabel]}}
\def\@step[#1]{\item[#1]\mbox{}\\\hspace*{\dimexpr-\labelwidth-\labelsep}}
\makeatother

\begin{document}

\begin{steps}
\step Bla, bla, bla...
\step Bla, bla, bla...
\step Bla, bla, bla...
\end{steps}

\begin{steps}[Action]
\step Bla, bla, bla...
\step Bla, bla, bla...
\step Bla, bla, bla...
\end{steps}

\begin{steps}[Thing]
\step Bla, bla, bla...
\step Bla, bla, bla...
\step Bla, bla, bla...
\end{steps}

\end{document}

输出

答案2

使用包裹enumitem为每个创建标签行动订单项:

\begin{enumerate}[label=Action \arabic*,align=left, leftmargin=2.0cm]

由于您想要在列表开始后添加一个新行,因此我使用了以下解决方案在枚举环境中,强制在项目编号后换行界定\step

\makeatletter
\def\step{%
   \@ifnextchar[ \@myitem{\@noitemargtrue\@myitem[\@itemlabel]}}
\def\@myitem[#1]{\item[#1]\mbox{}\\}
\makeatother

使用这些可获得所需的结果:

在此处输入图片描述

您还可以为每个部分使用自定义环境:

\documentclass{article}
\usepackage{enumitem}

% Since you want a blank line after the begin of a list
% https://tex.stackexchange.com/questions/29517/forcing-new-line-after-item-number-in-enumerate-environment
\makeatletter
\def\step{%
   \@ifnextchar[ \@myitem{\@noitemargtrue\@myitem[\@itemlabel]}}
\def\@myitem[#1]{\item[#1]\mbox{}\\}
\makeatother


% Custom environments
\newenvironment{Action}{%
    \begin{enumerate}[label=Action \arabic*,align=left, leftmargin=2.0cm]%
}{
    \end{enumerate}%
}

\newenvironment{Thing}{%
    \begin{enumerate}[label=Thing \arabic*,align=left, leftmargin=2.0cm]%
}{
    \end{enumerate}%
}




\begin{document}
\noindent
Bla, bla, here are the actions to do.


\begin{Action}
    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...
\end{Action}

\noindent
When the preceding actions have been done, you must do the following things.

\begin{Thing}
    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...

    \step
    Bla, bla, bla...
\end{Thing}
\end{document}

答案3

\usepackage{enumerate}

\begin{enumerate}[{Action}~1:]
\item Blah
\item Blah blah
\end{enumerate}
\begin{enumerate}[{Step}~1:]
\item Blah
\item Blah blah
\end{enumerate}

相关内容