我试图让我的文本在一个框内显示如下:
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)$
我所拥有的就是这些,有人可以帮我了解我不知道的隐藏命令吗?
\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)$}
答案1
您可以使用\fbox
和一个minipage
(或\parbox
)所需(固定)宽度;另一个选择是使用varwidth
来自varwidth
包,因此最终的宽度是内容的自然宽度。下面是一个展示这两种方法的小例子:
\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}
使用可选参数minipage
您可以控制所用框的其他属性;特别是,第二个可选参数允许您指定高度:
\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}
答案2
还有另一种可能性彩色盒子包裹。
一位 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}
答案3
关于什么framebox
?
\framebox(300,100){some text (or keep it empty)}
其中 300 是所需的宽度,100 是框的高度\unitlength
(pt
默认值)。
(致谢大卫·卡莱尔)
答案4
Gonzalo Medina 的答案是给出的问题的实际答案,但这里还有另一种选择:除了使用,\fbox
您还可以包裹mdframed
在基本用法中
\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}
制作一个漂亮的盒子:
但还让你可以根据自己的意愿变得花哨:
笔记:
- 这里使用的样式与文档中的一个示例仅略有不同,但我相信您可以选择更好的颜色。这只是为了说明一些选项,但还有许多其他选项。
代码:
\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}