Monday, November 3, 2008

\bar vs. \overline

Another quick post, this time about math. In particular about the \bar option. As many Latex users are aware, the \bar option is used to put a line over a letter/number in math mode, usually representing a mean. The problem with this method is that it puts a fixed-width bar over the letter (I think it's an underscore character '_') instead of covering the width of the letter(s).

This can be easily overcome with the overline option.

overline: \overline
usage: \overline{test}
Explanation: The overline option should be used instead of bar option.

The following code demonstrates the difference

\documentclass[12pt]{beamer}
\mode{
\usetheme{Boadilla}
}
\begin{document}
\begin{frame}[plain]
\begin{alertblock}{WRONG}
\begin{align*}
Z& = \frac{\bar{BMI}-\mu}{\sqrt{\frac{\sigma^2}{N}}} \\
& = \frac{\bar{BMI}-\mu}{SE(\bar{BMI})} \\
\end{align*}
\end{alertblock}
\begin{exampleblock}{RIGHT}
\begin{align*}

Z& = \frac{\overline{BMI}-\mu}{\sqrt{\frac{\sigma^2}{N}}} \\
& = \frac{\overline{BMI}-\mu}{SE(\overline{BMI})} \\
\end{align*}
\end{exampleblock}
\end{frame}
\end{document}

Which produces the following slide

29 comments:

  1. Thanks, this was exactly what I was looking for. Keep it up!

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. Thanks so much. I really needed this for my thesis.

    ReplyDelete
  4. Thanks! Just what the doctor ordered.

    ReplyDelete
  5. Thank you!! My thesis was looking weird until I found this.

    ReplyDelete
  6. Thank you, though if you have an index to the letter than the overline, there is a white space between the letter and its index and it looks horrible.

    \documentclass[12pt]{beamer}
    \begin{document}

    $\overline{V}_\textrm{p}$ instead of $\bar{V}_\textrm{p}$

    \end{document}

    Does anyone knows how to avoid the space between the V and p?

    Thanks

    ReplyDelete
  7. You can put whatever you want in the argument to the overline command, so to put the overline above a number and its subscript, you do:

    $\overline{V_\textrm{p}}$

    ReplyDelete
  8. You can also eliminate the space without having the overline cover both the symbol and its subscript by inserting a negative space (\!) between them:

    $\overline{V}\!_\textrm{p}$

    ReplyDelete
    Replies
    1. Thank you Kbolino, that's exactly what I was looking for.

      Delete
  9. That made my notes look nicer, and also lead me to try underline, which is what I wanted elsewhere. Thanks!

    ReplyDelete
  10. Thanks, nice tip!

    ReplyDelete
  11. Thank you for helping me write my paper!

    ReplyDelete
  12. Thanks! It saved the beauty of my thesis!

    ReplyDelete
  13. Very helpful, thanks!

    ReplyDelete
  14. I would say this is correct if you have a variable with several letters (eg. BMI in the example). But if you have a variable with a single letter (eg. x), then \bar is better than \overline.

    ReplyDelete
  15. Thanks man, thesis on course too

    ReplyDelete
  16. Thanks, this helped fix my thesis!

    ReplyDelete
  17. Sometimes the overline is too wide. Is there a command in-between \bar and \overline?

    ReplyDelete
    Replies
    1. Yes, but you have to define it yourself.
      https://tex.stackexchange.com/questions/22100/the-bar-and-overline-commands

      Delete
    2. This comment has been removed by the author.

      Delete
    3. This comment has been removed by the author.

      Delete