传递颜色作为参数

传递颜色作为参数

我想在表格中包含一个环境参数的颜色

{RGB}{249,104,21}
{rgb}{0.98,41.0,0.08}
{rgb/cmyk}{0.98,41.0,0.08/0.0,0.58,92.0,0.02}

以下文件的情况不太顺利。

\documentclass[a4paper,12pt]{article}

\usepackage{xcolor}

\ExplSyntaxOn

\NewDocumentEnvironment{wvPz}{O{orange}mmo}
     {%
       \medskip%
       \IfNoValueTF {#4}
           {%
              \noindent #2 \ #3 \hspace{0.5cm}%
           }%
         {%
            \noindent #2 \ #3 \ (#4)%
            \par\smallskip
         }%
       \color{#1}%
    }%
  {%
     \par
     \medskip%
  }

\ExplSyntaxOff

\begin{document}

\begin{wvPz}[{RGB}{249,104,21}]{aa}{bb}[cc]
  C is a field. R is a subfield of C, and the degree of C as an
  extension field of R is 2. Furthec, C is not an ordered field.
\end{wvPz}

\end{document}

答案1

模型参数\color是可选的,因此[]

在此处输入图片描述

\documentclass[a4paper,12pt]{article}

\usepackage{xcolor}

\ExplSyntaxOn

\NewDocumentEnvironment{wvPz}{O{orange}ommo}
     {
       \medskip
       \noindent #3 \ #4
       \IfNoValueTF {#5}
           {
             \hspace{0.5cm}
           }
         {
            \ (#5)
            \par\smallskip
         }
       \IfNoValueTF{#2}
          {\color{#1}}
          {\color[#1]{#2}}
    }
  {
     \par
     \medskip
  }

\ExplSyntaxOff

\begin{document}

\begin{wvPz}{aa}{bb}[cc]
  Default
\end{wvPz}

\begin{wvPz}[RGB][249,104,21]{aa}{bb}[cc]
  RGB 249,104,21
\end{wvPz}


\begin{wvPz}[RGB][104,249,21]{aa}{bb}[cc]
  RGB 104,249,21
\end{wvPz}


\begin{wvPz}[blue]{aa}{bb}[cc]
  Blue
\end{wvPz}

\end{document}

相关内容