我想在我的投影仪框架中排版方程式:
这是我的解决方案,当然,它看起来不太好。
我的代码是:
\[
\parbox[c][2cm]{2cm}{Attainable \\ GFlops/sec} = \min{\begin{cases}
\parbox[c][1cm]{3cm}{\small Peak Floating\-Point \\ Performance} \\
\hrulefill \\
\parbox[c][1cm]{2.5cm}{\small Peak Memory\\ Bandwidth }
\times
\parbox[c][1cm]{2.5cm}{\small Operational \\ Intensity} \end{cases}}
\]
问题:我该如何排版才能让它看起来像第一张图片?我使用\parbox
来打破操作数,但它们没有在中心对齐。我使用\small
,但等式的右操作数仍然与左操作数的大小相同。
答案1
摞起来!
\documentclass{beamer}
\usepackage[usestackEOL]{stackengine}
\def\stacktype{L}
\strutlongstacks{T}
\begin{document}
\begin{frame}
Here is the equation:\bigskip
{\rmfamily$\stackanchor{Attainable}{GFlops/sec} = \textit{min}
\left\{
\footnotesize\frac{
\stackanchor{Peak Floating-Point}{Performance}
}{
\stackanchor{Peak Memory}{Bandwidth} ~~\times~~
\stackanchor{Operational}{Intensity}
}
\right.
$}
\end{frame}
\end{document}
虽然它会产生相同的结果,但有些人可能更喜欢以下堆叠语法。它用 替换\stackanchor{...}{...}
。此外,它消除了对和 的\Centerstack{...\\...}
需求,因为 a始终是一个“长”支撑堆栈:\def\stacktype{L}
\strutlongstacks{T}
\Centerstack
\documentclass{beamer}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\begin{frame}
Here is the equation:\bigskip
{\rmfamily$\Centerstack{Attainable\\GFlops/sec} = \textit{min}
\left\{
\footnotesize\frac{
\Centerstack{Peak Floating-Point\\Performance}
}{
\Centerstack{Peak Memory\\Bandwidth} ~~\times~~
\Centerstack{Operational\\Intensity}
}
\right.
$}
\end{frame}
\end{document}
答案2
tabular
我自己尝试了一下,使用anddcases
环境和\frac
and运算符的组合\times
。我想尽可能多地使用算术运算符。也许这不是正确的策略,但我认为最终看起来并不那么糟糕。
编辑:@{}
在第一个环境的参数中添加tabular
,以抑制难看的额外空间。(想法取自 Gonzalo Medina 的回答。)
\documentclass{beamer}
\begin{document}
\begin{frame}
\[
\begin{tabular}{c@{}}Attainable\\ GFlops/sec\end{tabular}
= \min
\left\lbrace
\frac{
\begin{tabular}{c}
Peak Floating-Point\\ Performance
\end{tabular}
}
{
\begin{tabular}{c}
Peak Memory\\ Bandwidth
\end{tabular}
\times
\begin{tabular}{c}
Operational\\ Intensity
\end{tabular}
}
\right.
\]
\end{frame}
\end{document}
编辑(二):根据评论中 egreg 的评论,我用指令替换了dcases
环境\left\lbrace…\right.
,并删除了一些虚假\text
指令。这样代码就更简单了,新结果看起来与旧结果完全相同,但我还是上传了它。
答案3
另一种选择是使用tabular
和array
:
\documentclass{beamer}
\usepackage{booktabs}
\usepackage{array}
\begin{document}
\begin{frame}
{
\small
\[
\begin{tabular}{c@{}}
Attainable \\
GFlops/sec
\end{tabular}
= \min
\left\{
\begin{array}{@{}c@{}}
\begin{tabular}{@{}c@{}}
Peak Floating\-Point \\
Performance
\end{tabular} \\
\midrule
\begin{tabular}{@{}>{\centering\arraybackslash}p{2.2cm}@{}}
Peak Memory \\
Bandwidth
\end{tabular}
\times
\begin{tabular}{@{}>{\centering\arraybackslash}p{2cm}@{}}
Operational \\
Intensity
\end{tabular}
\end{array}
\right.
\]
}
\end{frame}
\end{document}
答案4
当然还有 TikZ。
代码
\documentclass{beamer}
\usepackage{amsmath}
\usepackage{tikz}
\newcommand\mybox[1]{
\tikz[baseline=-.5ex]
\node[align=center,execute at begin node=\setlength{\baselineskip}{2.5ex},text depth=.25ex]{#1};
}
\begin{document}
\begin{frame}
\[
\mybox{Attainable\\GFlops/sec}=\min
\begin{cases}
\frac{\mybox{Peak Floating Point\\Performance}}
{\mybox{Peak Memory\\Bandwidth}\times\mybox{Operational\\Intensity}}
\end{cases}
\]
\end{frame}
\end{document}