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

Re: Thinner Braces in Math Mode

Post by Cham »

Wow !

The result appears to be very nice.

I'll play a bit with this solution, to see if it fits my needs (without any compatibility issue...)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Thinner Braces in Math Mode

Post by Cham »

I changed a bit some parameters. I didn't printed an example yet, to see how fine it is, but when I zoom the PDF document, it appears to be very nice :

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=2] (a) {\(#1\)};
  \draw[line cap=round,decorate,decoration={brace,amplitude=4pt}]
    (a.south east) -- node[pos=0.5,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=2] (a) {\(#1\)};
  \draw[line cap=round,decorate,decoration={brace,amplitude=4pt}]
    (a.north west) -- node[pos=0.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}
A preview :
braces.jpg
braces.jpg (16.67 KiB) Viewed 4196 times
Now, is there a way to simplify the code above ? It's pretty messy to my eyes. :oops:
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Thinner Braces in Math Mode

Post by cgnieder »

Cham wrote:Now, is there a way to simplify the code above ? It's pretty messy to my eyes.
The code isn't messy at all! It is pretty straightforward, IMHO. There is not much you can do...

Regards
site moderator & package author
Post Reply