# How to specify height and width of \fbox{}

I am trying to have my text read like this inside a box:

        If A and B are two events that are not mutually exclusive then:

$P(A \cup B) = P(A) + P(B) - P(A \cap B)$


Al I have is this, can someone help guide me of hidden commands that I don't know about?

\fbox{If A and B are two events that are not mutually exclusive then $P(A \cup B) = P(A) + P(B) - P(A \cap B)$}

-
Maybe is this what you are trying to achieve? \documentclass{article} \begin{document} If A and B are two events that are not mutually exclusive then: $P(A \cup B) = P(A) + P(B) - P(A \cap B)$ \end{document}. –  Gonzalo Medina Mar 16 '13 at 2:36
I want to somehow have a box command code around this: \begin{center} If A and B are two events that are not mutually exclusive then: \end{center} \begin{center} $P(A \cup B) = P(A) + P(B) - P(A \cap B)$ \end{center} –  Janice Mar 16 '13 at 2:50

You can use \fbox and a minipage (or a \parbox) of the desired (fixed) width; another option would be to use the varwidth environment from the varwidth package, so the resulting width is the natural width of the contents. A little example showing both approaches:

\documentclass{article}
\usepackage{varwidth}

\begin{document}

\noindent\fbox{\begin{minipage}{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}
\centering
If A and B are two events that are not mutually exclusive then:
$P(A \cup B) = P(A) + P(B) - P(A \cap B)$
\end{minipage}}

\begin{center}
\fbox{\begin{varwidth}{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}
If A and B are two events that are not mutually exclusive then:
$P(A \cup B) = P(A) + P(B) - P(A \cap B)$
\end{varwidth}}
\end{center}

\end{document}


Using the optional arguments for minipage you can control other attributes of the used box; in particular, the second optional argument allows you to specify the height:

\documentclass{article}

\begin{document}

\noindent\fbox{\begin{minipage}[t][3\height][c]{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}
\centering
If A and B are two events that are not mutually exclusive then:
$P(A \cup B) = P(A) + P(B) - P(A \cap B)$
\end{minipage}}

\end{document}

-
\relax can be omitted in this case, I think. –  stalking isn't tolerated Mar 16 '13 at 3:17

Gonzalo Medina's is the actual answer to the problem given, but here is another option: Instead of using an \fbox you could also the mdframed package which in basic usage

\begin{mdframed}
If A and B are two events that are not mutually exclusive then:
$P(A \cup B) = P(A) + P(B) - P(A \cap B)$
\end{mdframed}


produces a nice box:

but also allows you to get fancy should you so desire:

## Notes:

• The style used here is only slightly modified from one of the examples in the documentation, but am sure you could pick better color choices. This one was just meant to illustrate a few of the options, but there are numerous others.

## Code:

\documentclass{article}
\usepackage{xcolor}
\usepackage[framemethod=tikz]{mdframed}

\begin{document}
\begin{mdframed}
If A and B are two events that are not mutually exclusive then:
$P(A \cup B) = P(A) + P(B) - P(A \cap B)$
\end{mdframed}

\bigskip
\begin{mdframed}[
linecolor=red,linewidth=2pt,%
frametitlerule=true,%
apptotikzsetting={\tikzset{mdfframetitlebackground/.append style={%
frametitlerulecolor=blue,
frametitlerulewidth=1pt, innertopmargin=\topskip,
frametitle={Non Mutually Exclusive Events},
outerlinewidth=1.25pt
]
% ----------
If A and B are two events that are not mutually exclusive then:
$P(A \cup B) = P(A) + P(B) - P(A \cap B)$
\end{mdframed}
\end{document}

-

There is another posibility with tcolorbox package.

A MWE:

\documentclass{article}
\usepackage[skins]{tcolorbox}
\begin{document}
\begin{tcolorbox}[skin=widget,
boxrule=1mm,
coltitle=black,
colframe=blue!45!white,
colback=blue!15!white,
width=(.9\linewidth),before=\hfill,after=\hfill,
$P(A \cup B) = P(A) + P(B) - P(A \cap B)$