3

When I try using underbrace across alignment tabs, like so

\begin{align*}
\underbrace{1 && 2 && 3 && 4}_{small} && 5 && 6 && 7 && 8
\end{align*}

I get an error, which is no too surprising.

Is there an easy way to implement the above?

Specifically, I am looking for an option to put an underbrace under some elements of an align environment when those elements are spread across several (contingent) alignment tabs. I would want the spacing between tabs not to be affected by the addition of the underbrace.

The result should look something like this:

enter image description here

Equivalent solutions not using the align environment are also welcome.

Edit: ideally, I would still want a solution using something like align because I might have to repeat this kind of construction on multiple lines and would want to maintain alignment between the tabs.

For instance, I might want to do something like:

enter image description here

(the above image is taken from David Carlisle's answer)

4 Answers4

4

Don't use align, but rather insert the space using something like \quad (or \qquad, or \hspace{<len>}):

enter image description here

\documentclass{article}

\begin{document}

\[
  \underbrace{1 \qquad 2 \qquad 3 \qquad 4}_{\makebox{\small small}}
    \qquad 5 \qquad 6 \qquad 7 \qquad 8
\]

\end{document}

If you are using amsmath anyway, you can use \text{..} rather than \makebox{\small ..}.


If you're stuck on using align, I'd suggest placing markers that capture the x-coordinate on the page where you want the \underbrace to start and finish. Let's call it a left and right mark:

enter image description here

\documentclass{article}
\usepackage{amsmath,zref-savepos}
\begin{document}

\begin{align*}
  \zsaveposx{left}\makebox[0pt][l]{%
    $\underbrace{\rule{\dimexpr\zposx{right}sp-\zposx{left}sp}{0pt}}_{\text{small}}$}
  1 && 2 && 3 && 4\zsaveposx{right}
    && 5 && 6 && 7 && 8
\end{align*}

\end{document}

zref's savepos module provides an interface to pdfTeX's \pdfsavepos via something akin to \labels. So we save the x-coordinate of left and right (in small points, measured from the left of the page) using \zsaveposx and use that to create a box of width (rightsp - leftsp). The box is set to have zero width, and therefore won't influence the spacing within the align. As it's left-aligned, the \underbrace{<rule>}_{<stuff>} will stretch to the right, where <rule> has zero height.

Since this technique uses a \label-\ref-like system, you need to compile at least twice on the first go for the references to settle.

Werner
  • 603,163
  • Thanks @Werner +1. That's more or less what I did to generate the picture showing what I was aiming for (I should have mentioned it I guess). I was not clear on this but ideally, I would still want a solution using something like align because I might have to do this on multiple lines and would want to maintain alignment. I'll edit my question. – Martin Van der Linden Jan 19 '16 at 18:14
  • 2
    @MartinVanderLinden: See my updated answer that uses zref's savepos module. – Werner Jan 19 '16 at 20:06
4

You can use array environment, second row to put brace and third to place text under brace.

\documentclass{article}
\usepackage{amsmath}

\begin{document}


$\begin{array}{*{8}{c}}
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\multicolumn{4}{c}{$\upbracefill$}&\multicolumn{4}{c}{}\\
\multicolumn{4}{c}{\text{small}}&\multicolumn{4}{c}{}
\end{array}$


\end{document} 

You can also automate creation of underbrace with command

\Underbrace{<number of columns>}{<text under brace>}

\documentclass{article}
\usepackage{amsmath}

\def\Underbrace#1#2{\multicolumn{#1}{c}{$\upbracefill$}&\multicolumn{\numexpr 8-#1}{c}{}\\
\multicolumn{#1}{c}{\text{#2}}&\multicolumn{\numexpr 8-#1}{c}{}}

\begin{document}

$\begin{array}{*{8}{c}}
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\Underbrace{4}{small}\\
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8
\end{array}$


\end{document}

enter image description here

Salim Bou
  • 17,021
  • 2
  • 31
  • 76
1

this adds the brace without disturbing the alignment, although you have to adjust the length and position of the brace by hand.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
1 && 2 && 3 && 4 && 5 && 6 && 7 && 8\\[15pt]
\smash{\raise25pt\rlap{$\underbrace{\hspace{3cm}}_{\mathrm{small}}$}}
1 && 2 && 3 && 4 && 5 && 6 && 7 && 8\\
\end{align*}
\end{document}
David Carlisle
  • 757,742
1

Here is a solution with pstricks:

\documentclass{article}
\usepackage{mathtools}
\usepackage{pstricks-add, auto-pst-pdf}

\begin{document}
\begin{postscript}
  \begin{align*}
    \pnode[0pt, -2pt]{B}1 & & 2 & & 3 & & 4\pnode[0pt, -2pt]{E} & & 5 & & 6 & & 7 & & 8 \\[15pt]
    1 & & 2 & & 3 & & 4 & & 5 & & 6 & & 7 & & 8
  \end{align*}
  \psset{linejoin=1, nodesepB=1.5ex, rot=90, braceWidth=0.8pt, braceWidthInner=2.5pt, braceWidthOuter=2.5pt}
  \psbrace(B)(E){\clap{\footnotesize small}}
\end{postscript}
\end{document} 

enter image description here

Bernard
  • 271,350