Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have the problem that I want to have an equation with underbrace but the surrounding parenthesis shall not include the underbrace, i.e. should have the size as if the underbrace wasn't there. Here is the code I use:

\documentclass{article}
\usepackage{amsmath}
\begin{document}    
$\exp \left(\gamma \underbrace{\begin{pmatrix} 1 & 2\\ 3 & 4 \end{pmatrix}}_\text{some text} \right)$
\end{document}

I'd like to have that the outer parenthesis have the same size and center as the parenthesis of the pmatrix. I tried \Bigg( but it looked slightly off and it only works for 2x2 matrices but not for 3x3. Any ideas?

share|improve this question
4  
Not the answer, but it's better to use \Biggl( for the left parenthesis and \Biggr) for the right (they deal better with spacing). And works with big, Big,… –  Manuel Dec 11 '12 at 21:17
2  
@Manuel -- ah, but you do have the answer, except it's \biggl( and \biggr) that match the inner parentheses. –  barbara beeton Dec 11 '12 at 21:30
    
@barbarabeeton No, I don't have the answer to the ...and it only works for 2x2 matrices but not for 3x3. The idea is to make \underbrace not in the parenthesis. –  Manuel Dec 11 '12 at 21:32
    
@Manuel 3x3 matrix inside the parenthesis is terrible anyways so no problem there :) –  percusse Dec 11 '12 at 21:34
    
Strongly related: Underbrace under sqrt content. I think the answers there offer possibilities for your problem, too. –  Hendrik Vogt Dec 23 '12 at 11:22

5 Answers 5

up vote 9 down vote accepted

this is overkill for a 2-by-2 matrix, but it would work for larger matrices as well, even for ones where big versions of parentheses aren't available.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$\exp \left( {\vphantom{\begin{pmatrix} 1\\ 3 \end{pmatrix}}} \right. \!\!
\gamma \underbrace{\!\! \begin{pmatrix} 1 & 2\\
 3 & 4 \end{pmatrix} \!\!}_\text{some text} \!\!
\left. {\vphantom{\begin{pmatrix} 1\\ 3 \end{pmatrix}}} \right)$
\end{document}

observe the use of \! to get rid of some unwanted horizontal space.

output of sample code

share|improve this answer
    
Ah I would have expected a \smash magic from you :P –  percusse Dec 11 '12 at 21:43
    
@percusse -- as much as i love \smash, that would have caused problems with whatever follows this expression on the next line. –  barbara beeton Dec 11 '12 at 21:45
    
@barbarabeeton One could use \left(\smash[b]{\underbrace{…}_{…}}\right) and \vphantom{\underbrace{…}_{…}} outside of the parenthesis, provided that the latter doesn’t fall in the next line (but it’s not such a good idea to use a big matrix in inline math). A macro could help to not have to repeat the content. –  Qrrbrbirlbel Dec 11 '12 at 21:50
1  
Thanks, works nicely! However, if the text under the matrix is very long, there is ugly whitespace around the matrix. So I combined your solution with the \mkern command from @tohecz and now it looks perfect :-). –  Phil Dec 12 '12 at 15:09

Maybe I shouldn't have posted this but I'm reviewing a lot of papers involving huge matrices and I can't stand inline matrices. If needed use the smallmatrix environment or state the matrix exponential as $e^{\gamma A}$ and put A matrix as a display math.

enter image description here

\documentclass{article}
\usepackage{mathtools} %<- Builds on top of amsmath and fixes/improves some stuff
\begin{document}    
The sentences start like this then slowly they get longer and longer and then sentence
becomes like this 
$e^{\gamma\!\! 
\underbracket[0.4pt][1pt]{
\begin{psmallmatrix} 1 & 2\\ 3 & 4 \end{psmallmatrix}
}_{\text{\tiny some text}} }$ 
and maybe after that something like 
\raisebox{0.5ex}{%
$\exp{(\gamma\!\! \underbracket[0.4pt][1pt]{
\begin{psmallmatrix} 1 & 2\\ 3 & 4 \end{psmallmatrix}}_{\text{\tiny some text}} )}
$
}
then continues with more stuff that starts another line which still looks terrible.
However this one 
\[
e^{\left(\gamma\!\! \underbracket[0.4pt][1pt]{
\begin{psmallmatrix} 1 & 2\\ 3 & 4 \end{psmallmatrix}
}_{\text{\tiny some text}} \right)} = 
\exp{(\gamma\!\! \underbracket[0.4pt][1pt]{
\begin{psmallmatrix} 1 & 2\\ 3 & 4 \end{psmallmatrix}
}_{\text{\tiny some text}} )}
\]
has no such problems. But still none of them works properly
in my opinion. The best is to go with $e^{\gamma A}$ where 
\[
A =\begin{pmatrix}
     1&2\\3&4
\end{pmatrix}
\]
\end{document}
share|improve this answer
1  
+1 If it looks too complicated and messy, split it into parts and use displayed math. –  yo' Dec 12 '12 at 9:32
    
I totally agree about the inline math. I just used inline math in the snippet, in the final version it's within an equation environment. –  Phil Dec 12 '12 at 13:56
    
For the person who awarded the bounty: I wasn't aware of this bounty so I've missed its owner but thank you very much. It feels a little undeserved for this answer :) –  percusse Dec 17 '12 at 0:19
    
You can hover over the bounty to see that it was @tohecz. And I agree with them that your answer deserves it, because sometimes the best answer is not about solving the posed problem but figuring out why it occurred at all. Though in this case the OP clarified inline math was not the intention –  Tobias Kienzler May 13 '13 at 12:04

If you need it only once, I would go for a manual adjustment:

\documentclass{article}
\usepackage{amsmath}
\begin{document}    
$\exp
\mkern30mu
\underbrace{
\mkern-30mu
\left(
\gamma
\begin{pmatrix} 1 & 2\\ 3 & 4 \end{pmatrix}
\right)
\mkern-18mu
}_\text{some text}
\mkern18mu
$
\end{document}

I put the \underbrace outside, and using \mkern with positive and negative value I made it think that its contents is smaller. The values 30mu and 18mu were found by trial-and-error.

share|improve this answer

Here is another:

\documentclass{article}
\usepackage{amsmath}
\newsavebox{\bpmatrixbox}
\newdimen\parenwd \parenwd=8.75002pt
\newcommand\bpmatrix[2]{
  \savebox{\bpmatrixbox}{\(\begin{pmatrix}#1\end{pmatrix}\)}
  \vrule height\ht\bpmatrixbox depth\dp\bpmatrixbox width0pt
  \smash{\oalign{
    \usebox{\bpmatrixbox}\cr\noalign{\kern\jot}
    \kern\parenwd\upbracefill\kern\parenwd\cr
    \strut\hidewidth\small #2\hidewidth}}
}

\begin{document}
Some text before
\begin{gather*}
  \exp\left(\gamma \bpmatrix{1& 2\\ 3& 4}{some text} \right) \\
\end{gather*}
the previous display math environment clashes into this here text without the gather's last double backslashes.
\end{document}

enter image description here

share|improve this answer

Again, overkill; but, for what it's worth, here's a tikz solution that appears to work.

enter image description here

The primary difficulty here, as elsewhere, was getting the underbrace and its text to count for vertical spacing, but not until after the outer parentheses were set. The tikz solution I initially had in mind was to save the position with tikz nodes in the middle of the math, and then come back afterwards with an underbrace at the saved position. The trouble with this approach is that tikz constructions that reference positions from other tikz pictures are supposed to be given the overlay option, which effectively smashes any effect the construction would have on the vertical spacing (and would make the next line too high).

The way I got around this was to put the entire expression in a node in a tikz picture. Thus, I actually have tikz nodes inside a tikz picture inside a tikz node inside a tikz picture. I'm not sure whether this behavior is supported, but it seems more or less to work for this particular construction.

\documentclass{article}
\usepackage{amsmath,tikz}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{calc}
\newcommand{\currentmatrix}{}
\newcommand{\tikznode}[2][$\currentmatrix$]{\tikz[overlay]\node (#2) {\vphantom{#1}};}

\begin{document}
\renewcommand{\currentmatrix}{\begin{pmatrix} 1 & 2\\ 3 & 4 \end{pmatrix}}
\begin{align*}
\tikz[remember picture,baseline=(left.east),inner xsep=0pt]{
    \node {$\exp \left(\gamma \tikznode{left}
        \begin{pmatrix} 1 & 2\\ 3 & 4 \end{pmatrix}\tikznode{right} 
        \right)$};
    \draw[overlay,decorate,decoration={brace,amplitude=3pt}]
        ($(right.south west) + (0,4pt)$) -- 
        coordinate(texthere) ($(left.south east)+(0,4pt)$); 
    \path (texthere) node[below] {$\scriptstyle\text{some text}$};
} &= e^{\gamma A} \\
&= \exp(\gamma A)
\end{align*}

\end{document}
share|improve this answer
    
This is a overkill not only in the sense of "too much tweaking for one thing", but as well in the sense "if people are going to use TikZ for everything, the documents will took hours to compile". –  yo' Dec 12 '12 at 9:31
    
@tohecz: Fair point, although I don't think uses like this are very bad from that perspective--what takes forever to compile are functions plotted with TikZ's own math library. In any case, I pursued this primarily because it was more difficult than I had first envisioned, and I was intrigued. Once I got something that worked, I couldn't not post it, could I? [The last sentence is intended humorously.] –  Charles Staats Dec 12 '12 at 17:04
    
The problem with TikZ is the heavy programming structure, but let's not discuss this anymore. It wasn't meant as "this answer is wrong", I just wanted to point out the efficiency issues ;) –  yo' Dec 12 '12 at 17:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.