我希望能够使用可选参数(默认为橙色)为文本着色。虽然Something Something
不应该着色。
\documentclass{article}
\usepackage{xcolor}
\NewDocumentEnvironment{Statement}{O{}}
{
Something Something
}
{ \vspace{0.3cm} }
\begin{document}
\begin{Statement}
This text is displayed in color.
\end{Statement}
\end{document}
答案1
答案2
正如大卫卡莱尔所说,环境是一个群体。关闭标记\color{}
后不会影响文本\end{statement}
。
如果您想要橙色的默认颜色,您只需在定义中声明它并应用\color{#1}
所选的颜色(如果没有,它将是橙色)。
看这里 :
\documentclass{article}
\usepackage{xcolor}
\newenvironment{statement}[1][orange]%
{%
\color{#1}% other stuff to apply at the start of the environment
}{%
%%%Stuff here to apply at the end
}
\begin{document}
This is normal text.
\begin{statement}
This text is displayed in color. Default is orange.
\end{statement}
This is normal text.
\begin{statement}[purple]
This text is displayed in purple.
\end{statement}
This is normal text
\end{document}