[Tex/LaTex] Arguments in a tcolorbox

fancyboxtcolorbox

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

Best Answer

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.

Related Question