7

I'm using mathpazo to format a document and have just become annoyed that a hat appears to be rendering too close to the letter it's decorating. I'd like to move the hat upwards, but am not sure how to go about doing it.

My LaTeX is just \hat{x}_{t+1}, which renders as:

rendered \hat{x}_{t+1}

Is there any way to change this?

8
\documentclass{article}
\usepackage{mathpazo}
\usepackage{amsmath}   %% come by habit ;)
\begin{document}
    \[
      \hat{x}_{t+1}
    \]
    \[
      \hat{\rule{0ex}{1.2ex}\mkern-3mu x}_{t+1}
    \]
\end{document}

enter image description here

  • Fantastic! This also introduced me to \rule{width}{height} as well as \mkernUNITS and mu units, none of which I'd used before. Thanks! – lmjohns3 Apr 29 '14 at 4:50
8

You could use a \vphantom{} which inserts a vertical height equal to the parameter provided but of zero width. So using \vphantom{f} will make the \hat behave as if the hat needs to be on top of an f:

enter image description here

To have more fine tuned control you can use a scaled parameter via \hat{\vphantom{\scalebox{1.1}{x}} x}:

enter image description here


The \vphantom{} trick is useful in other cases such as with \sqrt{x} \sqrt{y} (as below on the left) which looks odd but is better with a \sqrt{x\vphantom{y}} \sqrt{y} (on the right) where both the top and bottom of the \surd are now aligned:

enter image description here

Code:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
    \[
      \hat{\vphantom{f}x}_{t+1} \hat{f}_{t+1}
    \]
    or using \verb|\scalebox{}|
    \[
      \hat{x}_{t+1}
      \hat{\vphantom{\scalebox{1.1}{x}} x}_{t+1}
      \hat{\vphantom{\scalebox{1.2}{x}} x}_{t+1}
     \]
\end{document}
  • This is also a great answer, with an excellent explanation. Wish I could accept both. – lmjohns3 Apr 29 '14 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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