LaTeX forum ⇒ Text FormattingDouble hat looks ugly Topic is solved

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
nextdrinkplease
Posts: 3
Joined: Fri Jan 14, 2011 7:52 pm

Double hat looks ugly

Postby nextdrinkplease » Fri Jan 14, 2011 8:07 pm

Dear friends,

I have a LaTeX question for your amusement. :D

In maths mode, I want to have a symbol with two hats over it. I have obviously tried using (e.g.) $\hat{\hat{U}}$ but this looks rather ugly: the vertical separation between the two hats is too wide :shock: .

Any clever idea on the topic? I am a bit desperate because I tried everything I could think of...

Any help is greatly appreciated,
Cheers
Next



For your information: I am using the document class "elsarticle.cls" and I have a fairly recent version of TeXLive (running on Mac OS X 10.5.8).
Last edited by cgnieder on Fri Oct 19, 2012 11:59 pm, edited 1 time in total.

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net
LaTeX Beginner's Guide LaTeX Cookbook
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Double hat looks ugly  Topic is solved

Postby frabjous » Fri Jan 14, 2011 11:36 pm

Best I could come up with is the following:

\documentclass{article}
\usepackage{amsmath}
\usepackage{accents}
\begin{document}

$\hat{\vphantom{\rule{1pt}{5.5pt}}\smash{\hat{x}}}$
\end{document}




The smash makes it ignore the height of the inner x with a hat. Instead, it uses the vertical height of the "phantom" rule which isn't printed, so you can change how heigh the outer hat does by changing the second parameter to the \rule command. Adjust to taste.

(Note, you probably need the accents package for this to work at all, though I'm not sure why.)

hathatx.png
hathatx.png (500 Bytes) Viewed 9110 times

nextdrinkplease
Posts: 3
Joined: Fri Jan 14, 2011 7:52 pm

Re: Double hat looks ugly

Postby nextdrinkplease » Tue Jan 18, 2011 12:38 am

Thank you so much, this is exactly what i needed! i will try it out tomorrow and let you know how it goes, ok? :D

if i understand well, vphantom raises and lowers one of the two hats (the inner one)...brilliant!

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Double hat looks ugly

Postby frabjous » Tue Jan 18, 2011 1:10 am

What \vphantom{...} does is trick LaTeX into thinking that the current box has a height of the contents of {...} even without printing {...}. So in this case, the upper/outer hat is placed over a box which is treated as having the height of the non-printing rule here.

I haven't made any changes to the height of the inner/lower hat.
Last edited by cgnieder on Sat Oct 20, 2012 12:00 am, edited 1 time in total.

nextdrinkplease
Posts: 3
Joined: Fri Jan 14, 2011 7:52 pm

Re: Double hat looks ugly

Postby nextdrinkplease » Mon Feb 14, 2011 1:29 pm

I checked and it works fine, thanks a lot. It does need the accents package, just as you said.


Thanks a lot!

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Double hat looks ugly

Postby localghost » Mon Feb 14, 2011 5:27 pm

nextdrinkplease wrote:I checked and it works fine, […]

Then please mark the topic (not the last post) accordingly as written in Section 3 of the Board Rules (to be read before posting).


Best regards and welcome to the board
Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 1 guest