Published 2006-11-24 |
Author:
Kjell Magne Fauske

Colorful rounded boxes seems to be an important part of most poster presentations. Here are a few examples on how to create boxes with text and math using PGF/TikZ. The easiest solution is to put a minipage environment inside a node.

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the
**LaTeX Forum**.

Oder frag auf Deutsch auf TeXwelt.de.
En français: TeXnique.fr.

```
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,snakes}
\usepackage{amsmath,amssymb}
\begin{document}
% Define box and box title style
\tikzstyle{mybox} = [draw=red, fill=blue!20, very thick,
rectangle, rounded corners, inner sep=10pt, inner ysep=20pt]
\tikzstyle{fancytitle} =[fill=red, text=white]
\begin{tikzpicture}
\node [mybox] (box){%
\begin{minipage}{0.50\textwidth}
To calculate the horizontal position the kinematic differential
equations are needed:
\begin{align}
\dot{n} &= u\cos\psi -v\sin\psi \\
\dot{e} &= u\sin\psi + v\cos\psi
\end{align}
For small angles the following approximation can be used:
\begin{align}
\dot{n} &= u -v\delta_\psi \\
\dot{e} &= u\delta_\psi + v
\end{align}
\end{minipage}
};
\node[fancytitle, right=10pt] at (box.north west) {A fancy title};
\node[fancytitle, rounded corners] at (box.east) {$\clubsuit$};
\end{tikzpicture}%
%
\tikzstyle{mybox} = [draw=blue, fill=green!20, very thick,
rectangle, rounded corners, inner sep=10pt, inner ysep=20pt]
\tikzstyle{fancytitle} =[fill=blue, text=white, ellipse]
%
\begin{tikzpicture}[transform shape, rotate=10, baseline=-3.5cm]
\node [mybox] (box) {%
\begin{minipage}[t!]{0.5\textwidth}
Fermat's Last Theorem states that
\[
x^n + y^n = z^n
\]
has no non-zero integer solutions for $x$, $y$ and $z$ when $n > 2$.
\end{minipage}
};
\node[fancytitle] at (box.north) {Fermat's Last Theorem};
\end{tikzpicture}
%
\end{document}
```

## Comments

Hello Kjell Magne,

I tried to modify your example to produce old style computer paper for matrix printers and experienced the problem not being able to check for the end of the box. So I stripped down the code to the essential parts and included the explicit question as a comment. Please help.

Wolfgang

Do you mean the line height? Not sure how to calculate this accurately. I'm not familiar enough with the way TeX breaks the text. If you know the height of the box you can probably find a decent estimate.

You can get this information from the node anchor coordinates like you suggested. Here is a macro I wrote a long time ago:

If you feed it the appropriate node coordinates it should compute the height of the box for you. Probably not the most elegant solution.

Hi all & Kjeld

Amazing work... I tried puzzling a bit with it. And i have made some code which makes it easier to type the club suit and the title to the boxes. Check this code out. I really think it simplifies things a lot! And it brings many possibilities with it! :D

Hope this eases the TikZ-ing! :D

Kind regards Nick

@Nick: Thanks for sharing. Your solution is much more clever and elegant than mine.

wow, you guys are too good at this! Very clever! Nice solution for slides, etc.

Furthermore, this is a good solution to box equations with numbers without having to install the empheq package. This provides an easier way to emphasize stuff in a report. And it makes for great slides ofcourse. Again, really like this minipage solution!

This provides an easier way to emphasize stuff in a report. And it makes for great slides of course. Again, really like this minipage solution!

I made a package out of your example, thanks a lot for sharing !

http://snouffy.free.fr/blog-en/index.php/post/2010/01/30/Nice-boxes-for-your-theorems-with-tikz

Alexis.

Thanks Alexis, very useful! I just tested your package from your website. I just cannot write a comment there, perhaps a login is required.

Iformation from the node anchor coordinates like you suggested. Here is a macro I wrote a long time ago:

I met these beautiful boxes. I wanted to use for definitions and theorems with different copteurs in sections. Please help

Adding comments is currently not enabled.