tcolorbox:改变身体某一部分的背景

tcolorbox:改变身体某一部分的背景

我有一个 tcolorbox,其中有多个“部分”,中间用空格隔开\tcbline,我想更改其中两个(例如第二个和第四个)的背景。有人有好主意怎么做吗?

\documentclass{article}
\usepackage[many]{tcolorbox}%
\usepackage{lipsum}

\begin{document}
\begin{tcolorbox}
\lipsum[1]
\tcbline
\lipsum[2]
\tcbline
\lipsum[1]
\tcbline
\lipsum[1]
\end{tcolorbox}
\end{document}

答案1

我会通过在外部内使用tcbraster或来做这样的事情。以下代码示例创建蓝色和红色的彩色条纹,但每个条纹都可以赋予单独的颜色:tcbitemizetcolorbox

\documentclass{article}
\usepackage[many]{tcolorbox}%
\usepackage{lipsum,geometry}

\begin{document}

  \begin{tcolorbox}[enhanced,
      boxsep=0pt,top=0pt,bottom=0pt,leftupper=0pt,rightupper=0pt,
      toptitle=1mm,bottomtitle=1mm,lefttitle=5mm,righttitle=5mm,
      colbacktitle=yellow!20,coltitle=black,title=Box with interior raster,
      colback=blue!10,clip upper]
    \begin{tcbitemize}[raster columns=1,raster equal skip=0pt,
        sharp corners,boxrule=0pt,
        raster odd row/.style={empty},
        raster even row/.style={tile,colback=red!10}]
      \tcbitem
      \lipsum[1]
      \tcbitem
      \lipsum[2]
      \tcbitem
      \lipsum[1]
      \tcbitem
      \lipsum[1]
    \end{tcbitemize}
  \end{tcolorbox}


  \clearpage
  The same with a new environment:

  \newenvironment{mybox}{%
    \begin{tcolorbox}[enhanced,
      boxsep=0pt,top=0pt,bottom=0pt,leftupper=0pt,rightupper=0pt,
      toptitle=1mm,bottomtitle=1mm,lefttitle=5mm,righttitle=5mm,
      colbacktitle=yellow!20,coltitle=black,title=Box with interior raster,
      colback=blue!10,clip upper]%
    \begin{tcbitemize}[raster columns=1,raster equal skip=0pt,
        sharp corners,boxrule=0pt,
        raster odd row/.style={empty},
        raster even row/.style={tile,colback=red!10}]%
  }{\end{tcbitemize}\end{tcolorbox}}

  \begin{mybox}
    \tcbitem
    \lipsum[1]
    \tcbitem
    \lipsum[2]
    \tcbitem
    \lipsum[1]
    \tcbitem
    \lipsum[1]
  \end{mybox}

\end{document}

在此处输入图片描述

相关内容