11

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?

enter image description here

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.

6 Answers 6

7

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}
  {\end{minipage}\end{Sbox}\begin{center}\shadowbox{\TheSbox}\end{center}}

...

\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.

4

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[most]{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},
            drop fuzzy shadow]
    \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}

enter image description here

Update: recent tcolorbox versions introduced vignette library which produce the desired 3D effect:

\begin{tcolorbox}[enhanced, width=.75\linewidth, 
            colback=blue!50!green!20,
            arc=0pt, outer arc=0pt, 
            borderline={0.5pt}{3pt}{black!70, sharp corners},
            underlay vignette
            ]
    \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}

enter image description here

3

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.

3

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

1
  • 2
    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!) Sep 29, 2010 at 4:41
3

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}
\usepackage{adjustbox}

\begin{document}

\lipsum[1]

\begin{adjustbox}{minipage=200pt,margin=10pt,bgcolor=blue!25,frame,center,margin=0pt \medskipamount}
    \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)
\end{adjustbox}

\lipsum[2]

\end{document}

Result

2

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 must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .