thmbox 彩条

thmbox 彩条

我想问一下是否有人知道是否可以更改 thmbox 包中的条形颜色。可以更改条形的粗细,但不能更改颜色。

\usepackage{thmbox}
\newtheorem[style=M, thickness=1pt]{theoremExa}{Example}[chapter]
\begin{document}
 \begin{theoremExa}[Example Bla]
   .....
 \end{theoremExa}
\end{document}

答案1

您可以在标题中使用以下重新定义。它提供了一个新键color,您可以在其中指定颜色:

\makeatletter
\def\thmbox@color{black}
\define@key{thmbox}{color}{\def\thmbox@color{#1}}
\def\thmbox@head#1{%
  \par\noindent\vbox{%
    \setbox\thmbox@box@=\hbox{%
      \vrule width 0mm height 0mm depth \thmbox@vskip%
      #1}%
    \copy\thmbox@box@%
    \ifthmbox@underline%
       \color@begingroup\color{\thmbox@color}\hrule width \wd\thmbox@box@ height \thmbox@thickness\color@endgroup%
    \fi}%
  \hrule height 0mm\relax}
\def\thmbox@put#1{
  \vskip\z@%
  \noindent%
  \hbox{%
    {\dimen0=\thmbox@leftmargin%
     \advance\dimen0-\thmbox@hskip%
     \advance\dimen0-\thmbox@thickness%
     \hskip\dimen0}%
    \color@begingroup\color{\thmbox@color}\vrule width \thmbox@thickness\color@endgroup%
    \hskip\thmbox@hskip%
    \box#1%
    \ifx\thmbox@style L%
      \hskip\thmbox@hskip%
      \color@begingroup\color{\thmbox@color}\vrule width \thmbox@thickness\color@endgroup%
    \fi}%
  \par\nobreak}
\def\thmbox@tail{%
  \hrule height 0mm%
  \ifx\thmbox@style M%
    \thmbox@dim=1cm%
  \else\ifx\thmbox@style L%
    \thmbox@dim=\hsize%
    \advance\thmbox@dim-\thmbox@leftmargin%
    \advance\thmbox@dim-\thmbox@rightmargin%
    \advance\thmbox@dim2\thmbox@hskip%
    \advance\thmbox@dim2\thmbox@thickness%
  \fi\fi%
  \noindent%
  {\dimen0=\thmbox@leftmargin%
   \advance\dimen0-\thmbox@hskip%
   \advance\dimen0-\thmbox@thickness%
   \hskip\dimen0}%
  \color@begingroup\color{\thmbox@color}\vrule width \thmbox@dim height \thmbox@thickness\color@endgroup%
  \par}
\makeatother

以下是完整的 MWE:

在此处输入图片描述

\listfiles
\documentclass{report}
\usepackage{thmbox}
\usepackage{xcolor}

\makeatletter
\def\thmbox@color{black}
\define@key{thmbox}{color}{\def\thmbox@color{#1}}
\def\thmbox@head#1{%
  \par\noindent\vbox{%
    \setbox\thmbox@box@=\hbox{%
      \vrule width 0mm height 0mm depth \thmbox@vskip%
      #1}%
    \copy\thmbox@box@%
    \ifthmbox@underline%
       \color@begingroup\color{\thmbox@color}\hrule width \wd\thmbox@box@ height \thmbox@thickness\color@endgroup%
    \fi}%
  \hrule height 0mm\relax}
\def\thmbox@put#1{
  \vskip\z@%
  \noindent%
  \hbox{%
    {\dimen0=\thmbox@leftmargin%
     \advance\dimen0-\thmbox@hskip%
     \advance\dimen0-\thmbox@thickness%
     \hskip\dimen0}%
    \color@begingroup\color{\thmbox@color}\vrule width \thmbox@thickness\color@endgroup%
    \hskip\thmbox@hskip%
    \box#1%
    \ifx\thmbox@style L%
      \hskip\thmbox@hskip%
      \color@begingroup\color{\thmbox@color}\vrule width \thmbox@thickness\color@endgroup%
    \fi}%
  \par\nobreak}
\def\thmbox@tail{%
  \hrule height 0mm%
  \ifx\thmbox@style M%
    \thmbox@dim=1cm%
  \else\ifx\thmbox@style L%
    \thmbox@dim=\hsize%
    \advance\thmbox@dim-\thmbox@leftmargin%
    \advance\thmbox@dim-\thmbox@rightmargin%
    \advance\thmbox@dim2\thmbox@hskip%
    \advance\thmbox@dim2\thmbox@thickness%
  \fi\fi%
  \noindent%
  {\dimen0=\thmbox@leftmargin%
   \advance\dimen0-\thmbox@hskip%
   \advance\dimen0-\thmbox@thickness%
   \hskip\dimen0}%
  \color@begingroup\color{\thmbox@color}\vrule width \thmbox@dim height \thmbox@thickness\color@endgroup%
  \par}
\makeatother
\newtheorem[style=M, thickness=1pt,color=red]{theoremExa}{Example}[chapter]

\begin{document}
 \begin{theoremExa}[Example Bla]
   ......
 \end{theoremExa}
\end{document}

相关内容