参考:

参考:

MyList是一个始终恢复的enumitem列表:

\newlist{MyList}{enumerate}{2}
\setlist[MyList,1]{label={\arabic*.}, resume}% ALWAYS resumed

但似乎打破如果第一的使用MyList来自另一个环境(橙色文本)。在 MWE 中,此环境向列表添加颜色,然后调用\begin{MyList}

\newenvironment{MyColoredList}[2][]{%
    \color{#2}%
    \begin{MyList}[#1]
}{%
    \end{MyList}%
}%

但使用相同的环境直接使用MyList似乎很好(蓝色文本):

在此处输入图片描述

笔记:

  • 第二级没有恢复,因此没有问题。因此我删除了测试该部分的代码。
  • 我的问题不是如何为列表着色,而是如何resume在环境中调用列表时对其进行编号。

参考:

代码:

\documentclass{article}
\usepackage{enumitem}
\usepackage{xcolor}

\newlist{MyList}{enumerate}{2}
\setlist[MyList,1]{label={\arabic*.}, resume}% ALWAYS resumed
\setlist[MyList,2]{label={\alph*)}}%           NOT resumed

\newenvironment{MyColoredList}[2][]{%
    \color{#2}%
    \begin{MyList}[#1]
}{%
    \end{MyList}%
}%


\begin{document}
    \begin{MyColoredList}{red}
        \item First Item
    \end{MyColoredList}
    Some text
    \begin{MyColoredList}{orange}% <--- This should be number 2
        \item First Item
    \end{MyColoredList}
    Some text
    \begin{MyList}% <--- This should be number 3
        \item Second Item
    \end{MyList}
    Some text
    \begin{MyList}
        \item Third Item
    \end{MyList}
    Some text
    \begin{MyColoredList}{blue}
        \item Fourth Item (this works!!)
    \end{MyColoredList}
\end{document}

答案1

你可以用困难的方式来做:

\documentclass{article}
\usepackage{enumitem}
\usepackage{xcolor}

\newlist{MyList}{enumerate}{2}
\setlist[MyList,1]{
  label=\arabic*.,
  before=\setcounter{MyListi}{\value{MyList}},
  after=\setcounter{MyList}{\value{MyListi}},
}% ALWAYS resumed
\setlist[MyList,2]{label=\alph*)}%           NOT resumed

\newcounter{MyList}
\newenvironment{MyColoredList}[2][]{%
    \color{#2}\begin{MyList}[#1]
}{%
    \end{MyList}%
}%


\begin{document}
    \begin{MyColoredList}{red}
        \item First Item
    \end{MyColoredList}
    Some text
    \begin{MyColoredList}{orange}% <--- This should be number 2
        \item First Item
    \end{MyColoredList}
    Some text
    \begin{MyList}% <--- This should be number 3
        \item Second Item
    \end{MyList}
    Some text
    \begin{MyList}
        \item Third Item
    \end{MyList}
    Some text
    \begin{MyColoredList}{blue}
        \item Fourth Item (this works!!)
    \end{MyColoredList}
\end{document}

在此处输入图片描述

答案2

resume选项始终是本地的,即仅在当前组内。在某个环境中使用列表并尝试稍后在另一个环境中恢复列表将失败,因为信息会丢失。

补救措施是resume*,但它必须在本地指定,并且不能作为\setlist宏的选项给出。

\documentclass{article}
\usepackage{enumitem}
\usepackage{xcolor}



\newlist{MyList}{enumerate}{2}
\setlist[MyList,1]{label={\arabic*.},resume}% ALWAYS resumed
\setlist[MyList,2]{label={\alph*)}}%           NOT resumed

\newenvironment{MyColoredList}[2][]{%
  \color{#2}%
  \MyList[#1]
  }{%
  \endMyList%
}%


\begin{document}
    \begin{MyColoredList}{red}
        \item First Item
    \end{MyColoredList}
    Some text
    \begin{MyColoredList}[resume*]{orange}% <--- This should be number 2
    \item First Item
    \end{MyColoredList}
    Some text
    \begin{MyList}% <--- This should be number 3
        \item Second Item
    \end{MyList}
    Some text
    \begin{MyList}
        \item Third Item
    \end{MyList}
    Some text
    \begin{MyColoredList}{blue}
        \item Fourth Item (this works!!)
          \begin{MyList}[resume*]
            \item Inner Item
            \end{MyList}
    \end{MyColoredList}
    \begin{MyColoredList}{violet}
        \item Fifth Item (this works!!)
          \begin{MyList}[resume*]
            \item Inner Item
            \end{MyList}
    \end{MyColoredList}

\end{document}

更好的方法可以用以下series=密钥来实现:

\documentclass{article}
\usepackage{enumitem}
\usepackage{xcolor}


\newlist{MyList}{enumerate}{2}
\setlist[MyList,1]{label={\arabic*.},resume=foo}% ALWAYS resumed
\setlist[MyList,2]{label={\alph*)}}%           NOT resumed

\newenvironment{MyColoredList}[2][]{%
  \color{#2}%
  \begin{MyList}[#1]
  }{%
  \end{MyList}%
}%

\begin{document}
\begin{MyColoredList}[series=foo]{red}
\item First Item
    \end{MyColoredList}
    Some text
    \begin{MyColoredList}{orange}% <--- This should be number 2
    \item First Item
    \end{MyColoredList}
    Some text
    \begin{MyList}%  <--- This should be number 3
        \item Second Item
    \end{MyList}
    Some text
    \begin{MyList}
        \item Third Item
    \end{MyList}
    Some text
    \begin{MyColoredList}{blue}
        \item Fourth Item (this works!!)
          \begin{MyList}[resume*]
            \item Inner Item
            \end{MyList}
    \end{MyColoredList}
    \begin{MyColoredList}{violet}
        \item Fifth Item (this works!!)
          \begin{MyList}[resume*]
            \item Inner Item
            \end{MyList}
    \end{MyColoredList}

\end{document}

在此处输入图片描述

答案3

你可以尝试一下

\documentclass{article}
\usepackage{enumitem}
\usepackage{xcolor}

\makeatletter
\newlist{MyList}{enumerate}{2}
\setlist[MyList,1]{label={\arabic*.},
        after={\xdef\enit@resume@MyList{\noexpand\c@MyListi=\the\c@MyListi}},resume}% ALWAYS resumed
\setlist[MyList,2]{label={\alph*)}}%           NOT resumed

\makeatother
\newenvironment{MyColoredList}[2][]{%
    \color{#2}%
    \begin{MyList}[#1]
}{%
    \end{MyList}%
}%

\begin{document}

    \begin{MyColoredList}{red}
        \item First Item
    \end{MyColoredList}
    Some text
    \begin{MyColoredList}{orange}% <--- This should be number 2
        \item First Item
    \end{MyColoredList}
    Some text
    \begin{MyList}% <--- This should be number 3
        \item Second Item
    \end{MyList}
    Some text
    \begin{MyList}
        \item Third Item
    \end{MyList}
    Some text
    \begin{MyColoredList}{blue}
        \item Fourth Item (this works!!)
    \end{MyColoredList}
\end{document}

在此处输入图片描述

相关内容