0

I tried to underbrace a text with size 13 in ttfamily style. But as soon as I apply the underbrace, it changes the style. I also changed the color but that works somehow. I didn't find any options to set the font size or family, can this be done?

Here is the code I tried to achieve my target:

\fontsize{13}{13}{
  \ttfamily{
    $\underbrace{\textcolor{blue}{Title}}_{Title of the Project}$
  }
}

I don't care too much about the font, size and color below the braces but the one above is important. Would be great if that could be adjusted as well though.

1 Answer 1

1

You could use

$\underbrace{\texttt{\textcolor{blue}{Title}}}_{\texttt{Title}}$

but with some more work you can obtain a fairly general command where you can set text properties independently.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}

\ExplSyntaxOn

\NewDocumentCommand{\textunderbrace}{ O{} m m }
  {
    \group_begin:
    \invalid_tub:NNnnn \underbrace \sb { #1 } { #2 } { #3 }
    \group_end:
  }
\NewDocumentCommand{\textoverbrace}{ O{} m m }
  {
    \group_begin:
    \invalid_tub:NNnnn \overbrace \sp { #1 } { #2 } { #3 }
    \group_end:
  }

\keys_define:nn { invalid/tub }
  {
    font .tl_set:N = \l__invalid_tub_font_tl,
    font-main .tl_set:N = \l__invalid_tub_fontmain_tl,
    font-sub .tl_set:N = \l__invalid_tub_fontsub_tl,
    color .tl_set:N = \l__invalid_tub_color_tl,
    color-main .tl_set:N = \l__invalid_tub_colormain_tl,
    color-sub .tl_set:N = \l__invalid_tub_colorsub_tl,
    font .initial:n = \text,
    color .initial:n = .,
  }

\cs_new_protected:Nn \invalid_tub:NNnnn
  {
    \keys_set:nn { invalid/tub } { #3 }
    \tl_if_empty:NT \l__invalid_tub_fontmain_tl
      {
        \tl_set_eq:NN \l__invalid_tub_fontmain_tl \l__invalid_tub_font_tl
      }
    \tl_if_empty:NT \l__invalid_tub_fontsub_tl
      {
        \tl_set_eq:NN \l__invalid_tub_fontsub_tl \l__invalid_tub_font_tl
      }
    \tl_if_empty:NT \l__invalid_tub_colormain_tl
      {
        \tl_set_eq:NN \l__invalid_tub_colormain_tl \l__invalid_tub_color_tl
      }
    \tl_if_empty:NT \l__invalid_tub_colorsub_tl
      {
        \tl_set_eq:NN \l__invalid_tub_colorsub_tl \l__invalid_tub_color_tl
      }
    \ensuremath
      {
        #1 % \underbrace or \overbrace
         {
          \l__invalid_tub_fontmain_tl { \color{\l__invalid_tub_colormain_tl} #4 }
         }
        #2 % \sb or \sp
         {
          \l__invalid_tub_fontsub_tl { \color{\l__invalid_tub_colorsub_tl} #5 }
         }
      }
  }

\ExplSyntaxOff

\begin{document}

$\underbrace{\texttt{\textcolor{blue}{Title}}}_{\texttt{Title of the Project}}$
\textunderbrace[font=\texttt,color-main=blue]{Title}{Title of the Project}

\bigskip

\textunderbrace{Title}{Title of the project}

\bigskip

\textoverbrace[
  font-main=\texttt,
  font-sub=\textit,
  color-main=blue,
  color-sub=red,
]{Title}{Title of the Project}

\end{document}

If you use font=<command>, it will affect both parts; but you can set separately font-main and font-sub; similarly for color, color-main and color-sub.

Fewer braces mean fewer occasions to count them wrong.

enter image description here

You must log in to answer this question.

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