更改计数器数字的颜色

更改计数器数字的颜色

我创建了一个特殊的环境(称为“诗篇”),它将文本分成诗节、格式化它们并枚举它们。我还想让诗节的编号出现在\textcolor{BrickRed}文本的其余部分保持黑色。您将如何更改计数器的代码或环境的代码来实现这一点?以下是我的 MWE:

\documentclass[12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[dvipsnames]{xcolor}
\newcounter{qcounter}

\newenvironment{psalm}{ %   %%%% Begin environment code
    \begin{list}{\arabic{qcounter}}{ %  
\usecounter{qcounter}
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{0.2in}%
\setlength{\listparindent}{-0.1in}%
\setlength{\itemindent}{-0.1in}%
    } 
}{        
    \end{list}
} %%%%% End wrapup environment code

\begin{document}

\begin{psalm}
\item Glory be to the Father, and tó the Són, *\\ and to the Hóly Ghóst;
\item As it was in the beginning, † is now, and éver sháll be, *\\ world wíthout énd. 
 Amen.
\end{psalm}\end{document}

答案1

切换到enumerate环境并设置您的要求。请参阅这个答案这个答案作为参考。并添加leftmargin=*使其与左边距对齐。

\documentclass[12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage[dvipsnames]{xcolor}
%\usepackage[showframe]{geometry}

\newenvironment{psalm}{ %   %%%% Begin environment code
\begin{enumerate}[leftmargin=*, label=\textcolor{BrickRed}{\arabic*}]}
{\end{enumerate}} %%%%% End wrapup environment code

\begin{document}

\begin{psalm}
\item Glory be to the Father, and tó the Són, *\\ and to the Hóly Ghóst;
\item As it was in the beginning, † is now, and éver sháll be, *\\ world wíthout énd. 
 Amen.
\end{psalm}
\end{document}

在此处输入图片描述

答案2

这是一个解决方案,它设置了一个自定义的枚举类环境,该环境使用包的机制enumitem。列表占据了文本块的整个宽度,数字item不会突出到左边距。

在此处输入图片描述

\documentclass[12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[dvipsnames]{xcolor}

\usepackage{enumitem}
\newlist{psalm}{enumerate}{1}
\setlist[psalm]{label=\color{BrickRed}\arabic*,
                ref=\arabic*, % for cross-referencing
                wide=0pt, leftmargin=*,
                %nosep, % optional: no extra vert. space between psalms
                }

\begin{document}

\begin{psalm}
\item Glory be to the Father, and tó the Són, *\\ and to the Hóly Ghóst;
\item As it was in the beginning, † is now, and éver sháll be, *\\ world wíthout énd. Amen.
\end{psalm}
\end{document}

相关内容