\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?
\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?
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.
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}
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.
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?.
\lineskip=10pt in the preamble.
– egreg
Sep 23 '18 at 23:04
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}
\underline? – pluton Jun 22 '22 at 12:49