tikz.dev / tcolorbox Manual

The tcolorbox package

The Core Package

6 Side by Side

A side by side box is a special tcolorbox where the upper and lower part of the box are set side by side. All boxes of this kind are unbreakable.

6.1 Basic Settings
  • /tcb/sidebyside=true|false(default true, initially false)

  • Normally, the upper part and the lower part of the box have their positions as their names suggest. If sidebyside is set to true, the upper part is drawn left-handed and the lower part is drawn right-handed. Both parts are drawn together with the geometry settings of the upper part but the space is divided horizontally according to the following options. Colors, fonts, and box content additions are used individually. The resulting box is unbreakable.

    Compiled output

    \tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries}

    \begin{tcolorbox}[title=My title,sidebyside]
    This is the upper (\textit{left-handed}) part.
    \tcblower
    This is the lower (\textit{right-handed}) part.
    \end{tcolorbox}

    Compiled output

    % \usepackage{lipsum}
    % \tcbuselibrary{skins}
    \begin{tcolorbox}[bicolor,sidebyside,righthand width=3cm,
    sharp corners,boxrule=.4pt,colback=green!5,colbacklower=green!50!black!50]
    \lipsum[2]
    \tcblower
    \includegraphics[width=\linewidth]{goldshade}%
    \end{tcolorbox}
  • /tcb/sidebyside align=⟨alignment⟩(no default, initially center)Updated: 2024-11-26

  • Sets the vertical ⟨alignment⟩ for the left-handed and right-handed part.

    Feasible values for ⟨alignment⟩ are:

    • center: identical to minipage option c.

    • top: identical to minipage option t (aligns the top lines of the left-handed and right-handed side according to their baselines).

      This value of ⟨alignment⟩ needs luacolor to work properly since version 6.0.0 (2023-02-10). Adding \strut may help alternatively to simulate the effect for equal font heights.

    • bottom: identical to minipage option b (aligns the bottom lines of the left-handed and right-handed side according to their baselines).

    • center seam: aligns the center of the left-handed and right-handed side.

    • top seam: aligns the very top seam of the left-handed and right-handed side.

    • bottom seam: aligns the very bottom seam of the left-handed and right-handed side.

    Compiled output

    \tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,nobeforeafter,
    left=2mm,right=2mm,sidebyside,sidebyside gap=6mm,width=(\linewidth-2mm)/3}

    \begin{tcolorbox}[adjusted title=center,sidebyside align=center]
    This is a text which is too long for one line.
    \tcblower
    This is a short text.
    \end{tcolorbox}\hfill
    \begin{tcolorbox}[adjusted title=top,sidebyside align=top]
    This is a text which is too long for one line.
    \tcblower
    This is a short text.
    \end{tcolorbox}\hfill
    \begin{tcolorbox}[adjusted title=bottom,sidebyside align=bottom]
    This is a text which is too long for one line.
    \tcblower
    This is a short text.
    \end{tcolorbox}

    center, top, and bottom are identical to the known corresponding minipage options. While this is the preferred approach for text content, the result for boxed content like tables or images may not be as expected.

    For such content, one may use center seam, top seam, and bottom seam. For example, top seam aligns the very top seam of the left-handed and right-handed side.

    Compiled output

    \tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,
    size=small,righthand width=4cm,sidebyside,sidebyside gap=6mm,lower separated=false}

    \begin{tcolorbox}[adjusted title=center seam,sidebyside align=center seam]
    This is my description text for the pictures displayed on the right-handed side.
    \tcblower
    \includegraphics[width=\linewidth/2]{goldshade}%
    \includegraphics[width=\linewidth/2]{blueshade}
    \end{tcolorbox}

    \begin{tcolorbox}[adjusted title=top seam,sidebyside align=top seam]
    This is my description text for the pictures displayed on the right-handed side.
    \tcblower
    \includegraphics[width=\linewidth/2]{goldshade}%
    \includegraphics[width=\linewidth/2]{blueshade}
    \end{tcolorbox}

    \begin{tcolorbox}[adjusted title=bottom seam,sidebyside align=bottom seam]
    This is my description text for the pictures displayed on the right-handed side.
    \tcblower
    \includegraphics[width=\linewidth/2]{goldshade}%
    \includegraphics[width=\linewidth/2]{blueshade}
    \end{tcolorbox}
  • /tcb/lefthand ratio=⟨fraction⟩(no default, initially 0.5)

  • Sets the width of the left-handed part to the given ⟨fraction⟩ of the available space. ⟨fraction⟩ is a value between 0 and 1.

    Compiled output

    \tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries}

    \begin{tcolorbox}[title=My title,sidebyside,lefthand ratio=0.25]
    This is the upper (\textit{left-handed}) part.
    \tcblower
    This is the lower (\textit{right-handed}) part.
    \end{tcolorbox}
  • /tcb/righthand ratio=⟨fraction⟩(no default, initially 0.5)

  • Sets the width of the right-handed part to the given ⟨fraction⟩ of the available space. ⟨fraction⟩ is a value between 0 and 1.

    Compiled output

    \tcbset{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries}

    \begin{tcolorbox}[title=My title,sidebyside,righthand ratio=0.25]
    This is the upper (\textit{left-handed}) part.
    \tcblower
    This is the lower (\textit{right-handed}) part.
    \end{tcolorbox}

If one side of a side-by-side box should be adapted to the width of its content, this width has to be computed beforehand. The following example uses a savebox \mysavebox to store the picture to determine its width. A more convenient way to handle this task is to use the methods from Section 6.2.

Compiled output

% \tcbuselibrary{skins}
% \usepackage{lipsum}
% \newsavebox\mysavebox % preamble
\DeclareTotalTColorBox \mysidebox { O{} +m +m }{
bicolor,colback=white,colbacklower=yellow!10,
fonttitle=\bfseries,center title,
sidebyside,
code={\sbox{\mysavebox}{#2}},
lefthand width=\wd\mysavebox,
drop lifted shadow,
#1
}
{\usebox{\mysavebox}\tcblower#3}

\mysidebox[title=The Triangle]{%
\begin{tikzpicture}
\path[fill=red!20,draw=red!50!black]
(0,0) node[below]{A} -- (3,1) node[right]{B}
-- (1,4) node[above]{C} -- cycle;
\end{tikzpicture}%
}{%
\lipsum[1]
}
6.2 Advanced Settings
  • /tcb/sidebyside adapt=⟨side(s)⟩(no default, initially none)New: 2015-11-20

  • The option allows the left-handed and/or right-handed side to determine the dimensions of the box. This option is only valid inside \tcbsidebyside.

    Feasible values for ⟨side(s)⟩ are:

    Compiled output

    % \tcbuselibrary{skins}
    \tcbsidebyside[sidebyside adapt=left,
    title=Very important table,
    beamer,colframe=blue!50!black,colback=blue!10,
    lower separated=false,sidebyside gap=5mm
    ]{%
    \begin{tabular}{|l|c|r|}\hline
    left & center & right\\\hline
    A & B & C\\\hline
    D & E & F\\\hline
    \end{tabular}
    }{%
    This table contains the most important figures for
    all future actions. You may notice that B follows A,
    C follows B, and so on.
    }

    Compiled output

    % \tcbuselibrary{skins}
    \tcbsidebyside[sidebyside adapt=right,
    blanker,sidebyside gap=5mm
    ]{%
    \lipsum[2]
    }{%
    \begin{tikzpicture}
    \path[fill=yellow,draw=yellow!75!red] (0,0) circle (1cm);
    \fill[red] (45:5mm) circle (1mm);
    \fill[red] (135:5mm) circle (1mm);
    \draw[line width=1mm,red] (215:5mm) arc (215:325:5mm);
    \end{tikzpicture}
    }

    Compiled output

    % \tcbuselibrary{skins}
    \tcbsidebyside[sidebyside adapt=both,
    enhanced,center,
    title=Both sides adapted,
    attach boxed title to top center={yshift=-2mm},
    coltitle=black,boxed title style={colback=red!25},
    segmentation style=solid,colback=red!5,colframe=red!50
    ]{%
    \begin{tabular}{|l|c|r|}\hline
    left & center & right\\\hline
    A & B & C\\\hline
    D & E & F\\\hline
    \end{tabular}
    }{%
    \begin{tikzpicture}
    \path[fill=yellow,draw=yellow!75!red] (0,0) circle (1cm);
    \fill[red] (45:5mm) circle (1mm);
    \fill[red] (135:5mm) circle (1mm);
    \draw[line width=1mm,red] (215:5mm) arc (215:325:5mm);
    \end{tikzpicture}
    }