LaTeX forum ⇒ Math & ScienceThinner Braces in Math Mode Topic is solved

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

Thinner Braces in Math Mode

Postby Cham » Sun Nov 18, 2012 6:28 pm

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 :
  1. \documentclass[12pt,letterpaper]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage{amsmath}
  5.  
  6. \begin{document}
  7. Test with braces :
  8. \begin{equation}
  9. \underbrace{ABCD}_{\text{this is a test}} + DEFG = \overbrace{HIJK}^{\text{this is a test}}
  10. \end{equation}
  11. \end{document}

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
cgnieder
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Sun Nov 18, 2012 6:44 pm

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:
  1. \documentclass[12pt,letterpaper]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage{amsmath}
  5. \usepackage{newtxtext}
  6. \usepackage{newtxmath}
  7. \begin{document}
  8. Test with braces:
  9. \begin{equation}
  10. \underbrace{ABCD}_{\text{this is a test}} + DEFG = \overbrace{HIJK}^{\text{this is a test}}
  11. \end{equation}
  12.  
  13. \end{document}


braces.png
braces.png (7.82 KiB) Viewed 3006 times


Regards
Last edited by cgnieder on Sun Nov 18, 2012 7:17 pm, edited 2 times in total.
Reason: added example + image
Clemens
------------------------------
New German Q&A site about TeX: http://texwelt.de/wissen

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Cham
Posts: 591
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sun Nov 18, 2012 6:55 pm

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.

Link:
BBcode:
HTML:
Hide post links
Show post links

hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm
Location: 's-Hertogenbosch, Netherlands

Postby hugovdberg » Sun Nov 18, 2012 7:10 pm

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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
cgnieder
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Sun Nov 18, 2012 7:14 pm

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
Clemens
------------------------------
New German Q&A site about TeX: http://texwelt.de/wissen

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Cham
Posts: 591
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sun Nov 18, 2012 7:16 pm

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 ?

Link:
BBcode:
HTML:
Hide post links
Show post links

hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm
Location: 's-Hertogenbosch, Netherlands

Postby hugovdberg » Sun Nov 18, 2012 7:20 pm

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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
cgnieder
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Sun Nov 18, 2012 7:27 pm

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
Clemens
------------------------------
New German Q&A site about TeX: http://texwelt.de/wissen

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
Cham
Posts: 591
Joined: Sat Apr 02, 2011 4:06 pm

Postby Cham » Sun Nov 18, 2012 7:31 pm

I'm already using the mathtools package.

Is there any other way to add comments under (or above) an equation term ?

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
cgnieder
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Sun Nov 18, 2012 7:51 pm

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

  1. \documentclass[12pt,letterpaper]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[utf8]{inputenc}
  4. \usepackage{mathtools}
  5.  
  6. \usepackage{tikz}
  7. \usetikzlibrary{decorations.pathreplacing}
  8. \makeatletter
  9. \def\underbrace#1{%
  10. \@ifnextchar_{\tikz@@underbrace{#1}}{\tikz@@underbrace{#1}_{}}}
  11. \def\tikz@@underbrace#1_#2{%
  12. \tikz[baseline=(a.base)] {\node[inner sep=0] (a) {\(#1\)};
  13. \draw[line cap=round,decorate,decoration={brace,amplitude=5pt}]
  14. (a.south east) -- node[below,inner sep=7pt] {\(\scriptstyle #2\)} (a.south west);}}
  15. \def\overbrace#1{%
  16. \@ifnextchar^{\tikz@@overbrace{#1}}{\tikz@@overbrace{#1}^{}}}
  17. \def\tikz@@overbrace#1^#2{%
  18. \tikz[baseline=(a.base)] {\node[inner sep=0] (a) {\(#1\)};
  19. \draw[line cap=round,decorate,decoration={brace,amplitude=5pt}]
  20. (a.north west) -- node[pos=.5,above,inner sep=7pt] {\(\scriptstyle #2\)} (a.north east);}}
  21. \makeatother
  22.  
  23. \begin{document}
  24. Test with braces:
  25. \begin{equation}
  26. \underbrace{ABCD}_{\text{this is a test}} + DEFG = \overbrace{HIJK}^{\text{this is a test}}
  27. \end{equation}
  28.  
  29. \end{document}


Regards
Clemens
------------------------------
New German Q&A site about TeX: http://texwelt.de/wissen

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 4 guests