等式下的文本

等式下的文本

我正在尝试实现可以​​从这张图片中最好地描述的目标:

绿色的东西

我希望能够在我的等式下写下绿色文本和线条(实际上它就是这个等式),但我该怎么做呢?我目前所拥有的只有:

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

答案1

只是为了好玩(这可能不是最佳方式):

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

在此处输入图片描述

答案2

明智的颜色变化解决了这个问题,同时给出了一些“文本分数”的定义:

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

在此处输入图片描述

相关内容