In math mode, the slanted characters look somewhat disconnected from an \overline:
$\overline{P}$ looks odd; of course I would like the bar to be aligned more on the right, at least as much slanted as the top of the letter. How can this be achieved?
- 7,206
- 241
3 Answers
The following is taken from a recent discussion in chat.
For most cases, the following definition of a modified \overline, called \myol, works:
\newcommand{\myol}[2][3]{{}\mkern#1mu\overline{\mkern-#1mu#2}}
where the default adjustment to the \overline is 3mu (click the image to enlarge for higher detail):
\documentclass{article}
\newcommand{\myol}[2][3]{{}\mkern#1mu\overline{\mkern-#1mu#2}}
\begin{document}
\[\begin{array}{c}
\overline{A}\ \overline{B}\ \overline{C}\ \overline{D} \overline{E}\ \overline{F}\ \overline{G}\ \overline{H} \overline{I}\ \overline{J}\ \overline{K}\ \overline{L} \overline{M}\ \overline{N}\ \overline{O}\ \overline{P} \overline{Q}\ \overline{R}\ \overline{S}\ \overline{T} \overline{U}\ \overline{V}\ \overline{W}\ \overline{X} \overline{Y}\ \overline{Z}\\[\jot]
\myol{A}\ \myol{B}\ \myol{C}\ \myol{D} \myol{E}\ \myol{F}\ \myol{G}\ \myol{H} \myol{I}\ \myol{J}\ \myol{K}\ \myol{L} \myol{M}\ \myol{N}\ \myol{O}\ \myol{P} \myol{Q}\ \myol{R}\ \myol{S}\ \myol[1]{T} \myol{U}\ \myol[1]{V}\ \myol[1]{W}\ \myol{X} \myol[1]{Y}\ \myol{Z}
\end{array}\]
\end{document}
Note that \myol requires some adjustment for letters that are top-heavy and bottom-narrow (T, V, W and Y in my example above).
- 603,163
Here is an automated macro. It is inspired from the TeXBook, page 375, and from the \skew defined by the LaTeX2e kernel. I was annoyed at going in and out of math mode, but this way, the macro \skoverline allows some more general material to be intermixed with the letters in its argument.
\documentclass{article}
\newbox\usefulbox
\makeatletter
\def\getslant #1{\strip@pt\fontdimen1 #1}
\def\skoverline #1{\mathchoice
{{\setbox\usefulbox=\hbox{$\m@th\displaystyle #1$}%
\dimen@ \getslant\the\textfont\symletters \ht\usefulbox
\divide\dimen@ \tw@
\kern\dimen@
\overline{\kern-\dimen@ \box\usefulbox\kern\dimen@ }\kern-\dimen@ }}
{{\setbox\usefulbox=\hbox{$\m@th\textstyle #1$}%
\dimen@ \getslant\the\textfont\symletters \ht\usefulbox
\divide\dimen@ \tw@
\kern\dimen@
\overline{\kern-\dimen@ \box\usefulbox\kern\dimen@ }\kern-\dimen@ }}
{{\setbox\usefulbox=\hbox{$\m@th\scriptstyle #1$}%
\dimen@ \getslant\the\scriptfont\symletters \ht\usefulbox
\divide\dimen@ \tw@
\kern\dimen@
\overline{\kern-\dimen@ \box\usefulbox\kern\dimen@ }\kern-\dimen@ }}
{{\setbox\usefulbox=\hbox{$\m@th\scriptscriptstyle #1$}%
\dimen@ \getslant\the\scriptscriptfont\symletters \ht\usefulbox
\divide\dimen@ \tw@
\kern\dimen@
\overline{\kern-\dimen@ \box\usefulbox\kern\dimen@ }\kern-\dimen@ }}%
{}}
\makeatother
\begin{document}\thispagestyle{empty}
$\overline{P}$
$\skoverline{P}$
$x^{\overline{M}}$
$x^{\skoverline{M}}$
$\overline{SPQR}$
$\skoverline{SPQR}$
\end{document}

Code stolen from Werner's answer:
\[\begin{array}{c}
\overline{A}\ \overline{B}\ \overline{C}\ \overline{D} \overline{E}\ \overline{F}\ \overline{G}\ \overline{H} \overline{I}\ \overline{J}\ \overline{K}\ \overline{L} \overline{M}\ \overline{N}\ \overline{O}\ \overline{P} \overline{Q}\ \overline{R}\ \overline{S}\ \overline{T} \overline{U}\ \overline{V}\ \overline{W}\ \overline{X} \overline{Y}\ \overline{Z}\\[\jot]
\skoverline{A}\ \skoverline{B}\ \skoverline{C}\ \skoverline{D} \skoverline{E}\ \skoverline{F}\ \skoverline{G}\ \skoverline{H} \skoverline{I}\ \skoverline{J}\ \skoverline{K}\ \skoverline{L} \skoverline{M}\ \skoverline{N}\ \skoverline{O}\ \skoverline{P} \skoverline{Q}\ \skoverline{R}\ \skoverline{S}\ \skoverline{T} \skoverline{U}\ \skoverline{V}\ \skoverline{W}\ \skoverline{X} \skoverline{Y}\ \skoverline{Z}
\end{array}\]

I quite like user4686's definition of skoverline, but I find LaTeX2e code a bit hard to read / understand / modify. As such I tried my hand at porting the code to LaTeX3. To my knowledge, the following code should produce the exact same results (that is an overline kerned by half the current font's slant "width").
% -- skoverline (ported from https://tex.stackexchange.com/a/95079/114489 CC-BY-SA 3.0) --
% Gets the slant per pt of the height of a character in a given font.
% Returns a dimensionless value which can be multiplied with a height in pt.
\cs_new:Nn __skoverline_get_slant_per_pt_of_height:n { \dim_to_decimal:n { \fontdimen1 #1 } }
% Typesets an overline kerned by a given amount for a given box.
%
% Usage: __skoverline_kerned_overline:NN <kern dim> <content box>
\cs_new:Nn __skoverline_kerned_overline:NN
{
% Start drawing overline after half the slant width.
\kern #1
\overline
{
% Move back half the slant width.
\kern -#1
% Insert the box containing the content.
\box_use_drop:N #2
% Move half the slant width forward again.
\kern #1
}
% Move half the slant width back once more, after finishing the overline.
\kern -#1
}
\NewDocumentCommand \skoverline { m }
{
\mathchoice
{{ % display style math
% Typeset #1 in hbox and store in variable for measuring and later use.
\hbox_set:Nn \l_tmpa_box { $\dim_zero:N \mathsurround \displaystyle #1$ }
% Get the slant width for the hbox's height.
% (note: in a dimension expression, writing values next to each other is multiplication)
%
% |←→|____
% | / /
% | / /
% |/___/
\dim_set:Nn \l_tmpa_dim
{
__skoverline_get_slant_per_pt_of_height:n { \textfont\symletters }
\box_ht:N \l_tmpa_box
}
% Use only half the slant width.
\dim_set:Nn \l_tmpa_dim { \l_tmpa_dim / 2 }
% This results in the overline being above the slanted character's
% horizontal at half it's height.
%
% |←-→|
% ____
% / /
% / /
% /___/
\__skoverline_kerned_overline:NN \l_tmpa_dim \l_tmpa_box
}}
{{ % text style math
\hbox_set:Nn \l_tmpa_box { $\dim_zero:N \mathsurround \textstyle #1$ }
\dim_set:Nn \l_tmpa_dim
{
\__skoverline_get_slant_per_pt_of_height:n { \textfont\symletters }
\box_ht:N \l_tmpa_box
}
\dim_set:Nn \l_tmpa_dim { \l_tmpa_dim / 2 }
\__skoverline_kerned_overline:NN \l_tmpa_dim \l_tmpa_box
}}
{{ % script style math
\hbox_set:Nn \l_tmpa_box { $\dim_zero:N \mathsurround \scriptstyle #1$ }
\dim_set:Nn \l_tmpa_dim
{
\__skoverline_get_slant_per_pt_of_height:n { \scriptfont\symletters }
\box_ht:N \l_tmpa_box
}
\dim_set:Nn \l_tmpa_dim { \l_tmpa_dim / 2 }
\__skoverline_kerned_overline:NN \l_tmpa_dim \l_tmpa_box
}}
{{ % script script style math
\hbox_set:Nn \l_tmpa_box { $\dim_zero:N \mathsurround \scriptscriptstyle #1$ }
\dim_set:Nn \l_tmpa_dim
{
\__skoverline_get_slant_per_pt_of_height:n { \scriptscriptfont\symletters }
\box_ht:N \l_tmpa_box
}
\dim_set:Nn \l_tmpa_dim { \l_tmpa_dim / 2 }
\__skoverline_kerned_overline:NN \l_tmpa_dim \l_tmpa_box
}}
}
And as a demonstration to show that it still works this way,
the same code from https://tex.stackexchange.com/a/95084/4686 typeset with this implementation
(using the standalone class, fontspec and unicode-math):

Note: I'm still not all that experienced in writing LaTeX macros that actually typeset stuff "manually", and my understanding of LaTeX2e macros is limited. Should any LaTeX guru have some tips or corrections for me, I'd be grateful for a comment mentioning those. ^^
- 31

beamerbut can give you an insight why this is not so trivial if you don't want to adjust manually. – percusse Jan 23 '13 at 15:13skewworks fine! However I'm working with standard fonts and no beamer, so from my understanding the problem should not arise and accents be skewed automatically, how comes it is not so? I only have amsmath, amssymb and other non-interfering packages... Feel free to make this an answer, btw. – Quartz Jan 23 '13 at 16:13