Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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)$} 
share|improve this question
    
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

3 Answers 3

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}

enter image description here

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}
share|improve this answer
    
\relax can be omitted in this case, I think. –  Who is crazy first 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:

enter image description here

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

enter image description here

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={%
            shade,left color=white, right color=blue!20}}}, 
        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}
share|improve this answer

There is another posibility with tcolorbox package.

A MWE:

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,
adjusted title={Non Mutually Exclusive Events}]
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}
share|improve this answer
4  
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
    
+1! Very nice example, thanks. –  egreg Mar 16 '13 at 22:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.