Wrap text for words under equation

equationsmath-mode

I did this

   \begin{equation}

     Error(x) = \underbrace{ \left(E\left[\mathbb{E}\hat{f(x)}\right] - f(x)\right)^2}_\text{Bias^2; how much the predicted values differ from true values} \ \ +  \ \underbrace{\mathbb{E}\left[\hat{f}(x) - \mathbb{E}\left[\hat{f}(x)\right]\right]^2 }_\text{Variance; how the predictions made on the same value vary on different iterations of the model}

\end{equation}

But for the text looks whacky and does not wrap around. Not sure why this is not compiling anyways here is screen shot

enter image description here

Best Answer

You could put the text in \parbox-es, though you have to specify their width (adjust to taste). There are ways of getting the precise width, but I think this is close enough for most purposes:


\documentclass[12pt]{article}

\usepackage{amsmath,amssymb}

\begin{document}

\begin{equation}
     \mathrm{Error}(x) = \underbrace{ \left(E\left[\mathbb{E}\hat{f}(x)\right] - f(x)\right)^2}_{\parbox{1.5in}{\centering Bias$^2$; how much the predicted values differ from true values}} \ \ +  \ \underbrace{\mathbb{E}\left[\hat{f}(x) - \mathbb{E}\left[\hat{f}(x)\right]\right]^2 }_{\parbox{1.5in}{\centering Variance; how the predictions made on the same value vary on different iterations of the model}}
\end{equation}

\end{document}

parbox example

Related Question