9

I'm trying to put two instances of tcolorbox side by side and to vertically align to the top. From other posts I have tried minipage with option [t] with this code

\begin{document}
\begin{minipage}[t]{0.5\textwidth}
\begin{tcolorbox}[colback=isabelline,colframe=antiquewhite!20!black,title=Boundary layer]
\footnotesize{0, no boundary-layer\\
1, YSU scheme\\
2, Mellor-Yamada-Janjic TKE\\
3, NCEP Global Forecast System}
\end{tcolorbox}
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
\begin{tcolorbox}[colback=isabelline,colframe=antiquewhite!20!black,title=Surface physics]
\footnotesize{0, no surface temp prediction\\
1, thermal diffusion scheme\\
2, Unified Noah land-surface model\\
1, thermal diffusion scheme\\
2, Unified Noah land-surface model\\
1, thermal diffusion scheme\\
2, Unified Noah land-surface model\\
3, RUC land-surface model}
\end{tcolorbox}

\end{minipage}
\end{document}

But the result is that they are bottom-aligned. What am I missing? enter image description here

Thanks

4
  • \footnotesize does not have an argument, it is a font size switch only. And you don't need explicit `\` , just leave an empty line
    – user31729
    Feb 3, 2017 at 12:25
  • There's not any argument for footnotesize. 0 is the first character that has this font size.
    – pacomet
    Feb 3, 2017 at 12:27
  • 1
    No, you're stating \footnotesize{0, no surface...} ... this is like an argument. \footnotesize is sufficient. If you want to restrict the meaning of \footnotesize to some part of the text only, use it this way: {\footnotesize foo bar}, but apparently you wanted all to appear in that size...
    – user31729
    Feb 3, 2017 at 12:28
  • 1
    A tip: If you have many of such boxes, defining a \newtcolorbox environment will be very effective -- it will prevent specifing the same options over and over again.
    – user31729
    Feb 3, 2017 at 12:40

2 Answers 2

9

See the update for a special tcolorbox for such environments at the end of the answer.

Use tcbraster to align the box -- this provides a much cleaner interface for many setups with tcolorbox.

Say \begin{tcbraster}[raster columns=2,box valign=top]...\end{tcbraster}, for example

Please note that only tcolorbox environments may appear in a raster.

\documentclass{article}

\usepackage[x11names,svgnames,dvipsnames]{xcolor}
\usepackage[most]{tcolorbox}

\begin{document}

\begin{tcbraster}[raster columns=2, raster valign=top]
\begin{tcolorbox}[colback=white!70!yellow,colframe=white!20!black,title=Boundary layer]
\footnotesize 0, no boundary-layer

1, YSU scheme

2, Mellor-Yamada-Janjic TKE

3, NCEP Global Forecast System
\end{tcolorbox}
\begin{tcolorbox}[colback=white!70!yellow,colframe=white!20!black,title=Surface physics]
\footnotesize 0, no surface temp prediction 

1, thermal diffusion scheme

2, Unified Noah land-surface model

1, thermal diffusion scheme

2, Unified Noah land-surface model

1, thermal diffusion scheme

2, Unified Noah land-surface model

3, RUC land-surface model
\end{tcolorbox}
\end{tcbraster}
\end{document}

enter image description here

Update with special tcolorbox for this.

\documentclass{article}

\usepackage[x11names,svgnames,dvipsnames]{xcolor}
\usepackage[most]{tcolorbox}

\newtcolorbox{somebox}[1][]{%
  colback=white!70!yellow,
  colframe=white!20!black,
  #1%
}


\begin{document}
\begin{tcbraster}[raster columns=2, raster valign=top,fontupper=\footnotesize]
\begin{somebox}[title=Boundary layer]
0, no boundary-layer

1, YSU scheme

2, Mellor-Yamada-Janjic TKE

3, NCEP Global Forecast System
\end{somebox}
\begin{somebox}[title=Surface physics]
0, no surface temp prediction 

1, thermal diffusion scheme

2, Unified Noah land-surface model

1, thermal diffusion scheme

2, Unified Noah land-surface model

1, thermal diffusion scheme

2, Unified Noah land-surface model

3, RUC land-surface model
\end{somebox}
\end{tcbraster}
\end{document}
5
  • fontupper=\footnotesize would be even easier...
    – user31729
    Feb 3, 2017 at 12:41
  • 1
    box align=top could be also a valid alternative. It doesn't need a raster and, I think, it's easier to adjust the width of boxes when they don't occupy the whole line or they are not equal.
    – Ignasi
    Feb 5, 2017 at 17:06
  • @Ignasi: But that's the point: You have to manually adjust the width, of course box align=top works for single boxes then.
    – user31729
    Feb 5, 2017 at 17:28
  • for single boxes and with nobeforeafter for pairs of boxes like in this case (see pag 77. example at bottom of page).
    – Ignasi
    Feb 5, 2017 at 17:32
  • @Ignasi: Sorry, singles boxes = boxes that are not inside a raster, i.e. not grouped.
    – user31729
    Feb 5, 2017 at 17:35
6

Here, I used the \belowbaseline feature of stackengine to place each minipage a value of -\ht\strutbox below the baseline, so that it acts like a [t] aligned box. I added, as a test, "See baseline" text before the first box, so as to discern the rendered alignment.

\documentclass{article}
\usepackage{tcolorbox,xcolor,stackengine}
\begin{document}
See baseline\belowbaseline[-\ht\strutbox]{\begin{minipage}{0.5\textwidth}
\begin{tcolorbox}[colback=red!3,colframe=yellow!20!black,title=Boundary layer]
\footnotesize{0, no boundary-layer\\
1, YSU scheme\\
2, Mellor-Yamada-Janjic TKE\\
3, NCEP Global Forecast System}
\end{tcolorbox}
\end{minipage}}
\belowbaseline[-\ht\strutbox]{\begin{minipage}{0.5\textwidth}
\begin{tcolorbox}[colback=red!3,colframe=yellow!20!black,title=Surface physics]
\footnotesize{0, no surface temp prediction\\
1, thermal diffusion scheme\\
2, Unified Noah land-surface model\\
1, thermal diffusion scheme\\
2, Unified Noah land-surface model\\
1, thermal diffusion scheme\\
2, Unified Noah land-surface model\\
3, RUC land-surface model}
\end{tcolorbox}
\end{minipage}}
\end{document}

enter image description here

4
  • 2
    Your obsession of this 'strange' stackengine package is becoming very obvious;-)
    – user31729
    Feb 3, 2017 at 12:39
  • 1
    @ChristianHupfer As noted before, if the only tool in your toolbox is a hammer, pretty soon every problem starts looking like a nail. Feb 3, 2017 at 12:44
  • 1
    tcolorbox is a Swiss Army Knife... not usable everywhere, but very often ... and I live only 100km away from the border to Switzerland ;-)
    – user31729
    Feb 3, 2017 at 12:46
  • 1
    @ChristianHupfer I'm thinking of renaming the package OPositive (;^)) to remind users that it is the universal-donor package that any code can receive. Hmmm. maybe RubeGoldberg would be more appropriate?? Feb 3, 2017 at 12:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .