You are on page 1of 3

Section 21.2 on page 404 and Section 21.

3 on page 407 for more elaborate methods to


! See
create new environments and commands.
\newtcolorbox[hinit optionsi]{hnamei}[hnumberi][hdefaulti]{hoptionsi}
Creates a new environment hnamei based on tcolorbox P. 12 . Basically, \newtcolorbox
operates like \newenvironment. This means, the new environment hnamei optionally takes
hnumberi arguments, where hdefaulti is the default value for the optional first argument.
The hoptionsi are given to the underlying tcolorbox. Note that /tcb/savedelimiter P. 26
is set to the given hnamei automatically. The hinit optionsi allow setting up automatic
numbering, see Section 5 from page 100.
\newtcolorbox{mybox}{colback=red!5!white,
colframe=red!75!black}
This is my own box.

\begin{mybox}
This is my own box.
\end{mybox}

\newtcolorbox{mybox}[1]{colback=red!5!white,
colframe=red!75!black,fonttitle=\bfseries,
title=#1}
\begin{mybox}{Hello there}
This is my own box with a mandatory title.
\end{mybox}

\newtcolorbox{mybox}[2][]{colback=red!5!white,
colframe=red!75!black,fonttitle=\bfseries,
colbacktitle=red!85!black,enhanced,
attach boxed title to top center={yshift=-2mm},
title=#2,#1}
\begin{mybox}[colback=yellow]{Hello there}
This is my own box with a mandatory title
and options.
\end{mybox}

Hello there
This is my own box with a
mandatory title.

Hello there
This is my own box with a
mandatory title and options.

Definition in the preamble:


\newtcolorbox[auto counter,number within=section]{pabox}[2][]{%
colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,
title=Examp.~\thetcbcounter: #2,#1}

\begin{pabox}[colback=yellow]{Hello there}
This is my own box with a mandatory
numbered title and options.
\end{pabox}

Examp. 3.1: Hello there


This is my own box with
a mandatory numbered title
and options.

\renewtcolorbox[hinit optionsi]{hnamei}[hnumberi][hdefaulti]{hoptionsi}
Operates like \newtcolorbox, but based on \renewenvironment
\newenvironment. An existing environment is redefined.

15

instead

of

\newtcbox[hinit optionsi]{\hnamei}[hnumberi][hdefaulti]{hoptionsi}
Creates a new macro \hnamei based on \tcbox P. 14 . Basically, \newtcbox operates like
\newcommand. The new macro \hnamei optionally takes hnumberi+1 arguments, where
hdefaulti is the default value for the optional first argument. The hoptionsi are given to the
underlying tcbox. The hinit optionsi allow setting up automatic numbering, see Section 5
from page 100.
\newtcbox{\mybox}{colback=red!5!white,
colframe=red!75!black}

This is my own box.

\mybox{This is my own box.}

\newtcbox{\mybox}[1]{colback=red!5!white,
colframe=red!75!black,fonttitle=\bfseries,
title=#1}

Hello there
This is my own box.

\mybox{Hello there}{This is my own box.}

\newtcbox{\mybox}[2][]{colback=red!5!white,
colframe=red!75!black,fonttitle=\bfseries,
title=#2,#1}

Hello there
This is my own box.

\mybox[colback=yellow]{Hello there}%
{This is my own box.}

Definition in the preamble:


% counter from previous example
\newtcbox[use counter from=pabox]{\pbbox}[2][]{%
colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,
title=(\thetcbcounter) #2,#1}

(3.2) Hello there

\pbbox[colback=yellow]{Hello there}%
{This is my own box.}

This is my own box.

\newtcbox{\mybox}[1][red]{on line,
arc=0pt,outer arc=0pt,colback=#1!10!white,colframe=#1!50!black,
boxsep=0pt,left=1pt,right=1pt,top=2pt,bottom=2pt,
boxrule=0pt,bottomrule=1pt,toprule=1pt}
\newtcbox{\xmybox}[1][red]{on line,
arc=7pt,colback=#1!10!white,colframe=#1!50!black,
before upper={\rule[-3pt]{0pt}{10pt}},boxrule=1pt,
boxsep=0pt,left=6pt,right=6pt,top=2pt,bottom=2pt}
The \mybox[green]{quick} brown \mybox{fox} \mybox[blue]{jumps} over the
\mybox[green]{lazy} \mybox{dog}.\par
The \xmybox[green]{quick} brown \xmybox{fox} \xmybox[blue]{jumps} over the
\xmybox[green]{lazy} \xmybox{dog}.
The quick brown fox jumps over the lazy dog .
The

quick

brown

fox

jumps

over the

lazy

dog .

\renewtcbox[hinit optionsi]{\hnamei}[hnumberi][hdefaulti]{hoptionsi}
Operates like \newtcbox, but based on \renewcommand instead of \newcommand. An existing
macro is redefined.
16

N 2014-10-20

\tcolorboxenvironment{hnamei}{hoptionsi}
An existing environment hnamei is redefined to be boxed inside a tcolorbox with the given
hoptionsi.
% tcbuselibrary{skins}
\newenvironment{myitemize}{%
\begin{itemize}}{\end{itemize}}
\tcolorboxenvironment{myitemize}{blanker,
before skip=6pt,after skip=6pt,
borderline west={3mm}{0pt}{red}}
Some text.
\begin{myitemize}
\item Alpha
\item Beta
\item Gamma
\end{myitemize}
More text.

Some text.
Alpha
Beta

Gamma
More text.

See further examples in Section 16.4 on page 348.

17

You might also like