1

I'm quite new to LaTeX and struggling with the alignment in math mode. Is there any way to nicely align the bar in my equation:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

We denote by
\begin{equation}
    \text{OOB-MSE} = \frac{1}{n}\sum_{i=1}^{n}(y_i - \bar{\widehat{y}}_{i \: \text{OOB}})^2,
\end{equation}
the so-called out-of-bag mean square error, where $\overline{\widehat{y}}_{i \: \text{OOB}}$ is the averaged... 

\end{document}

I also tried the command from another similar question (Aligning issue with overline) but it's much smaller than the overline bar and still not really aligned..

\newcommand{\myol}[2][3]{{}\mkern#1mu\overline{\mkern-#1mu#2}}

Thanks!

The first bar in the picture uses the \bar command and the second uses the \overline command. Both aren't nicely aligned. Above is the usual \bar command and below the \overline command

4
  • It might be a good idea to add an image as well
    – daleif
    Commented Jun 4, 2021 at 12:41
  • 1
    I get a much better result with \bar{\hat{y}}
    – egreg
    Commented Jun 4, 2021 at 12:42
  • I don't like just the \hat command, I find it too narrow... Commented Jun 4, 2021 at 12:46
  • 1
    @cactus_splines: the mathabx package defines \widebar.
    – Bernard
    Commented Jun 4, 2021 at 13:15

1 Answer 1

0

Here I write my proposal using accents package. I have used this trick

\accentset{\mkern2.55mu\_}{\widehat{y}}

to have the bar and centering the widehat. Of course you can create a macro, but the advice that if you change the letter y for example you must change the value of \mkern2.55mu.

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{accents}
\begin{document}

We denote by
\begin{equation}
    \textup{OOB-MSE} = \frac{1}{n}\sum_{i=1}^{n}(y_i - \accentset{\mkern2.55mu\_}{\widehat{y}}_{i \: \textup{OOB}})^2,
\end{equation}
the so-called out-of-bag mean square error, where $\accentset{\mkern2.55mu\_}{\widehat{y}}_{i \: \textup{OOB}}$ is the averaged... 

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .