This is what I'm trying to do:
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?
Hope the below can meets your requirement:
\documentclass{book}
\usepackage{mnsymbol}
\begin{document}
$\overlinesegment{text}$
\end{document}
Output
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}
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}
Not sure if I understood your formatting objective, but the \overbracket
directive of the mathtools package may be what you're looking for.
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}
$\stackrel{text}{\wedge}$
? Sorry, if it not suits...