# How to format the case equation to look nicer?

I want to typeset the equation in my beamer frame:

This is my solution and of course, it doesn't look well.

And my code is :

$\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}}$


The question: How can I typeset it to make it looks like the first picture? I use \parbox to break the operand, but they isn't aligned at center. I use \small, but the right operands of the equation is still the same size of the left operand.

• The brace suggests a choice (the minimum) between two options while the line between these two options suggests a fraction: your formula is ambiguous. – Paul Gaborit Feb 5 '15 at 7:23
• @PaulGaborit：Yes. The line between them is used to distinguish the top and bottom (not necessary). If deleting the line, the right seems to be one equation. And this equation comes from the paper I read, so I just keep it same as the paper. – Yulong Ao Feb 5 '15 at 9:05
• Notice that 'min' should not be in italics, just as 'sin' shouldn't. – Andreas Rejbrand Feb 5 '15 at 17:58

Stack it!

\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}


While it produces the identical result, some may prefer the following stacking syntax. It replaces \stackanchor{...}{...} with \Centerstack{...\\...}. Also, it eliminates the need for \def\stacktype{L} and \strutlongstacks{T}, since a \Centerstack is always a "long", strutted stack:

\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}

• Usually, 'min' is not written in italics since it is an operator. – Karlo Jun 28 '16 at 16:41
• @Karlo I agree ($\min$ would be preferable), but the italic matches the stated desires of the OP, so I gave what was requested. – Steven B. Segletes Jun 29 '16 at 0:13

My own attempt, using a combination of tabular and dcases environments, and \frac and \times operators. I wanted to use as much arithmetic operators as possible. Maybe it wasn't the right tactic but in the end it doesn't look so bad, I think.

Edit: added @{} in argument of the first tabular environment, to suppress an ugly additional space. (Idea taken from Gonzalo Medina's answer.)

\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}


Edit (bis): following egreg's remarks in the comments, I've replaced the dcases environment by \left\lbrace…\right. instructions, and taken off some spurious \text instructions. Simpler code thus, and the new result seems exactly the same as the old one but I've uploaded it anyway.

• I'd use \left\lbrace instead of \begin{dcases} and \right. instead of \end{dcases}. Or no brace at all, but it's another matter. Why $\text{GFlops}/\text{sec}$ and not simply GFlops/sec? – egreg Feb 5 '15 at 7:50
• The \text{} commands are relics of previous attempts: I first wanted to remain in math mode (array environments) as much as possible. Indeed you're right, the \left…\right approach is better and simpler. I've modified my code accordingly. – Franck Pastor Feb 5 '15 at 9:54

Another option, using tabular and 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}


A varwidth option

\documentclass{article}
\usepackage{amsmath}
\usepackage{varwidth}
\begin{document}
$\begin{varwidth}{\linewidth} \centering Attainable \\ GFlops/sec \end{varwidth} =\min\begin{cases} \frac{ \begin{varwidth}{\linewidth} \small\centering Peak Floating Point \\ Performance \rule[-2pt]{0pt}{1pt} \end{varwidth} } { \begin{varwidth}{\linewidth} \small\centering Peak Memory\\ Bandwidth \end{varwidth} \,\, \times \,\, \begin{varwidth}{\linewidth} \small\centering \rule{0pt}{2ex} Operational \\ Intensity \end{varwidth} } \end{cases}$
\end{document}


And TikZ, of course.

# Code

\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}