6

Following with the answer for this question Create a color box? given by Gonzalo Medina I just made a few arrangements for a list of exercises the code is this

\documentclass{article}
\usepackage[most]{tcolorbox}
\tcbuselibrary{skins}
\usepackage{lipsum}


\newtcolorbox[auto counter,number within=section]{ejemplo}[1][]{
before=\bigskip\centering,
after=\bigskip,
breakable,
enhanced,
arc=15pt,
colframe=blue,
colback=white,
fonttitle=\sffamily\bfseries,
title=Ejem.~\thetcbcounter,
sharp corners,
rounded corners=northeast,
attach boxed title to top left,
boxed title style={
    enhanced,
    colframe=blue,
    colback=cyan,
    arc=5pt,
    bottomrule=0pt,
    rightrule=0pt,
    sharp corners,
    rounded corners=northeast,
},
interior style={},
frame style={
    left color=blue,
    right color=cyan,},
overlay unbroken and first={
    \node[anchor=west,font=\sffamily,color=cyan] 
    at (title.east) {{\small #1}};}}

\begin{document}
\begin{ejemplo}[Title]
  \lipsum[2]
\end{ejemplo}
\end{document}

getting something like this

enter image description here

But I need to add another argument in order to get some boxes with the \tcblower with the sidebyside option in other words write something like this with the code above

\begin{ejemplo}[sidebyside]{Title}
  \lipsum[2]
  \tcblower
  \lipsum[2]
 \end{ejemplo}

I've tried with

\newtcolorbox[auto counter,number within=section]{ejemplo}[2][]{
before=\bigskip\centering,
after=\bigskip,
breakable,
enhanced,
arc=15pt,
colframe=blue,
colback=white,
fonttitle=\sffamily\bfseries,
title=Ejem.~\thetcbcounter,
sharp corners,
rounded corners=northeast,
attach boxed title to top left,
boxed title style={
    enhanced,
    colframe=blue,
    colback=cyan,
    arc=5pt,
    bottomrule=0pt,
    rightrule=0pt,
    sharp corners,
    rounded corners=northeast,
},
interior style={},
frame style={
    left color=blue,
    right color=cyan,},
overlay unbroken and first={
    \node[anchor=west,font=\sffamily,color=cyan] 
    at (title.east) {{\small #2}};},#1}

and with

\newtcolorbox[auto counter,number within=section]{ejemplo}[2][]{
before=\bigskip\centering,
after=\bigskip,
breakable,
enhanced,
arc=15pt,
colframe=blue,
colback=white,
fonttitle=\sffamily\bfseries,
before title=Ejem.~\thetcbcounter,
sharp corners,
rounded corners=northeast,
attach boxed title to top left,
boxed title style={
    enhanced,
    colframe=blue,
    colback=cyan,
    arc=5pt,
    bottomrule=0pt,
    rightrule=0pt,
    sharp corners,
    rounded corners=northeast,
},
interior style={},
frame style={
    left color=blue,
    right color=cyan,},
overlay unbroken and first={
    \node[anchor=west,font=\sffamily,color=cyan] 
    at (title.east) {title #2};},#1}

But both are giving me errors how can I achieve that

5

sidebyside and breakable are not compatible.

Improved version

In this version the xparse package was used (through the xparse library) to define the environment and a starred version of it. The unstarred version admits page breaks and the starred version uses sidebyside; they are used as follows:

\documentclass{article}
\usepackage[a6paper]{geometry}%jus for the example
\usepackage[most]{tcolorbox}
\tcbuselibrary{skins,xparse}
\usepackage{lipsum}

\DeclareTColorBox[auto counter,number within=section]{ejemplo}{sm}{
before=\bigskip\centering,
after=\bigskip,
enhanced,
arc=15pt,
colframe=blue,
colback=white,
fonttitle=\sffamily\bfseries,
title=Ejem.~\thetcbcounter,
sharp corners,
rounded corners=northeast,
attach boxed title to top left,
boxed title style={
    enhanced,
    colframe=blue,
    colback=cyan,
    arc=5pt,
    bottomrule=0pt,
    rightrule=0pt,
    sharp corners,
    rounded corners=northeast,
},
interior style={},
frame style={
    left color=blue,
    right color=cyan,
    fill=none},
overlay unbroken and first={
    \node[anchor=west,font=\sffamily,color=cyan] 
    at (title.east) {{\small #2}};
    },
\IfBooleanTF{#1}{sidebyside}{breakable}
}

\begin{document}

\begin{ejemplo}*{Title}
  Some test text
  \tcblower
  Some test text
\end{ejemplo}

\begin{ejemplo}{Title}
  \lipsum[1-2]
\end{ejemplo}

\end{document}

The result:

enter image description here

Using

\DeclareTColorBox[auto counter,number within=section]{ejemplo}{smO{}}{
before=\bigskip\centering,
after=\bigskip,
enhanced,
arc=15pt,
colframe=blue,
colback=white,
fonttitle=\sffamily\bfseries,
title=Ejem.~\thetcbcounter,
sharp corners,
rounded corners=northeast,
attach boxed title to top left,
boxed title style={
    enhanced,
    colframe=blue,
    colback=cyan,
    arc=5pt,
    bottomrule=0pt,
    rightrule=0pt,
    sharp corners,
    rounded corners=northeast,
},
interior style={},
frame style={
    left color=blue,
    right color=cyan,
    fill=none},
overlay unbroken and first={
    \node[anchor=west,font=\sffamily,color=cyan] 
    at (title.east) {{\small #2}};
    },
\IfBooleanTF{#1}{sidebyside}{breakable},
#3
}

there's now an optional argument after the title to pass eventual keys, as in

\begin{ejemplo}*{Title}[colback=orange!20]
  Some test text
  \tcblower
  Some test text
\end{ejemplo}

\begin{ejemplo}{Title}[colback=green!20!black!40]
  \lipsum[1-2]
\end{ejemplo}

Initial version

\documentclass{article}
\usepackage[most]{tcolorbox}
\tcbuselibrary{skins}
\usepackage{lipsum}


\newtcolorbox[auto counter,number within=section]{ejemplo}[2][]{
before=\bigskip\centering,
after=\bigskip,
enhanced,
arc=15pt,
colframe=blue,
colback=white,
fonttitle=\sffamily\bfseries,
title=Ejem.~\thetcbcounter,
sharp corners,
rounded corners=northeast,
attach boxed title to top left,
boxed title style={
    enhanced,
    colframe=blue,
    colback=cyan,
    arc=5pt,
    bottomrule=0pt,
    rightrule=0pt,
    sharp corners,
    rounded corners=northeast,
},
interior style={},
frame style={
    left color=blue,
    right color=cyan,
    fill=none
},
overlay unbroken and first={
    \node[anchor=west,font=\sffamily,color=cyan] 
    at (title.east) {{\small #2}};
    },
#1    
}

\begin{document}
\begin{ejemplo}{Title}
  \lipsum[2]
\end{ejemplo}

\begin{ejemplo}[sidebyside]{Title}
  \lipsum[2]
  \tcblower
  \lipsum[4]
\end{ejemplo}

\end{document}

enter image description here

I added fill=none to frame style to prevent some undesired borders. Thanks to Thomas F. Sturm for suggesting this in his comment.

  • whoa!! it works perfectly @Gonzalo Medina I need to re-read the tcolorbox manual and experiment and play with it :) – Very23 Jun 30 '15 at 3:18
  • 1
    (+1) These are really very nice looking boxes and colors! I just discovered something I did not know. You may notice the very small dark blue border at the right hand side. This is a remnant of the fill operation which is not replaced by shading with left color and right color (as I assumed until now). If you add fill=none to frame style, this border vanishes. – Thomas F. Sturm Jun 30 '15 at 6:25
  • @ThomasF.Sturm Thanks for noticing this. I've updated my answer adding your suggestion. – Gonzalo Medina Jun 30 '15 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.