7

I am working on a latex document that uses tcolorboxes and I want to place two different tcolorboxes side by side. How can I achieve this?

EDIT: I found that using minipage we can achieve this. This is demonstrated here.

3
  • 1
    You could use tcbraster. But please post a MWE to show what you've tried so far.
    – TeXnician
    Commented Jan 16, 2018 at 17:28
  • @TeXnician Hi, so far I tried different widths for the boxes, but they did not work. How will I be able to use tcbraster? Commented Jan 16, 2018 at 17:32
  • A minipage is the wrong way to go here. Use tcbraster as recommended already.... look into the manual please
    – user31729
    Commented Jan 16, 2018 at 17:43

2 Answers 2

13

Here is the tcbraster way to place two (or more?) boxes side by side, by using the tcbraster environment and raster columns=2.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\begin{document}
\lipsum[2]
\begin{tcbraster}[raster columns=2,raster equal height]
\begin{tcolorbox}[nobeforeafter, title=box 1]
\lipsum[2]
\end{tcolorbox}
\begin{tcolorbox}[nobeforeafter, title=box 2]
\lipsum[2]
\end{tcolorbox}
\end{tcbraster}
\lipsum[2]
\end{document}

Update with more options:

Any option, that is not specific to the raster library will be handed over to the rastered tcolorbox environments, as such, those options have not to be specified each time, but only once in the raster setup.

Use raster column skip to increase the horizontal gap between the boxes:

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\begin{document}
\lipsum[2]
\begin{tcbraster}[raster columns=2,raster equal height,nobeforeafter,raster column skip=2cm]
  \begin{tcolorbox}[title=box 1]
    \lipsum[2]
  \end{tcolorbox}
  \begin{tcolorbox}[title=box 2]
    \lipsum[2]
  \end{tcolorbox}
\end{tcbraster}
\lipsum[2]
\end{document}

enter image description here

10

Like this?

enter image description here

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\noindent\begin{tcolorbox}[width=.475\textwidth, nobeforeafter, title=box 1]
\lipsum[2]
\end{tcolorbox}\hfill
\begin{tcolorbox}[width=.475\textwidth, nobeforeafter, title=box 2]
\lipsum[2]
\end{tcolorbox}
\lipsum[1]
\end{document}
2
  • But, there's a small issue: When I try a third tcolorbox after the two tcolorboxes that you mentioned that I want to place on a different line, it gets shifted to the left of the margin by a few inches, i.e., the first tcolorbox is vertically slightly to the right of the third one. How will get the left sides of both of them to be vertically aligned? Commented Jan 16, 2018 at 18:01
  • 2
    @Python_user for more than two boxes, use a tcbraster like in Christian's answer.
    – Ignasi
    Commented Jan 17, 2018 at 8:09

You must log in to answer this question.

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