Tcolorbox – How to Align on the Baseline of the Title in Tcolorbox

tcolorbox

I would like to the two boxes titled personal and other to appear on the same line and to be aligned on the baseline of the title. So far, I can't even get them on the same line even though there seems to be plenty of room for them.

% arara: pdflatex
% arara: pdflatex
% arara: open
\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newtcolorbox{mybox}[2][]{
  enhanced,
  attach boxed title to top left={yshift=-2ex,xshift=4ex},
  colframe=black,
  colback=white,
  fonttitle=\bfseries, 
  colbacktitle=white,
  coltitle=black,
  boxed title style={
    boxrule=0pt,
    colframe=white,
    },
  title=#2,
  #1}

\setlength\parindent{0pt}
\pagestyle{empty}
\begin{document}

\begin{mybox}{hello world}
  this is a test
\end{mybox}


  \rule{0.45\columnwidth}{2pt}

  \begin{mybox}[width=0.45\columnwidth]{{personal}}
   These are the menu items:
   \begin{itemize}
   \item 
   \item 
   \item 
   \item 
   \item 
   \end{itemize}
  \end{mybox}%%
  \begin{mybox}[width=0.45\columnwidth]{{other}}
   These are the menu items:
   \begin{itemize}
   \item 
   \item 
   \item 
   \end{itemize}
  \end{mybox}%%

\end{document}

enter image description here

Update

I've now managed to get the boxes on the same line by using the before=,after= keys.

enter image description here

But they're still not aligned as I wish to have them aligned.

I can achieve the effect that I desire by creating a strut and embedding the two tcolorbox environments within a tikzpicture:

  \def\aes{\rule[-0.5ex]{0pt}{3ex}}

  \begin{tikzpicture}

    \node[outer sep=0pt,inner sep=0pt,anchor=north west]
         at (0,0) {%%
          \begin{mybox}[width=0.45\columnwidth]{{\aes personal}}
           These are the menu items:
           \begin{itemize}
           \item 
           \item 
           \item 
           \item 
           \item 
           \end{itemize}
          \end{mybox}%%
          };

    \node[outer sep=0pt,inner sep=0pt,anchor=north west]
       at (0.5\columnwidth,0) {%%
          \begin{mybox}[width=0.45\columnwidth]{{\aes other}}
           These are the menu items:
           \begin{itemize}
           \item 
           \item 
           \item 
           \end{itemize}
          \end{mybox}%%
       };

  \end{tikzpicture}

enter image description here

but it seems that there's got to be a more natural way to do this.

Best Answer

One way is to use the adjustbox package and apply:

before=\adjustbox{valign=t}\bgroup, after=\egroup

which yields:

enter image description here

Notes:

  • If you don't want the two boxes separate horizontally, remove the \hfill.

  • Since the depth of the titles in the two boxes varied, I added a \vphantom{p} to the second box's title.

References:

Code:

\documentclass{article}
\usepackage{tcolorbox}
\usepackage{adjustbox}

\tcbuselibrary{skins}
\newtcolorbox{mybox}[2][]{
  enhanced,
  attach boxed title to top left={yshift=-2ex,xshift=4ex},
  colframe=black,
  colback=white,
  fonttitle=\bfseries, 
  colbacktitle=white,
  coltitle=black,
  boxed title style={
    boxrule=0pt,
    colframe=white,
    },
  title=#2,
  #1}

\setlength\parindent{0pt}
\pagestyle{empty}
\begin{document}

\begin{mybox}{hello world}
  this is a test
\end{mybox}


  \rule{0.45\columnwidth}{2pt}

  \begin{mybox}[width=0.45\columnwidth, before=\adjustbox{valign=t}\bgroup,
  after=\egroup\hfill]{{personal}}
   These are the menu items:
   \begin{itemize}
   \item 
   \item 
   \item 
   \item 
   \item 
   \end{itemize}
  \end{mybox}%%
  \begin{mybox}[width=0.45\columnwidth, before=\adjustbox{valign=t}\bgroup,
  after=\egroup]{{other\vphantom{p}}}
   These are the menu items:
   \begin{itemize}
   \item 
   \item 
   \item 
   \end{itemize}
  \end{mybox}%%

\end{document}