# How to combine \overbrace and \overline the way I want?

Consider the following:

\documentclass[a4paper,12pt]{article}

\usepackage{amsmath}

\begin{document}

$u=\overline{\exists degree\hspace{3pt} \overbrace{\big(\underbrace{degrees(course, degree)}_{u_1}\wedge\underbrace{degree\neq 1}_{u_2}\big)}^{u_3}}$

\end{document}


Which produces this:

I want that the \overbrace with the u_3 label will appear above the \overline, but still encompass only the parentheses. I can't find a way to do it.

Can it be done somehow?

Typeset the whole thing three times. The first one as a horizontal phantom to set the width, the second time as the real thing, the third time as a vertical phantom.

The first two times the two objects are superimposed with \ooalign.

In order to save typing, the object is saved in a temporary command, which takes as argument an invisible rule stating its height.

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{lipsum} % for giving context

\newcommand{\func}[1]{\operatorname{#1}}
\newcommand{\var}[1]{\mathit{#1}}

\begin{document}

\lipsum*[2]
\newcommand{\contents}[1]{% \exists\, \var{degree} \: \overbrace{ #1 \bigl(\, \underbrace{\func{degrees}(\var{course},\var{degree})}_{u_1} \wedge \underbrace{\var{degree}\neq 1}_{u_2} \,\bigr) }^{u_3} } u={\ooalign{% \displaystyle\overline{\rule{0pt}{2ex}\hphantom{\contents{}}}\cr \displaystyle\contents{\rule{0pt}{2.75ex}}\cr }} \vphantom{\contents{\rule{0pt}{2.75ex}}}
\lipsum[2]

\end{document}


• Why did you define the command inside document body? Is there some reason? Nice solution, by the way. – Sigur Dec 13 '14 at 14:18
• @Sigur It's probably something that won't be used anywhere else, so defining it in the math display is just like typing it “there”. If it was in the preamble it would be more difficult to access in case some correction has to be made. – egreg Dec 13 '14 at 14:20

Another solution prints the formula only once (no three times):

$$u = \vbox{\def\shiftA{3.3ex}\def\shiftB{\vrule height2.7ex width0pt} %spec. numbers for this formula \kern\shiftA\hrule\kern-\shiftA \hbox{\displaystyle \exists\, {\it degree} \overbrace{\big( \underbrace{\shiftB{\rm degrees}({\it course},{\it degree})}_{u_1} \wedge \underbrace{{\it degree}\neq 1}_{u_2} \big)}^{u_3} }}$$


I want that the \overbrace with the u_3 label will appear above the \overline, but still encompass only the parentheses. I can't find a way to do it.

So. Forget \overline. Simply use \hspace and draw a \rule at the desired position, height, length, (and width.)

$$u=\exists degree\hspace{3pt} \overbrace{\big(\underbrace{degrees(course, degree)}_{u_1} \wedge\underbrace{degree\neq 1}_{u_2}\big) \hspace{-21em}\rule[2.25ex]{21em}{} }^{u_3}$$


• It is better IMHO to write all the text in textmode. You can give a little space between \exist and degree. +1 – Sebastiano Mar 8 '20 at 22:09
• @Sebastiano Sure, I agree in principle with writing text in textmode \textrm etc., but that wasn't the question. That's a different issue entirely. – Justina Colmena Mar 8 '20 at 22:15
• Yes, my it was only a suggestion like never to use double . See tex.stackexchange.com/questions/503/why-is-preferable-to – Sebastiano Mar 8 '20 at 22:23
• I was using KaTex in wiki.js. – Justina Colmena Mar 10 '20 at 17:07
\documentclass[12pt]{article}
\usepackage{mathtools}

\begin{document}
\def\contento{\exists\,\mathit{degree}}
\def\contenti{\big(
\underbrace{{\rm degrees}({\it course},{\it degree})}_{u_1}
\wedge
\underbrace{{\it degree}\neq 1}_{u_2}
\big)}
$u=\overline{\contento\phantom{\contenti}} \llap{\displaystyle \overbrace{\vphantom{\overline{\contento\contenti}}\contenti}^{u_3} }$

$u=\overline{\contento\vphantom{\contenti}}\! \overbrace{ \overline{\vphantom{\contento}\contenti} }^{u_3}$
\end{document}