Is it possible to produce a hat symbol for a capital letter, between
Code: Select all
$\hat{M}$ and $\widehat{M}
Thank you.
Code: Select all
$\hat{M}$ and $\widehat{M}
Code: Select all
\documentclass{article}
\newlength\hwhatcwidth% half wide hat's contents width
\newlength\hwhatuwidth% half wide hat's contents width with contents upright
\newcommand*\halfwidehat[1]{%
\settowidth\hwhatcwidth{\ensuremath{#1}}%
\settowidth\hwhatuwidth{\ensuremath{\mathrm{#1}}}%
\addtolength\hwhatuwidth{-\hwhatcwidth}% now difference between upright/real
% since the real width is usually wider for standard math italics font, this will be negative
\makebox[0pt][l]{% overprint its contents with what follows after its closing brace
\kern\dimexpr0.25\hwhatcwidth-0.667\hwhatuwidth\relax% left offset for shortened \widehat
\ensuremath{\widehat{\vphantom{#1}\rule{0.5\hwhatcwidth}{0pt}}}% put a \widehat over nothing
% this `nothing' is as high as the string to be put underneath (\vphantom{#1), but only half as wide
}#1% overprint \makebox with given string
}%\halfwidehat{string}
\begin{document}
$\hat{M}$ and $\widehat{M}$
perhaps\ $\halfwidehat{M}$
$\halfwidehat{ABC}$
\end{document}
\halfwidehat
on strings wider than 3 characters, otherwise parts of the string will drop out of the hat Code: Select all
\usepackage{lmodern} %don't know if it is necessary
\newcommand{\wh}{\widehat}
Code: Select all
\wh{} instead of \hat{} or \widehar{}
Code: Select all
\newcommand{\wh}{\widehat}