如何在 tcolorbox 中制作两条以上的花式渐变条纹?

如何在 tcolorbox 中制作两条以上的花式渐变条纹?

我使用以下奇特的tcolorbox定义:

\newtcolorbox{mybox}{colframe=black!80,colback=black!10,sharpish corners,
skin=bicolor,interior style={left color=black!5,right color=black!35},segmentation style={left color=black!35,right color=black!5}}

使用\tcblower我可以分割框,并制作两个漂亮的渐变条纹,但我想使用两个以上。如何制作具有相同外观的环境,我可以使用简单\tcblower或类似的东西来添加另一个条纹?

答案1

也许伪造一些破损的盒子:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\newtcolorbox{mybox}[1][]{
    enhanced,
    colframe=black!80,
    before=,
    after=\vskip-1pt,
    left=0pt,right=0pt,top=0pt,bottom=0pt,
    sharpish corners,
    #1
}

\begin{document}
\begin{mybox}[skin=enhancedfirst,interior style={left color=black!35,right color=black!5}]
first
\end{mybox}
\begin{mybox}[skin=enhancedmiddle,interior style={left color=black!5,right color=black!5,middle color=black!35}]
second
\end{mybox}
\begin{mybox}[skin=enhancedmiddle,interior style={left color=black!35,right color=black!35,middle color=black!5}]
add as many as you want
\end{mybox}
\begin{mybox}[skin=enhancedlast,interior style={left color=black!5,right color=black!35}]
last
\end{mybox}
\end{document}

在此处输入图片描述

本手册第 11.7 节对此进行了记录。

答案2

有了tcolorbox 3.30 (2014/11/17),就可以使用该raster库来回答这个问题:

\documentclass{article}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{skins,raster}
\tcbuselibrary{breakable}% <- remove, if box should be not breakable

\newtcolorbox{xmybox}[1][]{      
  enhanced,colframe=black!80,size=tight,boxrule=0.5mm,
  lefttitle=3mm,righttitle=3mm,toptitle=1mm,bottomtitle=1mm,
  clip upper,sharpish corners,
  fonttitle=\bfseries,
  breakable,pad at break*=0pt,% <- remove, if box should be not breakable
  #1
}

\newenvironment{mybox}[1][]{%
  \begin{xmybox}[#1]%
  \begin{tcbitemize}[raster columns=1,raster row skip=0pt,
    enhanced,size=minimal,frame hidden,top=4pt,bottom=4pt,left=3mm,right=3mm,
    raster odd row/.style={interior style={left color=black!35,right color=black!5}},
    raster even row/.style={interior style={left color=black!5,right color=black!35}}]%
}{\end{tcbitemize}\end{xmybox}}

\begin{document}

\begin{mybox}[title=Striped Box]
  \tcbitem first
  \tcbitem second
  \tcbitem \lipsum[3]
  \tcbitem another one
  \tcbitem yet another one
  \tcbitem last
\end{mybox}

\end{document}

在此处输入图片描述

答案3

以下内容不可破坏,并且可以使用代码自定义条纹数量overlay

\documentclass{article}
\usepackage[many]{tcolorbox}
\usetikzlibrary{calc}

\newtcolorbox{mybox}[1][]{
    enhanced jigsaw,
    boxrule=0pt,
    left=0pt,right=0pt,top=0pt,bottom=0pt,
    overlay={
          \path[preaction={left color=black!35,right color=black!5}]
               ($(frame.north west)!0.25!(frame.south west)$) rectangle
                     ($(frame.north east)!0!(frame.south east)$);
          \path[preaction={left color=black!5,right color=black!35}]
               ($(frame.north west)!0.5!(frame.south west)$) rectangle
                     ($(frame.north east)!0.25!(frame.south east)$);
          \path[preaction={left color=black!35,right color=black!5}]
               ($(frame.north west)!0.75!(frame.south west)$) rectangle
                     ($(frame.north east)!0.5!(frame.south east)$);
          \path[preaction={left color=black!5,right color=black!35}]
               ($(frame.north west)!1!(frame.south west)$) rectangle
                     ($(frame.north east)!0.75!(frame.south east)$);
          \draw[line width=1pt] (frame.south west) rectangle (frame.north east);
          }
}

\usepackage{lipsum}  %% just for demo
\begin{document}
\begin{mybox}
  \lipsum[1-2]
\end{mybox}
\end{document}

在此处输入图片描述

相关内容