[Tex/LaTex] Vertical alignment of “nobeforeafter” tcolorbox

tcolorboxvertical alignment

Is there a way to vertically center the little tcolorboxes ?

\documentclass[]{article}
\usepackage[skins]{tcolorbox}

\begin{document}

\newtcbox{\LittleBox}[1][]{enhanced,nobeforeafter,#1}%

\begin{tcolorbox}[enhanced,sidebyside,sidebyside align= center, colbacktitle=white,coltitle=black,colback=white,fonttitle=\large\bfseries,title= Little boxes not centered vertically]

% not working: valign=center,valign lower=center, before=  \begin{center}, \vfill, \[\vcenter{}\], \begin{tabular}{cc}\end{tabular},sidebyside align= center,   \centering

\LittleBox{\scriptsize First} 
\LittleBox{\huge Second}
\tcblower
\LittleBox{\Large Third}
\LittleBox{\small Fourth}

\end{tcolorbox}

enter image description here

Best Answer

Two options; the first one uses a manual adjustment made using the baseline key for the tcolorboxes, 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}

enter image description here

Related Question