用章节定义颜色框

用章节定义颜色框

我定义如下:

{\theorembodyfont{\rmfamily}\newtheorem{Bsp}{Beispiel}[chapter]}

在文本中使用

\begin{Bsp}
bla
bla
\end{Bsp}

现在我只想为“示例”包含章节着色。请看图片: 在此处输入图片描述

在此处输入图片描述

答案1

您可以使用TikZ椭圆节点定义新样式;一条评论已要求正文从新行开始:

\documentclass{book}
\usepackage{ntheorem}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,fit,backgrounds}

\makeatletter
\newtheoremstyle{ovalplain}%
  {\item[\rlap{%
    \vbox{%
      \hbox{%
        \hskip\labelsep%
          {\begin{tikzpicture}
            \node[inner sep=0pt,outer sep=0pt]
              (name)
              {{\theorem@headerfont##1\ ##2\theorem@separator}};
            \begin{pgfonlayer}{background}  
            \node[overlay,fill=yellow!50!orange,ellipse,fit=(name)] {};  
            \end{pgfonlayer}
            \node[inner sep=0pt] {\rule[-5ex]{0pt}{0pt}};  
            \end{tikzpicture}%
          }%    
      }%
      \hbox{\strut}%
    }%
    }]
  }%
  {\item[\rlap{%
    \vbox{%
      \hbox{%
        \hskip\labelsep%
          {\begin{tikzpicture}
            \node[inner sep=0pt,outer sep=0pt]
              (name)
              {{\theorem@headerfont##1\ ##2\ (##3)\theorem@separator}};
            \begin{pgfonlayer}{background}  
            \node[overlay,fill=yellow!50!orange,ellipse,fit=(name)] {};  
            \end{pgfonlayer}
            \node[inner sep=0pt] {\rule[-5ex]{0pt}{0pt}};  
            \end{tikzpicture}%
          }%    
      }%
      \hbox{\strut}%
    }%
    }]
  }
\makeatother

\theoremstyle{ovalplain}
\theorembodyfont{\rmfamily}
\newtheorem{Bsp}{Beispiel}[chapter]

\begin{document}

\chapter{A test chapter}
\begin{Bsp}
A test example
\end{Bsp}

\end{document}

在此处输入图片描述

相关内容