10

There is a strange inconsistency between \overbrace and \underbrace when one wishes to have the associated text (above or below) in a different color.

\underbrace behaves as expected and \overbrace does not -- both the text below the brace and above are changed by the color command, not just the raised text. To try to fix a \color{black} is required inside the {} for the lower text. However, the brace remains red. Is this an error in xcolor?

\documentclass[a4paper,12pt,oneside,pdftex]{article}

\usepackage{amsmath}
\usepackage[dvipsnames]{xcolor}

\begin{document}

$$\underbrace{x}_{\color{red} \sin t} \overbrace{x}^{\color{red} \sin t} \quad \overbrace{\color{black}x}^{\color{red} \sin t} $$

\end{document}

Underbrace behaving, overbrace not, corrected (in part) by explicit \color{black} command

2
  • 1
    Welcome to TeX.SE.
    – Mico
    Commented Dec 21, 2020 at 8:26
  • 3
    Off-topic: Don't use $$ in a LaTeX document to initiate and terminate display math mode; instead, use \[ and \]. For more information on this issue, please see Why is \[ ... \] preferable to $$ ... $$?
    – Mico
    Commented Dec 21, 2020 at 8:29

1 Answer 1

8

You can either use \textcolor instead of \color or enclose the whole superscript in an extra set of {}:

enter image description here

\documentclass[a4paper,12pt,oneside,pdftex]{article}

\usepackage{amsmath}
\usepackage[dvipsnames]{xcolor}

\begin{document}

\[\underbrace{x}_{\color{red} \sin t} \overbrace{x}^{\textcolor{red}{\sin t}} \quad \overbrace{x}^{{\color{red} \sin t}} \]

\end{document}

You must log in to answer this question.

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