How to Put a Title on the Left Side of a tcolorbox
At a glance
- 1. Choose the placement
Use a normal title for a left-aligned heading above the content, or an overlay for a title on the box’s vertical edge.
- 2. Load tcolorbox
Load the package with its most option to enable the enhanced skin and TikZ overlay features.
- 3. Reserve space
For a vertical label, increase the box’s left padding so the label does not cover the content.
- 4. Position the label
Place a rotated TikZ node beside the frame’s west edge and pass the desired text as an environment argument.
A tcolorbox title normally appears above the box content and is left-aligned. If you want the title to run vertically along the box’s left edge instead, you need to position it separately; the example below adds a rotated label beside the frame.
Left-aligned title above the content
If by “on the left side” you mean aligned to the left rather than centered, use the ordinary title option. The title is left-aligned by default:
\begin{tcolorbox}[title=Example]
This box has a title at its upper left.
\end{tcolorbox}
A title’s alignment is different from its location: changing the alignment does not move it from the top to the vertical left edge. For a side label, use an overlay.
Put a vertical title beside the left edge
This complete example defines a reusable environment, sideTitleBox. It takes the label as its first argument and places that label vertically beside the box’s left border.
\documentclass{article}
\usepackage[most]{tcolorbox}
\newtcolorbox{sideTitleBox}[1]{
enhanced,
colback=blue!3,
colframe=blue!60!black,
boxrule=0.6pt,
left=11mm,
overlay={
\node[
rotate=90,
anchor=center,
fill=blue!60!black,
text=white,
inner xsep=3pt,
inner ysep=2pt
] at ([xshift=-4mm]frame.west) {#1};
}
}
\begin{document}
\begin{sideTitleBox}{Definition}
A side label can identify the kind of content in the box. The left padding
keeps this text clear of the label.
\end{sideTitleBox}
\end{document}
The most option loads the tcolorbox libraries needed here, including the enhanced skin and TikZ support for overlays. The overlay code draws a node relative to frame.west, the midpoint of the frame’s left edge. rotate=90 turns the node so its text runs vertically. The negative xshift moves it just outside that edge; fill and text style the label.
The left=11mm option adds interior padding. In this example the label is positioned outside the frame, so that padding is not needed to keep the label from covering the contents; it simply adds whitespace. Adjust it for the desired text margin. If you move the label inside the frame, increase left to keep the body text clear of it. The exact offset is a layout choice: try changing xshift=-4mm to bring the label closer to or farther from the frame. Because the overlay is drawn in relation to the frame, the label is also positioned consistently when the box’s height changes.
Use the environment
Pass the title in braces after the environment name. For example, \begin{sideTitleBox}{Note} creates a box with the vertical label “Note.” The environment body can contain ordinary text and paragraphs. You can use the same definition for several boxes with different labels.
If you want the label inside the box rather than outside it, change the horizontal shift or use a position farther to the right. Keep enough left padding to prevent the label and body text from colliding.
Common mistakes
- Confusing alignment with position:
halign title=leftconcerns alignment of a title at the top; it does not create a vertical side title. - Leaving too little padding: The overlay does not take up space in the normal text layout. If you place the label inside the frame, increase
leftso the body text does not run underneath it. - Positioning relative to the page: Use
frame.westrather than page coordinates. The frame anchor makes the label follow its own box. - Using an overlay without an enhanced skin: The
enhancedoption enables the overlay features used in this example; load the appropriate tcolorbox library if you are not usingmost.
For a horizontal title tab attached to the top-left corner rather than a vertical side label, use tcolorbox’s boxed-title attachment options instead of rotating an overlay node.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.