5

I'm trying to achieve which can be best described from this picture:

green stuff

I want to be able to write the green text and line under my equation (it's exactly this equation actually) but how do I do that? All I have at the moment is:

\noindent read stall cycles = \(\displaystyle \frac{reads}{program}\ *\ read\ 
miss\ rate\ (\%)\ *\ read\ miss\ penalty\ (cycles)\)
Nubcake
  • 165

2 Answers2

6

Just for fun (this may not be the optimal way of doing this):

\documentclass[12pt]{article}
\pagestyle{plain}
\usepackage[margin=1.8cm]{geometry}
\geometry{a4paper}
\usepackage[parfill]{parskip}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[usenames]{color}
\definecolor{cyan}{rgb}{0,1,1}
\newcommand{\cyan}[1]{\textcolor{cyan}{#1}}
\definecolor{black}{rgb}{0,0,0}
\newcommand{\black}[1]{\textcolor{black}{#1}}

\begin{document}

\[
  \text{read stall cycles} =
  \cyan{\underbrace{\black{\frac{\text{reads}}{\text{program}}
        \times \parbox{48pt}{read miss \\ rate (\%)}}}_{\text{read
        miss per program}}} \times
  \cyan{\underbrace{\black{\parbox{76pt}{read miss \\ penalty
          (cycle)}}}_{\parbox{62pt}{\scriptsize\centering number of cycles \\
        per read miss}}}
\]

\end{document}

enter image description here

Au101
  • 10,278
1

Judicious color changing solves the problem, together with some definitions for “textual fractions”:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}

\definecolor{underbrace}{RGB}{30,199,166}

\newcommand{\textfrac}[1]{%
  \begin{tabular}{@{}l@{}}#1\end{tabular}%
}

\begin{document}
\[
\colorlet{currentcolor}{.}
\text{read stall cycles}=
  \textcolor{underbrace}{%
    {\underbrace{%
       \textcolor{currentcolor}{%
         \textfrac{reads\\\hline program}
         \times
         \textfrac{read miss\\[\arrayrulewidth]rate (\%)}
       }
     }_{\text{read miss per program}}
    }
  }
  \times
  \textcolor{underbrace}{%
    {\underbrace{%
       \textcolor{currentcolor}{%
         \textfrac{read miss\\[\arrayrulewidth]penalty (cycle)}
       }
     }_{\substack{\text{number of cycles}\\\text{per read miss}}}
    }
  }
\]

\end{document}

enter image description here

egreg
  • 1,121,712