# 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
• Off topic, but P(AB) = P(A) + P(B) − P(AB) even if A and B are two events that are mutually exclusive, because in that case AB is ∅ and P(∅) = 0 by axiom. – L. F. Feb 21 '19 at 12:11

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. – kiss my armpit Mar 16 '13 at 3:17
• i'm sorry i cant figure out where you are setting the width and height in inches in your example, i just see the height as 3, which is inches? – user1709076 Oct 19 '19 at 11:46

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,
If A and B are two events that are not mutually exclusive then:
\tcblower
$P(A \cup B) = P(A) + P(B) - P(A \cap B)$
\end{tcolorbox}
\end{document}

• Could you add some example of usage? Otherwise this is more of a comment than an answer. Alternative ways of doing something are always welcome. – egreg Mar 16 '13 at 10:56

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}

• The package framed works in the same way \begin{framed} Here your text \end{framed} I don't know the differences with mdframed – loved.by.Jesus Sep 20 '17 at 13:36
• @loved.by.Jesus: I think framed is an older package: last updated in 2012. mdframed is a bit newer and allows for use of tikz. Having said that, mdframed is also geting old and the latest similar pacakge that I know of is tcolorbox. – Peter Grill Sep 21 '17 at 22:15

What about framebox ?

\framebox(300,100){some text (or keep it empty)}


where 300 is the wanted width and 100 the height of the box, in \unitlength (pt by default).

(Credits to David Carlisle)

• If you credit someone, you could post the answer as Community Wiki question to not "steal" it ;-) – Romain Picot Oct 13 '15 at 13:15
• @RomainPicot : I don't consider answering to an old question with input from a reply to another question, moreso linking to the original answer, is stealing. Actually it would even only be strictly applying the CC-BY-SA rules, provided the initial answer was original enough — which it is indubitably not… Anyway, since it's asked nicely. – Skippy le Grand Gourou Oct 13 '15 at 13:54
• +1 for simple answer! how do you arrange the text conf so it doesn't go out of box at sides? – nilon Aug 23 '16 at 14:36
• @nilon Sorry, I don't know and don't have the ability to search currently. – Skippy le Grand Gourou Aug 24 '16 at 9:24