Math & ScienceThinner Braces in Math Mode

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Thinner Braces in Math Mode

Post by Cham »

The \underbrace and \overbrace commands are really useful, but they are ugly. I would like to have thinner braces. Is this possible ?

Here's a compilable example :

Code: Select all

\documentclass[12pt,letterpaper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\begin{document}
  Test with braces :
  \begin{equation}
    \underbrace{ABCD}_{\text{this is a test}} + DEFG = \overbrace{HIJK}^{\text{this is a test}}
  \end{equation}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Thinner Braces in Math Mode

Post by cgnieder »

This is depending on the math font you use and the way the braces are built (see here for example). So if you choose a different math font you'll probably get different braces which you might like better.

An example:

Code: Select all

\documentclass[12pt,letterpaper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{newtxtext}
\usepackage{newtxmath}
\begin{document}
Test with braces:
\begin{equation}
 \underbrace{ABCD}_{\text{this is a test}} + DEFG = \overbrace{HIJK}^{\text{this is a test}}
\end{equation}

\end{document}
braces.png
braces.png (7.82 KiB) Viewed 11926 times
Regards
Last edited by cgnieder on Sun Nov 18, 2012 7:17 pm, edited 2 times in total.
site moderator & package author
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Thinner Braces in Math Mode

Post by Cham »

The newtxtext and newtxmath packages are giving me a compilation error.

If I keep the same fonts as in my example above, is there a way to modify the underbrace and overbrace commands, so they give a nicer (thinner, slimmer) horizontal brace ?

EDIT : By nicer horizontal braces, I mean that the line thickness should be much smaller. Something graceful, not that heavy thick line we currently have.
hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

Re: Thinner Braces in Math Mode

Post by hugovdberg »

You should probably install the newtx package from ctan. Depending on your latex distribution there are different ways to install them.
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Thinner Braces in Math Mode

Post by cgnieder »

hugovdberg wrote:You should probably install the newtx package from ctan.
My thoughts exactly. The best way would be updating the TeX distribution by using the corresponding package manager. Installing fonts and fonts packages by hand can be a tedious task.

Regards
site moderator & package author
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Thinner Braces in Math Mode

Post by Cham »

Ok about the newtx package, but what about the braces without changing the fonts ?

Should I conclude that it's not really possible to change the horizontal brace commands ?
Or that it's too complicated to do, so it's not worth it ?

Edit : are there any other horizontal brace styles in LaTeX, to add comments to an equation ?
hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

Re: Thinner Braces in Math Mode

Post by hugovdberg »

I think the only other option would be drawing them using TikZ or the like, then you have full control over how your braces look like. But designing them might be a tedious task.
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Thinner Braces in Math Mode

Post by cgnieder »

mathtools says about \underbrace and \overbrace:
The standard implementation of the math operators \underbrace and \overbrace in LaTeX has some deficiencies. For example, all lengths used internally are fixed and optimized for 10 pt typesetting. As a direct consequence thereof, using font sizes other than 10 will produce less than optimal results. Another unfortunate feature is the size of the braces. In the example below, notice how the math operator \sum places its limit compared to \underbrace.
The package also tries to fix that. So maybe using mathtools will give already what you want. Note the »mathtools« internally also loads »amsmath«.

Regards
site moderator & package author
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Thinner Braces in Math Mode

Post by Cham »

I'm already using the mathtools package.

Is there any other way to add comments under (or above) an equation term ?
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Thinner Braces in Math Mode

Post by cgnieder »

Here is a TikZ solution (that might have some rough edges...) I basically stole from here:

Code: Select all

\documentclass[12pt,letterpaper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\makeatletter
\def\underbrace#1{%
  \@ifnextchar_{\tikz@@underbrace{#1}}{\tikz@@underbrace{#1}_{}}}
\def\tikz@@underbrace#1_#2{%
  \tikz[baseline=(a.base)] {\node[inner sep=0] (a) {\(#1\)};
  \draw[line cap=round,decorate,decoration={brace,amplitude=5pt}]
    (a.south east) -- node[below,inner sep=7pt] {\(\scriptstyle #2\)} (a.south west);}}
\def\overbrace#1{%
  \@ifnextchar^{\tikz@@overbrace{#1}}{\tikz@@overbrace{#1}^{}}}
\def\tikz@@overbrace#1^#2{%
  \tikz[baseline=(a.base)] {\node[inner sep=0] (a) {\(#1\)};
  \draw[line cap=round,decorate,decoration={brace,amplitude=5pt}]
    (a.north west) -- node[pos=.5,above,inner sep=7pt] {\(\scriptstyle #2\)} (a.north east);}}
\makeatother

\begin{document}
Test with braces:
\begin{equation}
 \underbrace{ABCD}_{\text{this is a test}} + DEFG = \overbrace{HIJK}^{\text{this is a test}}
\end{equation}

\end{document}
Regards
site moderator & package author
Post Reply