I want to represent, say, the closure of a set or the extended reals, e.g., $\bar{\mathbb{R}}$ but unfortunately this creates a bar that is much too small (horizontally) and can barely be seen. On the other hand, $\overline{\mathbb{R}}$ creates a line that is too long. I need something that's just right, in between the bar and the overline. What would be my best choice?


Here is a command \xoverline[width percent]{symb} that will do it. Note that it will not scale inside sub or superscripts. If you need that, everthing has to go through a \mathchoice resulting in a lot more complex code.


    \setbox\myboxB\null% Phantom box
    \wd\myboxB=#1\wd\myboxA% Scale phantom
    \sbox\myboxB{$\m@th\overline{\copy\myboxB}$}%  Overlined phantom
    \setlength\mylenA{\the\wd\myboxA}%   calc width diff
       \rlap{\hskip 0.5\mylenA\usebox\myboxB}{\usebox\myboxA}%
        \hskip -0.5\mylenA\rlap{\usebox\myboxA}{\hskip 0.5\mylenA\usebox\myboxB}%





enter image description here

  • 20
    Someone should do the \mathchoice thing and package this into a package! Jun 27 '14 at 5:38
  • I think there is bug with \xoverline if using this in math mode, cuz the font in math mode is oblique.
    – Lucas
    Nov 17 '21 at 15:43

I usually define a command \overbar, which reduced the width of \overline by 1.5mu on each side.



\newcommand{\overbar}[1]{\mkern 1.5mu\overline{\mkern-1.5mu#1\mkern-1.5mu}\mkern 1.5mu}

$\bar{\mathbb{R}}$ $\overbar{\mathbb{R}}$ $\overline{\mathbb{R}}$


  • 1
    Would this solution have the same issues regarding subscripts/superscripts as described in Danie's solution? Jan 24 '16 at 21:48
  • 1
    @Anthony I believe not, it doesn’t go out of math mode and thus stays in the style it was invoked in. Aug 1 '16 at 21:33
  • Great command, makes the bar look identical to an excerpt from Understanding Analysis by Stephen Abbott (although \overline might still be a good alternative). Oct 12 '17 at 20:26

I need a bit shorter overlines for variables in boolean algebra to make clear that variables are separately inverted. I defined the following command:

\newcommand{\olsi}[1]{\,\overline{\!{#1}}} % overline short italic

It is special designed for variables that are typeset in italic, so it is not only above but rather above right. So upright characters need a different definition:

\newcommand{\ols}[1]{\mskip.5\thinmuskip\overline{\mskip-.5\thinmuskip {#1} \mskip-.5\thinmuskip}\mskip.5\thinmuskip} % overline short

Similar definitions for underlines:

\newcommand{\ulsi}[1]{\!\overline{\,{#1}}} % underline short italic
\newcommand{\uls}[1]{\mskip.5\thinmuskip\underline{\mskip-.5\thinmuskip {#1} \mskip-.5\thinmuskip}\mskip.5\thinmuskip} % underline short


$ \olsi{x+y} = \olsi{x}\olsi{y} $

is rendered as

enter image description here

I hope that helps.


It took me a while to get a command that puts a nice overline over any field name, independent if its the reals, rationals, a finite field, or just a single literal. Based on this and that, I wrote the command \closure that uses \olsi for the overline if the argument is just a single literal, and \ols otherwise. The following table gives a comparison of these commands.


As a small bonus it also does not require any additional packages to be loaded.



%command for alg-closure that automatically adapts its 'bar' to the arg based on the args length (including '\')
\newcommand{\ols}[1]{\mskip.5\thinmuskip\overline{\mskip-.5\thinmuskip {#1} \mskip-.5\thinmuskip}\mskip.5\thinmuskip} % overline short
\newcommand{\olsi}[1]{\,\overline{\!{#1}}} % overline short italic
  \tctestifnum{\count@stringtoks{#1}>1} %checks if number of chars in arg > 1 (including '\')
  {\ols{#1}} %if arg is longer than just one char, e.g. \mathbb{Q}, \mathbb{F},...
  {\olsi{#1}} %if arg is just one char, e.g. K, L,...


  \texttt{\textbackslash overline} & $\overline{\mathbb{R}}$ & $\overline{\mathbb{Q}}$ & $\overline{\mathbb{F}_p}$ & $\overline{K}$ & $\overline{L}$ & $\overline{L_1}$ & $\mathcal{Z}_{\overline{K}}$\\
  \texttt{\textbackslash bar} & $\bar{\mathbb{R}}$ & $\bar{\mathbb{Q}}$ & $\bar{\mathbb{F}_p}$ & $\bar{K}$ & $\bar{L}$ & $\bar{L_1}$ & $\mathcal{Z}_{\bar{K}}$\\[4pt]
  \texttt{\textbackslash ols} & $\ols{\mathbb{R}}$ & $\ols{\mathbb{Q}}$ & $\ols{\mathbb{F}_p}$ & $\ols{K}$ & $\ols{L}$ & $\ols{L_1}$ & $\mathcal{Z}_{\ols{K}}$\\
  \texttt{\textbackslash olsi} & $\olsi{\mathbb{R}}$ & $\olsi{\mathbb{Q}}$ & $\olsi{\mathbb{F}_p}$ & $\olsi{K}$ & $\olsi{L}$ & $\olsi{L_1}$ & $\mathcal{Z}_{\olsi{K}}$\\[4pt]
  \texttt{\textbackslash closure} & $\closure{\mathbb{R}}$ & $\closure{\mathbb{Q}}$ & $\closure{\mathbb{F}_p}$ & $\closure{K}$ & $\closure{L}$ & $\closure{L_1}$ & $\mathcal{Z}_{\closure{K}}$\\


I'm not a Latex expert, but I've made a code that allows you to control the length and position of the top bar in another answer. Maybe that helps someone.

See the complete answer to see all the examples and drawbacks.

Here is its summary:

\mybar{<scale factor>}{<right shift>}{<math expression>}

First code

\usepackage{mathtools}  % <----- for '\mathrlap' command (necessary)


Example of use:


If you are planning to use this command more often for a specific mathematical expression, you can use the following code to make things cleaner.

\mybar[<scale factor>][<right shift>]{<math expression>}

Second code

\usepackage{mathtools}  % <----- for '\mathrlap' command (necessary)
\usepackage{xparse}     % <----- for '\NewDocumentCommand' command (necessary)

\NewDocumentCommand{\mybar}{ O{0.60} O{3pt} m }{%  <---- Set the default values here

Example of use:

$\mybar{V}$            % <---- bad result
$\mybar[0.6][2pt]{V}$  % <---- set manually

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.