13

This is what I'm trying to do:

enter image description here

I basically want to put a hat on top of the word and then a text on top of the hat. How do I do this?

3
  • Do you looking this $\stackrel{text}{\wedge}$? Sorry, if it not suits...
    – MadyYuvi
    Commented Apr 13, 2021 at 4:15
  • 2
    Please clarify what you mean by "hat". Presumably not a bowler hat or a top hat, right? Could it be a curly brace lying on its side?
    – Mico
    Commented Apr 13, 2021 at 4:43
  • 1
    @Mico you are right, I need something that looks like the line (with borders) on the picture I attached. I called it a "hat" because I didn't find a better name.
    – yegor256
    Commented Apr 13, 2021 at 4:54

3 Answers 3

9

Hope the below can meets your requirement:

\documentclass{book}
\usepackage{mnsymbol}
\begin{document}

$\overlinesegment{text}$

\end{document}

Output

enter image description here

1
  • fdsymbol.sty also does the same trick...
    – MadyYuvi
    Commented Apr 13, 2021 at 5:17
15

With standard fonts and stmaryrd.

\documentclass{article}
\usepackage{stmaryrd} % for the \mapsfrom glyph
\usepackage{amsmath} % for \arrowfill@

\newcommand{\overhat}[2]{% #1 = main word, #2 = label
  \leavevmode\vbox{\offinterlineskip
    \ialign{%
      \hfil##\hfil\cr
      \footnotesize\strut\,#2\,\cr
      \makehat\cr
      \strut#1\cr
    }%
  }%
}
\makeatletter
\newcommand{\makehat}{%
  \arrowfill@{\mapstochar\relbar}\relbar{\relbar\mapsfromchar}{}%
}
\makeatother

\begin{document}

Hello, \overhat{Jeffrey}{name}

Hello, \overhat{A}{y}

Hello, \overhat{A}{zzz}

\end{document}

enter image description here

Without fonts, so the size of the bars are easily customizable. Here the height is 1pt.

\documentclass{article}
\usepackage{l3draw}

\newcommand{\overhat}[2]{% #1 = main word, #2 = label
  \leavevmode\vbox{\offinterlineskip
    \ialign{%
      \hfil##\hfil\cr
      \footnotesize\strut\,#2\,\cr
      \hatbar
      \leaders\hrule height 0.9pt depth -0.5pt\hfill
      \hatbar\cr
      \strut#1\cr
    }%
  }%
}
\ExplSyntaxOn
\newcommand{\hatbar}
 {
  \draw_begin:
  \draw_cap_round:
  \draw_path_moveto:n {0pt,0pt}
  \draw_path_lineto:n {0pt,1pt}
  \draw_path_use_clear:n { stroke }
  \draw_end:
 }
\ExplSyntaxOff

\begin{document}

Hello, \overhat{Jeffrey}{name}

Hello, \overhat{A}{y}

Hello, \overhat{A}{zzz}

\end{document}

enter image description here

1
  • Such a nice suggestion...
    – MadyYuvi
    Commented Apr 14, 2021 at 3:53
8

Not sure if I understood your formatting objective, but the \overbracket directive of the mathtools package may be what you're looking for.

enter image description here

Observe that \overbracket is a math-mode command; hence the $ symbols to initiate and terminate inline math mode and the two instances of \text in

$\overbracket{\text{Jeffrey}}^{\text{name}}$

If your document has several instances of such \overbracket-based directives, it's probably worth setting up a dedicated macro to help simplify and streamline entering the required information. E.g.,

\newcommand\myhat[2]{$\overbracket{\text{#1}}^{\text{#2}}$

This would allow you to input \myhat{Jeffrey}{name}.

Section 3.2.2 of the user guide of the mathtools package provides information on customizing (a) the line thickness of the "hat" and (b) the height of the hat above the baseline.

\documentclass{article}
\usepackage{mathtools} % for '\overbracket' macro
\begin{document}
\sffamily % optional

Hello, $\overbracket{\text{Jeffrey}}^{\text{name}}$!
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .