Math & Sciencehat position over underlined letter

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Montag
Posts: 340
Joined: Wed Jul 15, 2009 9:25 am

hat position over underlined letter

Post by Montag »

Hello,
is it possible to align the hat (made with \hat) above y like it is (centered) over the x? Is this possible using a global option/adjustment?
Unbenannt.JPG
Unbenannt.JPG (14.88 KiB) Viewed 42005 times
Last edited by Montag on Wed Mar 02, 2011 11:43 am, edited 1 time in total.
OS: Win 7 64-bit LaTeX: MikTeX 2.9 64-bit Editor: TXC 1 RC1

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Frits
Posts: 169
Joined: Wed Feb 02, 2011 6:02 pm

hat position over underlined letter

Post by Frits »

I'm not sure if this is going to solve your problem, since you didn't give a Minimal Working Example.

My guess is that the line underneath the 'y' is done with \underline{y}. Then your code probably looked like:

Code: Select all

\hat{\underline{y}}
Now this goes wrong: LaTeX centers the hat automatically above its argument. The argument here is \underline{y}, where the underline is wider than the y.
Solution: center it above the y and then define the underlining:

Code: Select all

\underline{\hat{y}}
howtoTeX.com - Your LaTeX resource site (Tips, Tricks, Templates and more!)
Follow howtoTeX on twitter
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

hat position over underlined letter

Post by localghost »

Montag wrote:[…] is it possible to align the hat (made with \hat) above y like it is (centered) over the x? Is this possible using a global option/adjustment?
With respect to the line underneath both characters, the hat is centred. It optically looks like it's not because the »y« appears more slanted (we know it isn't). What you want is to shift it according to your personal thus subjective feeling. And this feeling seems to depend on the used font (keyword MWE). With the standard CM it looks OK. Nevertheless you can define a new command that does this job.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\newcommand*{\xhat}[1]{#1\kern-0.35em\hat{\phantom{#1}}}

\begin{document}
$\hat{y}\xhat{y}$
\end{document}

Thorsten
Montag
Posts: 340
Joined: Wed Jul 15, 2009 9:25 am

Re: hat position over underlined letter

Post by Montag »

Thank you both.
Frits' suggestion seems to work fine.
The new command by you (Thorsten) seems to be a little bit shifted to the right, either I underline first and the put that hat on it or vice versa. But then, I am next to not familiar with kerning properties/options of characters at all.
OS: Win 7 64-bit LaTeX: MikTeX 2.9 64-bit Editor: TXC 1 RC1
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

hat position over underlined letter

Post by localghost »

Montag wrote:[…] But then, I am next to not familiar with kerning properties/options of characters at all.
You should be able to adjust \kern-0.35em according to your needs. It simply stands for some negative space. Just play around with it. Valid length units like »em« or »ex« should be familiar to you.
Montag
Posts: 340
Joined: Wed Jul 15, 2009 9:25 am

hat position over underlined letter

Post by Montag »

localghost wrote:
Montag wrote:[…] But then, I am next to not familiar with kerning properties/options of characters at all.
You should be able to adjust \kern-0.35em to your needs. It simply stands for some negative space. Just play around with it. Valid length units like »em« or »ex« should be familiar to you.
Ok, thank you ... now I got it, I think. The em value "was" (-> is) directly connected to the font metrics, thus font-dependent and that's why the spacing command you posted has to be changed.
OS: Win 7 64-bit LaTeX: MikTeX 2.9 64-bit Editor: TXC 1 RC1
Post Reply