Splitting a tcolorbox into two columns

boxeshorizontal alignmenttcolorbox

I'd like to split a tcolorbox environment into two columns like this:

+---------------------------------------------------------------------------+ 
| Definition.   Lorem ipsum dolor sit amet, consectetur adipiscing elit.    |
|               Praesent ac sem commodo, venenatis nisl ac, pharetra arcu.  |   <-- tcolorbox
|               Cras accumsan pharetra facilisis. Vivamus mattis vulputate  |
|               dui, quis vulputate metus pretium a.                        |
+---------------------------------------------------------------------------+

I first tried putting a two-column table into the tcolorbox, but this did not even compile (LaTeX error: floats lost). I then tried putting two minipages (one for Definition., the rest for the text) inside the tcolorbox to split it in half, but alignment is corrupted in such a way that I don't really even know how to describe the problem:

\documentclass{standalone}

\usepackage{tcolorbox, xcolor, lmodern}

\definecolor{jblueleft}{RGB}{0, 79, 144}
\definecolor{jblueinner}{RGB}{240, 248, 255}

\newtcolorbox{exampleBox}{textmarker,
    borderline west={3pt}{0pt}{jblueleft},
    colback=jblueinner} % Define the box style.

\newcommand{\definition}[1]{
\begin{exampleBox}
    \fboxsep=0pt
    \noindent\begin{minipage}[t]{0.5\linewidth}
        {\fontfamily{lmss}\selectfont\textcolor{jblueleft}{\textbf{Definition}.}}
    \end{minipage}
    \hfill
    \begin{minipage}[t]{0.5\linewidth}
        #1
    \end{minipage}
\end{exampleBox}
}
\begin{document}
\definition{For a particle traversing a 2-dimensional path \(c\) in a force field \(\bmv F(x,y)=f(x,y)\ui+g(x,y)\uj\), the work integral is 
    \begin{align*}
        W&=\int_c \bmv F\cdot\,\mathrm d\bmv r\\
        &=\int_c f(x,y)\,\mathrm dx+\int_c g(x,y)\,\mathrm dy
    \end{align*}}
\end{document}

The following gives this erroneous output:

erroneous latex output

Best Answer

Another approach using tcolorbox options sidebyside:

\documentclass[margin=5pt]{standalone}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{tcolorbox, xcolor, lmodern}

\tcbuselibrary{skins}

\definecolor{jblueleft}{RGB}{0, 79, 144}
\definecolor{jblueinner}{RGB}{240, 248, 255}

% my guess to missing definitions
\newcommand\bmv{\bm{v}}
\newcommand\ui{\mathbf{i}}
\newcommand\uj{\mathbf{j}}

\tcbset{
  textmarker/.style={
    enhanced,
    sharp corners,
    boxrule=0pt,  
  }
}
% end of my guess

\newsavebox{\exampleTitle}
\savebox\exampleTitle{%
  \fontfamily{lmss}\bfseries
  \textcolor{jblueleft}{Definition.}}

\newtcolorbox{exampleBox}{
  textmarker,
  borderline west={3pt}{0pt}{jblueleft},
  colback=jblueinner,
  before upper=\usebox\exampleTitle,
  sidebyside,
  lower separated=false,
  sidebyside align=top,
  sidebyside gap=5pt,
  lefthand width=\the\wd\exampleTitle,
} % Define the box style.

\newcommand{\definition}[1]{%
  \begin{exampleBox}
    \tcblower
    #1%
  \end{exampleBox}%
}
\begin{document}
\definition{For a particle traversing a 2-dimensional path \(c\) in a force field \(\bmv F(x,y)=f(x,y)\ui+g(x,y)\uj\), the work integral is
    \begin{align*}
        W&=\int_c \bmv F\cdot\,\mathrm d\bmv r\\
        &=\int_c f(x,y)\,\mathrm dx+\int_c g(x,y)\,\mathrm dy
    \end{align*}}
\end{document}

enter image description here

OP's example is incomplete: none of the definitions of commands \bmv, \ui, and \uj and tcolorbox style key textmaker are provided. I used my guess instead.


Hmm, \@hangfrom, which comes from LaTeX2e kernel, will make the example shorter. Output is the same as above.

\documentclass[margin=5pt]{standalone}
\usepackage{amsmath}
\usepackage{bm}
\usepackage{tcolorbox, xcolor, lmodern}

\tcbuselibrary{skins}

\definecolor{jblueleft}{RGB}{0, 79, 144}
\definecolor{jblueinner}{RGB}{240, 248, 255}

% my guess to missing definitions
\newcommand\bmv{\bm{v}}
\newcommand\ui{\mathbf{i}}
\newcommand\uj{\mathbf{j}}

\tcbset{
  textmarker/.style={
    enhanced,
    sharp corners,
    boxrule=0pt,  
  }
}
% end of my guess

\makeatletter
\newtcolorbox{exampleBox}{
  textmarker,
  borderline west={3pt}{0pt}{jblueleft},
  colback=jblueinner,
  before upper=\@hangfrom{%
    \fontfamily{lmss}\bfseries
    \textcolor{jblueleft}{Definiton. }% note the space after "."
  },
} % Define the box style.
\makeatother

\newcommand{\definition}[1]{%
  \begin{exampleBox}   
    #1%
  \end{exampleBox}%
}

\begin{document}
\definition{For a particle traversing a 2-dimensional path \(c\) in a force field \(\bmv F(x,y)=f(x,y)\ui+g(x,y)\uj\), the work integral is
    \begin{align*}
        W&=\int_c \bmv F\cdot\,\mathrm d\bmv r\\
        &=\int_c f(x,y)\,\mathrm dx+\int_c g(x,y)\,\mathrm dy
    \end{align*}}
\end{document}
Related Question