8.4 Flexible boxes for multiple purposes

Standard LaTEX offers basic box manipulations through the graphics and graphicx packages. This is further extended through adjustbox, but basically boxes remain boxes, and you are confined to adding a simple border, scaling, rotating, or clipping and that’s about it.

If you needed other special enhancements, then you had to turn to the few specialized packages available for adding shadows (e.g., shadow by Mauro Orlandini), a frame around a minipage (boxedminipage by Scott Pakin), or the more comprehensive fancybox package by Timothy Van Zandt offering shadows, oval frames, and a few other features, but on the whole the available options are somewhat limited.

This only changed fairly recently when Thomas Sturm introduced his tcolorbox package, which sets out to be a one-stop for any kind of complex box presentation including features like splitting them across pages or other goodies.

The package comes with a huge manual [186] of more than 500 pages. We therefore limit ourselves to show only the main features that are useful in many situations. Thus, if you miss some special feature or find that your desired layout is difficult to achieve, check out that manual, because chances are high that your needs are covered there through additional keys or commands not covered in this book.

8.4.1 tcolorbox - The basic usage

The core functionality of tcolorbox is provided by an environment that builds a box object based on the settings given in its optional key/value list argument. We discuss various useful keys throughout this section.

8.4.2 Extending tcolorbox through libraries

The functionality covered by tcolorbox is huge, and for better organization some of it is placed into libraries that are available only on demand through a package option or alternatively through a declaration in the preamble. In this book we partly cover skins, breakable, vignette, and poster with a few examples.

However, there are many more libraries to explore, for example, listings, listingsutf8, and minted (alternative libraries for displaying listings), theorems (boxed theorems), fitting (adjust content size to available space), xparse (use extended command and environment declarations of LaTEX, previously implemented in the xparse package), and documentation (for documenting LaTEX source code). For details of their functionalities refer to the package manual [186].

8.4.3 Defining new tcolorbox environments and commands

In Example 8-4-22 we have already made use of the powerful possibility to define your own named tcolorbox environments or commands. Here is now the full syntax for such declarations.

8.4.4 Special tcolorbox applications

Given that the documentation for the tcolorbox package has more than 500 pages, you can imagine that it describes many interesting applications that we cannot discuss in the available space, e.g., displaying listings, boxed theorems, creation of exercises with solutions, and many more. If you are interested in any of them, refer to package manual [186] for details.

For this book we conclude with three applications: how to turn tcolorboxes into float objects, how to make rasters of boxes, and how to produce large professionallooking posters with the package.