# Underbrace across align tabs

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:

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:

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

-
Please, add an approximate example of what you want: for a single line it's easy, as you saw. – egreg Jan 19 at 18:42
@egreg : the example provided by David Carlisle in his answer is a good one. I'll add it to my question. – Martin Van der Linden Jan 19 at 18:45

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

\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:

\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.

-
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 at 18:14
@MartinVanderLinden: See my updated answer that uses zref's savepos module. – Werner Jan 19 at 20:06

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}


-
+1. Not the simplest solution but definitely the closest from what I am looking for so far. – Martin Van der Linden Jan 19 at 18:40
Thanks for the automation. I really like your answer. Unfortunately, I can only accept one answer and @Werber's answer is closer from what I asked initially. – Martin Van der Linden Jan 19 at 20:58

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

\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}

-
+1. I would obviously prefer automatic length and position adjustment, but that's a start. – Martin Van der Linden Jan 19 at 18:34
I believe you can use a combination of tikzmark with array or alignment. – cacamailg Jan 19 at 19:23
@cacamailg I leave it to others to do the tikz answers:-) (but yes, probably) – David Carlisle Jan 19 at 19:32

Here is a solution with pstricks:

\documentclass{article}
\usepackage{mathtools}

\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}


-