Vertical alignment of "nobeforeafter" tcolorbox
Two options; the first one uses a manual adjustment made using the baseline
key for the tcolorbox
es, and the second one uses the option valign=c
for an \adjustbox
from the adjustbox
package; the setting is done automatically using before
and after
:
\newtcbox{\LittleBox}[1][]{
enhanced,
before=\adjustbox{valign=c}\bgroup,
after=\egroup,#1
}
The complete code with both possibilities:
\documentclass[]{article}
\usepackage[skins]{tcolorbox}
\usepackage{adjustbox}
\newtcolorbox{mybox}[1][]{
enhanced,
sidebyside,
sidebyside align= center,
colbacktitle=white,
coltitle=black,
colback=white,
fonttitle=\large\bfseries,
#1
}
\newtcbox{\LittleBox}[1][]{
enhanced,
before=\adjustbox{valign=c}\bgroup,
after=\egroup,#1
}
\newtcbox{\LittleBoxA}[1][]{
enhanced,
nobeforeafter,#1
}
\begin{document}
\begin{mybox}[title= Little boxes centered vertically]
\LittleBoxA[baseline=-1ex]{\scriptsize First}
\LittleBoxA{\huge Second}
\tcblower
\LittleBoxA{\Large Third}
\LittleBoxA[baseline=-0.5ex]{\small Fourth}
\end{mybox}
\begin{mybox}[title= Little boxes centered vertically]
\LittleBox{\scriptsize First}
\LittleBox{\huge Second}
\tcblower
\LittleBox{\Large Third}
\LittleBox{\small Fourth}
\end{mybox}
\end{document}
tcolorbox
in version published in 2014-10-10 introduced box align
option which solves this problem.
Default value for box align
is bottom
, but it's possible to also choose top
, center
and base
. Therefore, a little change to LittleBox
will do the work
\newtcbox{\LittleBox}[1][]{enhanced, nobeforeafter, box align = center, #1}
\documentclass[]{article}
\usepackage[skins]{tcolorbox}
\begin{document}
\newtcbox{\LittleBox}[1][]{enhanced, nobeforeafter, box align = center, #1}%
\begin{tcolorbox}[enhanced, sidebyside, sidebyside align= center,
colbacktitle=white, coltitle=black, colback=white,
fonttitle=\large\bfseries, title= Little boxes centered vertically]
\LittleBox{\scriptsize First}
\LittleBox{\huge Second}
\tcblower
\LittleBox{\Large Third}
\LittleBox{\small Fourth}
\end{tcolorbox}
\end{document}