如何用这 3 种不同的方法制作彩色盒子

如何用这 3 种不同的方法制作彩色盒子

我想用这 3 种不同的方式将文本放入颜色框中。参见下面的图片

1.图1:- 在此处输入图片描述

2.图2:- 在此处输入图片描述

3.图3:- 在此处输入图片描述

请告诉我。

答案1

不可否认,定义框做得有点粗糙,但是你可以看看:

\documentclass[]{article}

\usepackage{tcolorbox}
\definecolor{mytheorembg}{HTML}{F2F2F9}
\definecolor{mytheoremfr}{HTML}{00007B}
\definecolor{myexamplebg}{HTML}{F2FBF8}
\definecolor{myexamplefr}{HTML}{88D6D1}
\definecolor{myexampleti}{HTML}{2A7F7F}
\definecolor{mydefinitbg}{HTML}{E5E5FF}
\definecolor{mydefinitfr}{HTML}{3F3FA3}

\tcbuselibrary{theorems,skins,hooks}
\newtcbtheorem[number within=section]{Theorem}{Theorem}
  {%
     enhanced
    ,colback = mytheorembg
    ,frame hidden
    ,boxrule = 0sp
    ,borderline west = {2pt}{0pt}{mytheoremfr}
    ,sharp corners
    ,detach title
    ,before upper = \tcbtitle\par\smallskip
    ,coltitle = mytheoremfr
    ,fonttitle = \bfseries\sffamily
    ,description font = \mdseries
    ,terminator sign dash
    ,separator sign none
  }
  {th}
\newtcbtheorem[number within=section]{Example}{Example}
  {%
     colback = myexamplebg
    ,colframe = myexamplefr
    ,coltitle = myexampleti
    ,boxrule = 1pt
    ,sharp corners
    ,detach title
    ,before upper=\tcbtitle\par\smallskip
    ,fonttitle = \bfseries
    ,description font = \mdseries
    ,separator sign none
    ,description delimiters parenthesis
  }
  {ex}
\newtcolorbox{Definition}[1]
  {
     enhanced
    ,colback = mydefinitbg
    ,colframe = mydefinitfr
    ,coltitle = mydefinitfr
    ,colbacktitle = mydefinitbg
    ,fonttitle = \bfseries
    ,title = {#1}
    ,attach boxed title to top right = {yshift = -5pt, xshift = -7mm}
    ,boxed title style = { boxrule = .25mm }
    ,arc = 5mm
    ,interior code app =
      {
        \node
          [
             anchor=south west
            ,line width = 0.5mm
            ,rounded corners
            ,inner sep = 5pt
            ,draw = mydefinitfr
            ,fill = mydefinitbg
            ,yshift = -5pt%3.5pt
            ,xshift = 7mm
            ,text = mydefinitfr
            ,font = \bfseries
          ] at (frame.north west)
          {\ Definition\ \null};
      }
  }

\begin{document}
\section{Your boxes}
An example theorem is shown in theorem~\ref{th:pnt}, and there is
example~\ref{ex:bertrand}.
\begin{Theorem}{Prime Number Theorem (PNT)}{pnt}
  \begin{equation*}
    \pi(x)\sim\frac{x}{\log x}
  \end{equation*}
\end{Theorem}

\begin{Example}{Generalisation of Bertrand's Postulate}{bertrand}
  Let $\varepsilon>0$. Prove that there exist a prime between $n$ and
  $(1+\varepsilon)n$ for all large $n$, in particular there always exist a
  prime between $n$ and $2n$ for $n>1$.
\end{Example}

\begin{Definition}{Ordinary}
  An ordinary differential equation, often abbreviated as an ODE, is a
  differential equation that is in the form of:
  \begin{equation*}
    F(x,y,y',y''\cdots)=0
  \end{equation*}
\end{Definition}
\end{document}

在此处输入图片描述

相关内容