Counters assigned using the initialization options are administrated automatically. Especially, they are increased for each new box. Independent from the real counter name, the counter value can be referenced by \thetcbcounter, e. g. inside the title of the box. The real counter name is stored inside\tcbcounter.
/tcb/new/auto counter (no value, initially unset)
Creates a new counter automatically. With /tcb/new/number formatÕ P. 77 and /tcb/new/number withinÕ P. 77, the appearance and behavior of the counter can be changed. The counter value is referenced by\thetcbcounter.
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}[label={myautocounter}]{Title with number}
This box is automatically numbered with \ref{myautocounter} on page
\pageref{myautocounter}. Inside the box, the \thetcbcounter\ can also be referenced by |\thetcbcounter|.
The real counter name is \texttt{\tcbcounter}.
\end{pabox}
Examp. 4.1: Title with number
This box is automatically numbered with4.1on page75. Inside the box, the 4.1 can also be referenced by \thetcbcounter. The real counter name is tcb@cnt@pabox.
/tcb/new/use counter from=htcolorbox i (no default, initially unset) Here, a counter from another htcolorboxi is reused. Note that the setting for /tcb/new/number formatÕ P. 77and/tcb/new/number withinÕ P. 77are inherited and can-not be changed. The counter value is referenced by \thetcbcounter.
\newtcolorbox[use counter from=pabox]{mybox}[2][]{%
colback=blue!5!white,colframe=blue!75!black,fonttitle=\bfseries, title=Some Box \thetcbcounter: #2,#1}
\begin{mybox}[label={myusecounterfrom}]{Title with continued number}
This box is automatically numbered with \ref{myusecounterfrom} on page
\pageref{myusecounterfrom}. Inside the box, the \thetcbcounter\ can also be referenced by |\thetcbcounter|.
The real counter name is \texttt{\tcbcounter}.
\end{mybox}
Some Box 4.2: Title with continued number
This box is automatically numbered with4.2on page76. Inside the box, the 4.2 can also be referenced by \thetcbcounter. The real counter name is tcb@cnt@pabox.
/tcb/new/use counter=hcounter i (no default, initially unset) Here, an ordinary existing LATEX counter is used for numbering. With /tcb/new/number formatÕ P. 77 and /tcb/new/number withinÕ P. 77, the appearance and behavior of the counter can be changed. The counter value is referenced by\thetcbcounter.
% \newcounter{myexample}% preamble
\newtcolorbox[use counter=myexample,number format=\Alph]{mybox}[2][]{%
colback=green!5!white,colframe=green!55!black,fonttitle=\bfseries, title=Some Box \thetcbcounter: #2,#1}
\begin{mybox}[label={myusecounter}]{Title with \LaTeX\ number}
This box is automatically numbered with \ref{myusecounter} on page
\pageref{myusecounter}. Inside the box, the \thetcbcounter\ can also be referenced by |\thetcbcounter|.
The real counter name is \texttt{\tcbcounter}.
\end{mybox}
Some Box A: Title with LATEX number
This box is automatically numbered withA on page76. Inside the box, the A can also be referenced by \thetcbcounter. The real counter name is myexample.
/tcb/new/no counter (no value, initially set)
The created boxes are not numbered. This is the default. The option may be used to overrule a previous option.
/tcb/new/number within=hcounter i (no default, initially unset) The automatic counter is set to zero, if hcounter i is increased. Additionally, during output, the value of hcounter i is prepended to the value of the automatic counter.
To prepend the automatic counter with the chapter number and to reset it with every new chapter, use:
number within=chapter
See/tcb/new/use counterÕ P. 76 for a complete example.
/tcb/new/number format=hformat macroi (no default, initially \arabic) Declares the format of the automatic counter. The hformat macroi can be any valid LATEX number formatting macro like \arabic, \roman, etc.
To display the counter value in large roman numbers, use:
number format=\Roman
See/tcb/new/auto counterÕ P. 75 for a complete example.
/tcb/new/number freestyle=hcodei (no default, initially unset) Allows advanced control over the complete number format. This option overrules the format given by /tcb/new/number withinand /tcb/new/number format. Nevertheless, you can combine it with /tcb/new/number withinto get the desired reset property.
The hcodei is some formatting code which should contain \tcbcounter to reference the automated counter. Since this hcodei is expanded, you have to secure each macro with
\noexpand with exception of \tcbcounter.
Definition in the preamble:
\newtcolorbox[auto counter,number within=section,
number freestyle={(Q/\noexpand\thesection/\noexpand\Alph{\tcbcounter})}, ]{phbox}[2][]{%
colback=yellow!15!white,colframe=blue!75!black,fonttitle=\bfseries, title=Question~\thetcbcounter: #2,#1}
\begin{phbox}[label={myfreestyle}]{Title with freestyle number}
This box is automatically numbered with \ref{myfreestyle} on page
\pageref{myfreestyle}. Inside the box, the \thetcbcounter\ can also be referenced by |\thetcbcounter|.
The real counter name is \texttt{\tcbcounter}.
\end{phbox}
Question (Q/4/A): Title with freestyle number
This box is automatically numbered with(Q/4/A)on page77. Inside the box, the (Q/4/A) can also be referenced by \thetcbcounter. The real counter name is tcb@cnt@phbox.
The following options /tcb/new/crefname and
!
/tcb/new/Crefname need to be set inside the preamble./tcb/new/crefname={hsingular i}{hplurali} (no default, initially unset) This option key can be used only in conjunction with the cleveref package [5] which has to be loaded separately. It creates a cross-reference type for the new tcolorbox’es, where the lowercase hsingular i and hplurali forms of the cross-reference are given. See/tcb/label typeÕ P. 72 and [5] for more information.
/tcb/new/Crefname={hsingular i}{hplurali} (no default, initially unset) This option key can be used only in conjunction with the cleveref package [5] which has to be loaded separately. It creates a cross-reference type for the new tcolorbox’es, where the uppercase hsingular i and hplurali forms of the cross-reference are given. See /tcb/label typeÕ P. 72 and [5] for more information.
Definition in the preamble:
% \usepackage{cleveref}
\newtcolorbox[auto counter,number within=section,
Crefname={Bluebox}{Blueboxes},crefname={bluebox}{blueboxes}]%
{mybluebox}[2][]{colback=blue!5!white,colframe=blue!75!black,fonttitle=\bfseries, title=Bluebox \thetcbcounter: #2,#1}
% \usepackage{cleveref}
% \usepackage{varioref}
\begin{mybluebox}[label={myreference}]{My title}
This is an example.
\end{mybluebox}
\Cref{myreference}, \cref{myreference}.\\
\Cpageref{myreference}, \cpageref{myreference}.\\
\nameCref{myreference}, \namecref{myreference}.\\
\labelcref{myreference}, \labelcpageref{myreference}.\\
With \texttt{varioref}:\\
\Vref{myreference}, \vref{myreference}.\\
\Vref*{myreference}, \vref*{myreference}.
Bluebox 4.1: My title
This is an example.
Bluebox4.1, bluebox4.1.
Page78, page78.
Bluebox, bluebox.
4.1,78.
With varioref:
Bluebox4.1, bluebox4.1.
Bluebox 4.1, bluebox 4.1.