# Suggestions on how to place a sentence of text inside a box with a border around it

I have an "XYZ's Law" quote that I'd like to show somewhere on a page vertically centered in a box with some form of simple border around it. Basically I'm trying to achieve the LaTeX equivalent of how Norvig's Law is shown at http://norvig.com/norvigs-law.html where there's some text centred and placed inside a bordered box on the page. Can anyone begin to make suggestions on how I'd go about creating something of such an appearance?

I apologize if my use of the term box here overlaps with another use of the term that is specific to LaTeX. I've seen the term box come up a number of times in LaTeX, so I don't know whether it has special meaning within the realms of LaTeX that I've gone and unintentionally overlapped here.

-

To get you started, and following Jan's suggestion of using fancybox, you could define an environment such as

\usepackage{fancybox}

\newenvironment{boxedlaw}[1]
{\begin{Sbox}\begin{minipage}{#1}\centering}

...

\begin{boxedlaw}{5cm}
XYZ's Law
\end{boxedlaw}


And really have a look at the documentation from this package for further suggestions as well as other styles of boxes.

-

For start, you may want to look at the fancybox package. For some ideas how to create even fancier boxes, look at this tikz example.

-

Metafun/ConTeXt is great at this. See for example chapter 4 in the metafun manual.

-
I think this sort of stuff is overkill for the task in question, but the in-paragraph shading of sentences shown in Chapter 5 are seriously cool. (P.S. wish that manual had PDF bookmarks!) – Will Robertson Sep 29 '10 at 4:41

Previous answers have presented several options to draw framed and colored boxes but tcolorbox was missing. Next there is an example using it.

\documentclass{article}

\usepackage{lipsum}% For dummy text to show centering
\usepackage{xcolor}
\usepackage[skins]{tcolorbox}

\begin{document}

\lipsum[1]

{\par\centering
\begin{tcolorbox}[enhanced, width=.75\linewidth,
colback=blue!50!green!20,
arc=0pt, outer arc=0pt,
borderline={1.5pt}{0pt}{black!90},
borderline={0.25pt}{3pt}{black!70, sharp corners},
\centering
{\LARGE Norvig's Law
\par\medskip}
\normalsize\itshape
Any technology that surpasses 50\% penetration\\
will \textbf{never} double again\\
(in any number of months)
\end{tcolorbox}\par}

\lipsum[2]

\end{document}


-

For proclamations like such, you can also consider using the ntheorem package, which provides a "framed theorem" environment.

\usepackage{ntheorem}

\theoremstyle{nonumberplain}
\newframedtheorem{XYZLaw}{XYZ's Law}

...

\begin{XYZLaw}
XYZ's law states that blah implies foobar
\end{XYZLaw}

-

You can use adjustbox for this with the following keys:

• minipage=<width> for the paragraph box.
• margin=<amount> to add some padding.
• bgcolor=<color> to set the background color.
• frame to draw a border around it (Note: option values can be used to adjust it).
There is also cframe=<color> (again plus optional values) if you want a colored frame.
• center to center it the current \linewidth.
• margin=0pt <vskip> to add some vertical skip above and below.

Note that the order of the keys is meaningful.

\documentclass{article}

\usepackage{lipsum}% For dummy text to show centering
\usepackage{xcolor}

\begin{document}

\lipsum[1]

\centering\sffamily
{\LARGE Norvig's Law
\par\medskip}
\normalsize
Any technology that surpasses 50\% penetration\\
will \textbf{never} double again\\
(in any number of months)