自动化环境内逐项列出的选项设置

自动化环境内逐项列出的选项设置

我在问自己是否有办法自动设置文档环境中的选项?例如,我itemize在一个tcolorbox环境中有一个块,在其中我将设置label\textcolor{myColor}{$\bullet$},而它们在块之外只是黑色。是否可以自动执行此设置?

这里我的例子使用了 aitemize里面的 atcolorbox但我想知道在给定的文档环境中工作时是否可以自动化选项。

我正在使用pdfLaTex编译器,这是我的最小代码:

\documentclass[letterpaper]{article}
\usepackage[most]{tcolorbox}
\usepackage{enumitem}
\usepackage{xcolor}

\definecolor{myColor}{rgb}{0.68, 0.05, 0.0}

\newtcolorbox[auto counter]{exmp}[3][]{
    breakable,
    enhanced,
    borderline west={2pt}{0pt}{myColor},
    sharp corners,
    boxrule=0pt,
    fonttitle={\large\bfseries},
    coltitle={black},
    label=#2,
    title= {\textcolor{myColor}{Example~\thetcbcounter:} #3\\},
    attach title to upper,
    right=0pt,
    top=0pt,
    bottom=0pt,
    frame hidden,
    colback=white!80!gray, 
    #1
}

\begin{document}
A simple itemize outside my environment:
\begin{itemize}
    \item A
    \item B
    \item C
\end{itemize}

\begin{exmp}{ex:myEx}{My example}
A itemize that I custom in an environment: 
\begin{itemize}[label=\textcolor{myColor}{$\bullet$}] % Option I want to automate
    \item A
    \item B
    \item C
\end{itemize}
\end{exmp}
\end{document}

提前感谢对后续方法的开发

答案1

将 a 添加\setlistcode键值中:

在此处输入图片描述

\documentclass{article}

\usepackage[most]{tcolorbox}
\usepackage{enumitem}
\usepackage{xcolor}

\definecolor{myColor}{rgb}{0.68, 0.05, 0.0}

\newtcolorbox[auto counter]{exmp}[3][]{
    breakable,
    enhanced,
    borderline west={2pt}{0pt}{myColor},
    sharp corners,
    boxrule=0pt,
    fonttitle={\large\bfseries},
    coltitle={black},
    label=#2,
    title= {\textcolor{myColor}{Example~\thetcbcounter:} #3\\},
    attach title to upper,
    right=0pt,
    top=0pt,
    bottom=0pt,
    frame hidden,
    colback=white!80!gray,
    code={\setlist[itemize]{label=\textcolor{myColor}{$\bullet$}}},
    #1
}

\begin{document}
A simple itemize outside my environment:
\begin{itemize}
    \item A
    \item B
    \item C
\end{itemize}

\begin{exmp}{ex:myEx}{My example}
  A itemize that I custom in an environment: 
  \begin{itemize}
    \item A
    \item B
    \item C
  \end{itemize}
\end{exmp}

A simple itemize outside my environment:
\begin{itemize}
    \item A
    \item B
    \item C
\end{itemize}

\end{document}

相关内容