1

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

2 Answers 2

3

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

I was almost there—turns out all that was left to do was tweak the 0.5 in the minipages to the correct ratio I wanted. I had in fact succeeded in splitting the tcolorbox into two sections, they were just equal sections when I did not want them to be.

I changed 0.5 and 0.5 to 0.15 and 0.85.

3
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
    – CarLaTeX
    Commented Apr 20, 2022 at 5:21
  • @CarLaTeX, this is my own post.
    – Joseph
    Commented Apr 20, 2022 at 16:54
  • Do you mean it is an answer?
    – CarLaTeX
    Commented Apr 20, 2022 at 18:13

You must log in to answer this question.

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