8

I use the following fancy tcolorbox definition:

\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}}

Using \tcblower I can split the box, and make two fancy gradient stripe, but I would like to use more than two. How to do an environment with the same appearance, where I can use simple \tcblower or something like that to add another stripe?

1
  • Have you tried nested boxes from tcolorbox package? Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – user31729
    Commented Sep 6, 2014 at 8:07

3 Answers 3

15

maybe faking some broken boxes:

\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}

enter image description here

this is documented in section 11.7 of the manual.

3
  • Yes, this is hacker solution :) Using single environment would be nicer! Commented Sep 6, 2014 at 15:39
  • @user3058699 As far as I know tcolorbox does not support more than one lower part, so you are either faking a single box (like I did) or using the overlay to draw the gradients over the box content (as @Harish did). If it is for the sake of a cleaner code, you could design a single command like \myfakesinglebox{}{}{}{} that embed the various environments (however you would still have three or more boxes in reality).
    – d-cmst
    Commented Sep 6, 2014 at 17:07
  • some kind of list or table solution is not possible inside a tcolorbox? Commented Sep 7, 2014 at 10:31
5

With tcolorbox 3.30 (2014/11/17), there are new possiblities to answer this question using the raster library:

\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}

enter image description here

3

The following is not breakable and the number of stripes can be customised with the overlay code:

\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}

enter image description here

2
  • If this needs to be breakable across pages, let me know.
    – user11232
    Commented Sep 6, 2014 at 10:09
  • It's important, that I would like to decide in the text where to start a new stripe. Typically at the end of a paragraph. Commented Sep 6, 2014 at 15:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .