I would like to define a tcolorbox
with an auto counter
. The value of the counter will decide some part of the final style of the box. As an example, imagin that the background of the box alternates between blue and red for even or odd boxes.
There are several questions and answers about conditional styles for TiKZ
nodes but I don't understand them and don't know how to apply to tcolorbox
.
I know I can do it defining two different styles and manually applaying them, like in following code. But I prefer that LaTeX does the work for me.
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\newtcolorbox[auto counter]{oddbox}{
colback=red!20,
title=\thetcbcounter
}
\newtcolorbox[use counter from=oddbox]{evenbox}{
colback=blue!20,
title=\thetcbcounter
}
\begin{document}
\begin{oddbox}
\lipsum[2]
\end{oddbox}
\begin{evenbox}
\lipsum[2]
\end{evenbox}
\begin{oddbox}
\lipsum[2]
\end{oddbox}
\end{document}