Even More Beautiful LaTeX Boxes


What skimming 500 pages of documentation yields

Having fancy boxes is nice. Since I personally write quite a few summaries for my studies (some of which are available over here), I’ve come to appreciate them as a way of highlighting important information without just having bold-text-keywords everywhere. They can also be a delimiter, or allow you to find the appropriate topic at a glance.

A blog post made by fellow Polyring-member xyquadrat (don’t be shy, give him a visit here) reminded me that creating good-looking boxes can be quite daunting.

It also reminded me that blog posts need not be article-length ramblings or thought-provoking introductions to a complex topic. So, in this very short post I’ll give you some fancy tcolorbox presets you are free to use and modify in whatever way you see fit.

Let’s get started!

An unassuming box

What’s the first thing that stands out when you look at a default tcolorbox?

default

That’s right - nothing. It’s just a box. It doesn’t demand your attention, it sits there idly encapsulating whatever information you have made it show. It’s plain but nothing more, functional but barebones, a box but not a box.

And that’s completely fine.

However, for me personally, it can be kind of hard to make the title out at a glance. Also, it breaks up the flow of reading, but not in a way that’s saying “Look here, this is important!”, it’s just… there. It’s like someone removed the labels of the terraria at the zoo: You know something’s in there and it’s probably interesting to look at, it is jarring enough to distract you from just walking by - it demands attention, but not in a way where you actually feel like you want to investigate.

Am I going overboard with metaphors that scarcely make sense? Probably.

Anyways, here’s my take on a default box.

!default

Notice that not much has changed. The title now demands to be looked at and is easily readable, but besides that, the box is mostly the same.

And that’s also fine. It’s a basic building block, and great for documents where you’ll use tons of those and using a more fancy version would be visually distracting.

I’ve also made a definition and theorem variant that use the same counter, which is helpful for those documents where they use one numbering for, well, everything. You can of course remove those bits of code or add more boxes that use that counter.

Here’s the code for them:

\newtcbtheorem[use counter=algocf, number within=section]{definition}{Definition}{
                lower separated=false,
                colback=white!80!gray,
colframe=white, fonttitle=\bfseries,
colbacktitle=white!50!gray,
coltitle=black,
enhanced,
%parbox=false,
boxed title style={colframe=black},
attach boxed title to top left={xshift=0.5cm,yshift=-2mm},
}{def}

\newtcbtheorem[use counter from=definition, number within=section]{theorem}{Theorem}{
                lower separated=false,
                colback=white!80!gray,
colframe=white, fonttitle=\bfseries,
colbacktitle=white!50!gray,
coltitle=black,
enhanced,
boxed title style={colframe=black},
attach boxed title to top left={xshift=0.5cm,yshift=-2mm},
}{th}

Bonus: These are automatically labeled, the last set of brackets defines their prefix. For example, to reference a box

\begin{definition}{coolstuff}{mylabel} 
	Text 
\end{definition}

You’d use

On page \pageref{def:mylabel} we have the box titled \nameref{def:mylabel}.
References are easy!

Colours!

Am I mad that it is called tcolorbox and not tcolourbox? Maybe.

A simple box is nice. But sometimes you want something that pops. If the previous box was your average run-of-the-mill box, then these are the boxes that spend too much of their income on fancy clothes and makeup.

But dang do they look good in them.

Colours

These are the boxes that I featured previously in my post on LaTeX. Here’s my code for the orange version - I think you can figure out fairly easily what to tweak to get them just right for your taste.

\newtcolorbox{defbox}[1]{
before skip=7.5pt,
enhanced,
fonttitle=\sffamily\bfseries\large,
coltitle=orange,
title=Definition: #1,
title code={
\path[fill=orange!20] (title.south west) rectangle (frame.north east);
\path[draw=orange,solid,line width=0.45mm]
([xshift=5mm]title.south west) -- ([xshift=-5mm]title.south east);
},
boxrule=0pt,frame hidden,
toprule=2mm,
borderline west={4pt}{0pt}{orange},
colback=orange!20,
}

Closing Remarks

I initially wanted to write only a very, very short text accompanying the code.

Well, that failed.

However, I hope that I have convinced you that you can design great-looking and/or functional boxes in \(\LaTeX \). If your creativity has been sparked (or you simply think all presets found on the internet don’t suit you), check out the documentation of tcolorbox - it’s about as extensive as they get, and even provide lots of neat examples you can take inspiration from.