How to Position a Starred tcolorbox
At a glance
- 1. Use the right syntax
Write the star as part of the environment name, then put the tcolorbox options in square brackets.
- 2. Choose a width
Set the box width relative to the current column, such as using 0.9 times linewidth in paracol.
- 3. Align the box
Use a surrounding alignment environment to position the box; halign aligns its contents, not the box itself.
- 4. Check the star
The starred environment is unbreakable; use the unstarred environment with breakable when the box must split across pages.
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, orhalign=rightaligns ordinary text inside the box.- An outer
centerorflushrightenvironment 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 asfigure. Atcolorboxtakes 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
halignwith 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
tcolorboxwithbreakableif the contents may span pages. - Sizing against the page rather than the column. Inside
paracol, use\linewidthfor the current column’s width. A fixed measure such as10cmmay 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
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.