TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use mathpazo font package and I think the hat symbol is too low. Can I make a macro to change behavior of all my hats?

This question has a good example, but I don't want to have to retype all of my hats:

Can I move the hat symbol vertically upwards?

share|improve this question
possible duplicate of Can I move the hat symbol vertically upwards? – Harish Kumar Jul 25 '14 at 0:32
up vote 3 down vote accepted

Here I use stackengine to add a stacking gap on the argument of \hat. I also use scalerel package to preserve the math style, and to express the stacking gap, .3\LMpt, in terms of a unit that scales with the math style (as an argument to \ThisStyle{}, \LMpt is a scalable version of 1pt, that will scale with smaller math styles).

The hat kerning is lost, when I wrap the argument in an \addstackgap, so I re-add kerning to the hat, proportional to the height of the glyph, using \slantfactor = .2.

$\svhat{x}\svhat{P}$ (original)

$\hat{x} \hat{P} \scriptstyle \hat{x} \hat{P} \scriptscriptstyle \hat{x} \hat{P}$

enter image description here

share|improve this answer
great answer, I don't have stackengine.sty on my windows latex install and installing packages manually seems to be quite a headache that I have yet to try (tex.stackexchange.com/questions/2063/…). Any solution that does not require stackengine? – bdeonovic Jul 24 '14 at 16:12
@Benjamin The package can be downloaded from ctan.org/tex-archive/macros/latex/contrib/stackengine. If you just place the .sty file in your working directory, all should work. – Steven B. Segletes Jul 24 '14 at 16:24

Instead of using the mathpazo package, which is (a) quite old and (b) well known for having various font metric problems, you could use the newpxtext and newpxmath packages. These are derived from the mathpazo package but have much better font metrics. In particular, these packages produce well-spaced hat symbols. If you use these packages instead of mathpazo -- and I can honestly not think of a good reason for continuing to use mathpazo if newpxtext and newpxmath are available on your system -- there's simply no need to manually correct/improve the spacing of the stacked hat symbol.

enter image description here

$\hat{u}$ $\hat{U}$

For comparison, here are the same two symbols with the mathpazo package loaded instead of newpxtext and newpxmath:

enter image description here

share|improve this answer
This is excellent, thank you! I accepted @Steven's answer since he directly answered my question (for anyone in the future looking to change hat height, regardless of font used). I will probably use this solution though. – bdeonovic Jul 24 '14 at 16:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.