[Tex/LaTex] Side brace around image with underbrace

bracesgraphics

I have an image and I want to put a side brace on the left and an underbrace on the bottom. The underbrace works fine, but the left becomes twice the image height for some reason. I'm sure the image isn't actually that big, I've looked at the pixel height. Is this the wrong way to do it?

$r\left\{\underbrace{\includegraphics{image1.jpg}}_{k/r}\right.$

Best Answer

You have to center the picture with respect to the math axis: but it's best to define a personal command for this

\documentclass{article}
\usepackage{graphicx}

\newcommand{\bracedincludegraphics}[2][]{%
  \sbox0{$\vcenter{\hbox{\includegraphics[#1]{#2}}}$}%
  \left\lbrace
    \vphantom{\copy0}
  \right.\kern-\nulldelimiterspace
  \underbrace{\box0}}

\begin{document}
$r\bracedincludegraphics{image1}$
\end{document}

The command \bracedincludegraphics accepts the same options as \includegraphics.

enter image description here

I set the image in a box for later use, centered with respect to the math axis (that's the main problem with your try, as the image has all height and no depth, and \left assumes that it has to cover as much over the math axis as below).

Then I use the box to determine the size of the left brace with a \vphantom, close with \right. and kern back a bit; only after this I typeset the image with the underbrace.

EDIT

In order to add a small clearance also between the underbrace and the image, the following modified macro should help:

\newcommand{\bracedincludegraphics}[2][]{%
  \sbox0{$\vcenter{\hbox{\includegraphics[#1]{#2}}}$}%
  \left\lbrace
    \vphantom{\copy0}
  \right.\kern-\nulldelimiterspace
  \underbrace{\vrule width0pt depth \dimexpr\dp0 + .3ex\relax\box0}}

The .3ex should be what's needed, but it depends on the font actually used for math.

enter image description here