11

Is it possible to create an overline with a gap containing a symbol in the middle in math mode?

What I would like to achieve is something like this: Example

JPW
  • 721

2 Answers2

10

Something like this?

\documentclass{article}
\usepackage{amsmath}

\newcommand{\joverline}[2]{%
  \mathord{% make sure we're in math mode
    \vbox{\offinterlineskip
      \halign{##\cr
        \hrulefill$\,\scriptscriptstyle#1\,$\hrulefill\cr
        \noalign{\kern.3ex}
        $#2$\cr
      }%
    }%
  }%
}

\begin{document}

$\joverline{n}{(Q,\emptyset)}$

\end{document}

enter image description here

Something more could be needed if you plan to use this construction also in sub/superscripts.

A version with the superscript centered vertically with respect to the rule:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\chrulefill}{%
  \leaders\hrule height \dimexpr\fontdimen22\scriptscriptfont2+0.2pt\relax
                 depth -\dimexpr\fontdimen22\scriptscriptfont2-0.2pt\relax
          \hfill}

\newcommand{\joverline}[2]{%
  \mathord{% make sure we're in math mode
    \vbox{\offinterlineskip
      \halign{##\cr
        \chrulefill$\,\scriptscriptstyle#1\,$\chrulefill\cr
        \noalign{\kern.2ex}
        $#2$\cr
      }%
    }%
  }%
}

\begin{document}
$\joverline{n}{(Q,\emptyset)}$
\end{document}

You can change the spacing between the rule and the main part by modifying the \kern.2ex; adjust at will.

enter image description here

egreg
  • 1,121,712
  • Thank you, your answer works almost perfect, but I would prefer the line to be vertically centered. Additionally in an exponent like $\joverling{n}{(Q, S)}}^1$ the 1 seems to have too less spacing from the line. – JPW Jul 02 '13 at 18:03
  • @JPW Added new version – egreg Jul 02 '13 at 18:12
4

The overset gap, currently set to 2pt, can be changed to suit.

\documentclass{article}
\usepackage{stackengine}
\usepackage{calc}
\newcommand\overlineset[2]{%
  \stackengine{2pt}{$#1$}{\makebox[\widthof{$#1$}]{%
      $\scriptscriptstyle\hrulefill\,#2\,\hrulefill$}}{O}{c}{F}{T}{S}%
}
\begin{document}
\(\overlineset{(Q,\emptyset)}{n}\)
\end{document}

enter image description here

  • Thanks for the answer, but I get a "! LaTeX Error: File `stackengine.sty' not found." on "Version 3.1415926-2.4-0.9998 (MiKTeX 2.9) (preloaded format=xelatex 2012.11.2)" – JPW Jul 02 '13 at 17:56
  • @JPW The package is at http://ctan.org/pkg/stackengine . To test it out, you can just download the .sty file to your working directory. If you like what you see, get the PDF to see its capability. – Steven B. Segletes Jul 02 '13 at 17:58