Tx · LaTeX & TikZ

How to Position a Starred tcolorbox

Published By the 9to5Science editorial team

At a glance

  1. 1. Use the right syntax

    Write the star as part of the environment name, then put the tcolorbox options in square brackets.

  2. 2. Choose a width

    Set the box width relative to the current column, such as using 0.9 times linewidth in paracol.

  3. 3. Align the box

    Use a surrounding alignment environment to position the box; halign aligns its contents, not the box itself.

  4. 4. Check the star

    The starred environment is unbreakable; use the unstarred environment with breakable when the box must split across pages.

Advertisement

A starred tcolorbox uses the same option syntax as an ordinary tcolorbox. Put the star in the environment name and put the box options in square brackets immediately afterward. The star does not introduce a float-placement argument such as [h]; a tcolorbox is not a figure or table float.

In a paracol column, use the column’s \linewidth to size a box relative to the available column width. To center or right-align the box, align the box itself with a surrounding environment. The halign option instead controls alignment of the material inside the box.

The starred environment’s syntax

The general form is:

\begin{tcolorbox*}[<tcolorbox options>]
  Box contents
\end{tcolorbox*}

For example, width=0.9\linewidth requests a box nine-tenths as wide as the current line. Options are key-value settings, not positional arguments. Put the options inside the square brackets, separated by commas.

The starred form is unbreakable. An ordinary tcolorbox is also unbreakable by default; use the ordinary environment with the breakable option if the box needs to break across pages:

\begin{tcolorbox}[breakable, width=\linewidth]
  This box may continue onto another page.
\end{tcolorbox}

Center or right-align a box in paracol

Here is a complete example. It makes a narrower box in each column and centers each box within that column. The center environment positions the box; halign=center centers text inside it.

\documentclass{article}
\usepackage{paracol}
\usepackage[most]{tcolorbox}

\begin{document}
\begin{paracol}{2}

\begin{center}
\begin{tcolorbox*}[
  width=0.9\linewidth,
  colback=blue!5,
  colframe=blue!50!black,
  halign=center
]
  Box in the first column
\end{tcolorbox*}
\end{center}

\switchcolumn

\begin{center}
\begin{tcolorbox*}[
  width=0.9\linewidth,
  colback=green!5,
  colframe=green!50!black,
  halign=center
]
  Box in the second column
\end{tcolorbox*}
\end{center}

\end{paracol}
\end{document}

The paracol package sets the line width within each column, so \linewidth refers to that column’s available width. The box therefore scales with the column rather than with the full text block. For a right-aligned box, replace center with flushright. A box at its natural width or at width=\linewidth will already occupy the available width, leaving no horizontal space to shift.

Box alignment versus content alignment

These settings solve different problems:

  • width=... controls the box’s overall width.
  • halign=left, halign=center, or halign=right aligns ordinary text inside the box.
  • An outer center or flushright environment positions a narrower box in the surrounding column.

For example, a narrow box with halign=right still sits at the left edge unless you also position the box itself. Conversely, centering a box does not necessarily center its text.

Common mistakes

  • Using [h] as a position option. That notation is used with floats such as figure. A tcolorbox takes its own key-value options, so [h] is not a general instruction to place the box “here.”
  • Putting the star in the wrong place. Use \begin{tcolorbox*}[...] and \end{tcolorbox*}. The star is part of the environment name, not a separate argument after the options.
  • Confusing halign with box placement. It aligns content inside the box, not the box relative to the column.
  • Using the starred form when page breaks are needed. Use tcolorbox with breakable if the contents may span pages.
  • Sizing against the page rather than the column. Inside paracol, use \linewidth for the current column’s width. A fixed measure such as 10cm may be wider than a narrow column.

If a custom box environment is involved, its optional and mandatory arguments come from its own definition. The same basic rule still applies: the tcolorbox options belong in the optional argument immediately after the environment name, unless the custom definition explicitly changes how options are supplied.

References

  1. tcolorbox: CTAN package page and package documentation
  2. paracol: CTAN package page and package documentation

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.