12

\overline{\overline{ABC}} produces a double bar over ABC, but it takes up too much vertical space.

How can I make the top bar closer to the bar below it?

3 Answers 3

7

You can easily vary the command \doverline defined below by changing the vertical offset (e.g. 0.5ex).

\documentclass{memoir}

\usepackage{amsmath,tikz}
\usetikzlibrary{calc}

\newcommand\doverline[1]{%
\tikz[baseline=(nodeAnchor.base)]{
    \node[inner sep=0] (nodeAnchor) {$#1$}; 
    \draw[line width=0.1ex,line cap=round] 
        ($(nodeAnchor.north west)+(0.0em,0.2ex)$) 
            --
        ($(nodeAnchor.north east)+(0.0em,0.2ex)$) 
        ($(nodeAnchor.north west)+(0.0em,0.5ex)$) 
            --
        ($(nodeAnchor.north east)+(0.0em,0.5ex)$) 
    ;
}}


\begin{document}
\noindent{}Officia quidem est accusamus labore architecto. Ullam hic corporis quod consectetur sequi quod eaque. 
Ducimus iste excepturi et cumque ut. Earum animi autem eum tempora.
.$\overline{\overline{1234567890}}$. 
Officia quidem est accusamus labore architecto. Ullam hic corporis quod consectetur sequi quod eaque. 
Ducimus iste excepturi et cumque ut. 
.$\doverline{1234567890}$. 
Earum animi autem eum tempora. Officia quidem est accusamus labore architecto. Ullam hic. 
\begin{align*}
        Z&=1234567890\\
        Z&=\overline{\overline{1234567890}}\\
        Z&=\doverline{1234567890}\\
        Z&={1234567890}
\end{align*}
\end{document}

Ti*k*Z is a mighty tool which allows those quick definitions without digging in to the core of TeX.

enter image description here


EDIT: egreg's solution is more concise when dealing with subscripts and superscripts. My solution could be adopted to this by using LuaTeX's access to \mathstyle but as his solutions already deals with this issue there is not really a need for it.

There is another solution on How to reduce the vertical space between two overlines?.

5
  • 1
    I am accepting this solution because it does not affect the document spacing (between lines of text). When I tried @egreg's solution, there were still gaps between lines of text created by the dbloverline. Commented Sep 23, 2018 at 15:35
  • 1
    @CampanIgnis The answer of mine you linked to does not address this. You may have been thinking of this answer? Commented Sep 23, 2018 at 22:41
  • @David The issue with document spacing cannot be avoided if you have too high objects in a line; a single overline is already near the limit. I don't think this solution avoids the issue.
    – egreg
    Commented Sep 23, 2018 at 22:52
  • @David Actually, in my test neither solution changes the spacing, at least with CampanIgnis example text. You can try by setting \lineskip=10pt in the preamble.
    – egreg
    Commented Sep 23, 2018 at 23:04
  • @egreg yes, it appears now you are correct that both change the vertical spacing. But in my document this solution causes less vertical skip (I'm not sure what the explanation could be). Commented Sep 23, 2018 at 23:35
12

The \overline operation inserts a kern three times \fontdimen8 of the math extension font (which is also used as the rule thickness).

We can so reduce this kerning by artificially making the inner overlined box less tall by twice the applied kerning.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\dbloverline}[1]{\overline{\dbl@overline{#1}}}
\newcommand{\dbl@overline}[1]{\mathpalette\dbl@@overline{#1}}
\newcommand{\dbl@@overline}[2]{%
  \begingroup
  \sbox\z@{$\m@th#1\overline{#2}$}%
  \ht\z@=\dimexpr\ht\z@-2\dbl@adjust{#1}\relax
  \box\z@
  \ifx#1\scriptstyle\kern-\scriptspace\else
  \ifx#1\scriptscriptstyle\kern-\scriptspace\fi\fi
  \endgroup
}
\newcommand{\dbl@adjust}[1]{%
  \fontdimen8
  \ifx#1\displaystyle\textfont\else
  \ifx#1\textstyle\textfont\else
  \ifx#1\scriptstyle\scriptfont\else
  \scriptscriptfont\fi\fi\fi 3
}
\makeatother

\begin{document}

$\overline{\overline{ABC}}$
$\dbloverline{ABC}$

$X_{\overline{\overline{ABC}\kern-\scriptspace}}$
$X_{\dbloverline{ABC}}$

\end{document}

I took the occasion for removing the \scriptspace which is added in subscripts/superscripts for the inner overline atom.

enter image description here

The same idea can be used for underlining, using the depth instead of the height. In the code I use \@@underline, because this is the saved \underline primitive.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
% overline
\newcommand{\dbloverline}[1]{\overline{\dbl@overline{#1}}}
\newcommand{\dbl@overline}[1]{\mathpalette\dbl@@overline{#1}}
\newcommand{\dbl@@overline}[2]{%
  \begingroup
  \sbox\z@{$\m@th#1\overline{#2}$}%
  \ht\z@=\dimexpr\ht\z@-2\dbl@adjust{#1}\relax
  \box\z@
  \ifx#1\scriptstyle\kern-\scriptspace\else
  \ifx#1\scriptscriptstyle\kern-\scriptspace\fi\fi
  \endgroup
}
% underline
\newcommand{\dblunderline}[1]{\@@underline{\dbl@underline{#1}}}
\newcommand{\dbl@underline}[1]{\mathpalette\dbl@@underline{#1}}
\newcommand{\dbl@@underline}[2]{%
  \begingroup
  \sbox\z@{$\m@th#1\@@underline{#2}$}%
  \dp\z@=\dimexpr\dp\z@-2\dbl@adjust{#1}\relax
  \box\z@
  \ifx#1\scriptstyle\kern-\scriptspace\else
  \ifx#1\scriptscriptstyle\kern-\scriptspace\fi\fi
  \endgroup
}
\newcommand{\dbl@adjust}[1]{%
  \fontdimen8
  \ifx#1\displaystyle\textfont\else
  \ifx#1\textstyle\textfont\else
  \ifx#1\scriptstyle\scriptfont\else
  \scriptscriptfont\fi\fi\fi 3
}
\makeatother

\begin{document}

\textbf{Double overline}

$\overline{\overline{ABC}}$
$\dbloverline{ABC}$

$X_{\overline{\overline{ABC}\kern-\scriptspace}}$
$X_{\dbloverline{ABC}}$

\bigskip

\textbf{Double underline}

$\underline{\underline{ABC}}$
$\dblunderline{ABC}$

$X_{\underline{\underline{ABC}\kern-\scriptspace}}$
$X_{\dblunderline{ABC}}$

\end{document}

enter image description here

3
  • Thanks. Would you have a similar strategy for \underline?
    – pluton
    Commented Jun 22, 2022 at 12:49
  • 1
    @pluton It was easy… :-)
    – egreg
    Commented Jun 22, 2022 at 13:28
  • Great! Thanks a lot!
    – pluton
    Commented Jun 22, 2022 at 13:37
6

Two other solutions: one with the \widebar command, borrowed from mathabx, another based on \overbracket, from mathtools:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\newcommand{\wideBar}[1]{\overbracket[0.3pt][0pt]{\overbracket[0.3pt][0pt]{\mkern-2.8mu #1}}}

\DeclareFontFamily{U}{mathx}{\hyphenchar\font45}
\DeclareFontShape{U}{mathx}{m}{n}{
<-6> mathx5 <6-7> mathx6 <7-8> mathx7
<8-9> mathx8 <9-10> mathx9
<10-12> mathx10 <12-> mathx12
}{}
\DeclareSymbolFont{mathx}{U}{mathx}{m}{n}
\DeclareFontSubstitution{U}{mathx}{m}{n}
\DeclareMathAccent{\widebar}{0}{mathx}{"73}

\begin{document}

\[ \widebar{\widebar{X}}\quad\widebar{\widebar{XYZ}} \]%

\[ \wideBar{X}\quad\wideBar{XYZ} \]%

\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 .