# How to avoid change of textsize when using underbrace?

I'd like to use underbrace in a formula:

\begin{IEEEeqnarray}{r/C/l?s}
P_{a} \left( a | \gamma, \epsilon, \hat{K} \right)
& = & \frac{1}{1 + \frac{\gamma}{\epsilon} \times
\underbrace{
\frac{\alpha_{X} \left( p_{f} | \hat{K} \right)} {\alpha_{Y} \left( a | \hat{S} \right)}
}_{\Gamma \left( a | \hat{K} \right)}
}
& \IEEEnonumber
\end{IEEEeqnarray}


Compared to the formula without underbrace, the the underbraced part is enlarged:

\begin{IEEEeqnarray}{r/C/l?s}
P_{a} \left( a | \gamma, \epsilon, \hat{K} \right)
& = & \frac{1}{1 + \frac{\gamma}{\epsilon} \times
% \underbrace{
\frac{\alpha_{X} \left( p_{f} | \hat{K} \right)} {\alpha_{Y} \left( a | \hat{S} \right)}
% }_{\Gamma \left( a | \hat{K} \right)}
}
& \IEEEnonumber
\end{IEEEeqnarray}


How can I avoid the change of the font-size when underbracing parts of a formula?

Add \textstyle inside \underbrace; better, define a new command.

\documentclass{article}
\usepackage{IEEEtrantools}
\newcommand{\tunderbrace}[1]{\underbrace{\textstyle#1}}

\begin{document}
\begin{IEEEeqnarray}{r/C/l?s}
P_{a} ( a | \gamma, \epsilon, \hat{K} )
& = & \frac{1}{1 + \frac{\gamma}{\epsilon} \times
\tunderbrace{
\frac{\alpha_{X} ( p_{f} | \hat{K} )} {\alpha_{Y} ( a | \hat{S} )}
}_{\Gamma ( a | \hat{K} )}
}
& \IEEEnonumber
\end{IEEEeqnarray}
\end{document}


By the way, you should have discovered why using indiscriminately \left and \right is wrong.

You probably also want to use \mid instead of |:

\documentclass{article}
\usepackage{IEEEtrantools}
\newcommand{\tunderbrace}[1]{\underbrace{\textstyle#1}}

\begin{document}
\begin{IEEEeqnarray}{r/C/l?s}
P_{a} ( a \mid \gamma, \epsilon, \hat{K} )
& = & \frac{1}{1 + \frac{\gamma}{\epsilon} \times
\tunderbrace{
\frac{\alpha_{X} ( p_{f} \mid \hat{K} )} {\alpha_{Y} ( a \mid \hat{S} )}
}_{\Gamma ( a \mid \hat{K} )}
}
& \IEEEnonumber
\end{IEEEeqnarray}
\end{document}


• I would use a different name for \mid. This looks like conditional propability, i.e. \let\mid\given would make more sense as a first approx, i.e. P_a(a \given y,\epsilon,\hat{K}) it makes a lot more sense when reading the than using \mid. And as a second approx I'd use a macro that allowed \given to grow along the outer fences. – daleif Jan 20 '14 at 16:11
• @daleif OFFTOPIC! I usually prefer \newcommand\given{\,|\,} because in that context the large spacing around \mid doesn't look good, IMHO. – Manuel Jan 20 '14 at 16:12
• @Manuel, I do the same thing, but I tend to use \: not, \,, but that is a personal preference. Though, since \given can be used in many different contexts, I have a definition for each, such that the macro that gives the outer fences redefines \given, then e.g. a \Set{a\in A \given a^2>0} does not need to have the same symbol as used in a conditional propability. – daleif Jan 20 '14 at 16:20

The following example is based on egreg's solution (last example with \mid). It defines \KeepStyleUnderBrace that also works for the other math styles automatically:

\documentclass{article}
\usepackage{IEEEtrantools}

\newcommand*{\KeepStyleUnderBrace}[1]{%
\mathop{%
\mathchoice
{\underbrace{\displaystyle#1}}%
{\underbrace{\textstyle#1}}%
{\underbrace{\scriptstyle#1}}%
{\underbrace{\scriptscriptstyle#1}}%
}\limits
}

\begin{document}
\begin{IEEEeqnarray}{r/C/l?s}
P_{a} ( a \mid \gamma, \epsilon, \hat{K} )
& = &
\frac{1}{1 + \frac{\gamma}{\epsilon} \times
\KeepStyleUnderBrace{
\frac{\alpha_{X} ( p_{f} \mid \hat{K} )}
{\alpha_{Y} ( a \mid \hat{S} )}
}_{\Gamma ( a \mid \hat{K} )}
}
& \IEEEnonumber
\end{IEEEeqnarray}
\end{document}


• This is a great kludge. IMHO this should be the default behaviour of \underbrace. – ScumCoder Sep 30 '16 at 13:19