7

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

7

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

  • It works very well, thanks ! Clever idea: "adjustbox" package. – SDrolet May 28 '14 at 16:35
3

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}

enter image description here

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.