# Adding underbrace in the array environment to some arbitrary columns

I've created the following output using the array environment, and I feel like it has to be created in that environment. As you can see, it's in three rows.

What I want, is to put the \underbrace{} in the exact same place as the following figure:

The LaTeX commands of the output is as the followings:

$\begin{array}{ccccccccc}‎ ‎‏‎\text{Saturday}‎ & ‎‏\text{Sunday} &‎ ‎‏\text{Mondey} &‎ ‎‏\text{Tuesday} &‎ ‎‏\text{Wednesday} ‎‎‏‏& &‎‎ ‎‏‎\text{Saturday} =‎ 4‎ &&‎ ‎‏\text{Wednesday} = 324 ‎‎‏\\ ‎‏%‎\smash[b]{‎\underbrace{‎ x‎ & ‎3‎x & 9x & 27x & ‎81‎ x = ‎324‎ %}}‎ ‎‎ & ‎‎\Longrightarrow& x ‎‎‎‎‎‎ = ‎4‎, && \text{Differenc‏e}‎ =‎ ‎320 ‎\\‎ ‎‎\multicolumn{5}{c}{(0.75)} &‎ &‎ ‎(0.25) ‎&& ‎(0.25)‎ \end{array}$‎‎‎‎


As you can see, I've commented out the \smash[b]{‎\underbrace{‎}} command, because leaving it enabled causes errors and the output completely clatters. Please help me on the issue. Thanks.

This is not done with array, but rather with stacks. The intercolumn gap is adjusted with \setstacktabbedgap{} and the interrow baselineskip is adjusted with \setstackgap{L}{}.

\documentclass{article}
\usepackage{tabstackengine,amsmath}
\begin{document}
\setstacktabbedgap{5pt}
\setstackgap{L}{18pt}
\renewcommand\stacktype{L}
\savestack\leftside{\tabbedLongunderstack{
Saturday & Sunday & Monday & Tuesday & Wednesday\\
$x$ & $3x$ & $9x$ & $27x$ & $81x = 324$
}}
\savestack\rightside{\tabbedLongunderstack{%
& Saturday${}= 4$ && Wednesday${}=324$\\
$\Longrightarrow$ & $x = 4$ && Difference ${}= 320$\\
& (0.25) && (0.25)
}}
\tabbedLongunderstack{
\stackunder[2\dimexpr\Lstackgap]{$\underbrace{\leftside}$}{(0.75)} & \rightside
}
\end{document}


If one wants the brace lowered, a simple addition of \addstackgap remedies that:

\documentclass{article}
\usepackage{tabstackengine,amsmath}
\begin{document}
\setstacktabbedgap{5pt}
\setstackgap{L}{18pt}
\renewcommand\stacktype{L}
Saturday & Sunday & Monday & Tuesday & Wednesday\\
$x$ & $3x$ & $9x$ & $27x$ & $81x = 324$
}}}
\savestack\rightside{\tabbedLongunderstack{%
& Saturday${}= 4$ && Wednesday${}=324$\\
$\Longrightarrow$ & $x = 4$ && Difference ${}= 320$\\
& (0.25) && (0.25)
}}
\tabbedLongunderstack{
\stackunder[2\dimexpr\Lstackgap]{$\underbrace{\leftside}$}{(0.75)} & \rightside
}
\end{document}


Just as a point of interest, I used \tabbedLongunderstack{} because all columns had identical (center) alignment. There is also the \tabularLongunderstack{<alignment>}{} macro, if different columns required different alignments.

• Thanks for your nice answer. Why can't it be done with the array, is there any ways to do it with the array? – Qaher Dec 30 '16 at 12:16
• @Gahir Maybe someone can propose a solution with array and \multicolumn, but it's a joke around here that I will always redo things with stacks, since I wrote the stackengine and tabstackengine packages. Reinventing the wheel and all that. Glad I could be of some assistance. – Steven B. Segletes Dec 30 '16 at 12:19

You can use two tabular environments aligned at the top, the first of which can be “underbraced” by reducing its dimensions.

The key is adding \$-\arraystretch\normalbaselineskip] at the end of the first tabular. \documentclass{article} \begin{document} \[ \renewcommand{\arraystretch}{2} {\underbrace{\begin{tabular}[t]{@{}ccccc@{}} Saturday & Sunday & Monday & Tuesday & Wednesday \\ x & 3x & 9x & 27x & 81x=324 \\ \multicolumn{5}{@{}c@{}}{(0.75)} \\[-\arraystretch\normalbaselineskip] \end{tabular}}} \begin{tabular}[t]{c@{\hspace{\tabcolsep}}cc@{}} & Saturday{}=4 & Wednesday{}=324 \\ \Longrightarrow & x=4, & Difference{}=320 \\ & (0.25) & (0.25) \end{tabular}$

\end{document}


• The spaces around Longrightarrow look not equal. Should be used @{} in the left second tabular also? I don't know. – Sigur Dec 30 '16 at 12:46
• Nice! A solution with \Longrightarrow between two tabular could be possible? Maybe could be hard to insert it exactly in the middle line. – Sigur Dec 30 '16 at 13:04
• @Sigur It is in the middle, isn't it? – egreg Dec 30 '16 at 13:56
• Yes. Sorry, I was talking about the arrow not inside the tabular. When I see the output, first idea comes to my mind is 2 tabular and the arrow in the middle. Don't worry. Just offtopic. Regards. – Sigur Dec 30 '16 at 14:03

With trial and error:

\documentclass{article}
\usepackage{array, amsmath}
\usepackage{geometry}%

\begin{document}

$\begin{array}{*{9}{c}}‎ ‎‏‎\text{Saturday}‎ & ‎‏\text{Sunday} &‎ ‎‏\text{Monday} &‎ ‎‏\text{Tuesday} &‎ ‎‏\text{Wednesday} ‎‎‏‏& &‎‎ ‎‏‎\text{Saturday} =‎ 4‎ &&‎ ‎‏\text{Wednesday} = 324 ‎‎‏\\ x‎ & ‎3‎x & 9x & 27x & ‎81‎ x = ‎324‎ ‎‎ & \Longrightarrow & x ‎‎‎‎‎‎ = ‎4‎, && \text{Differenc‏e}‎ =‎ ‎320 ‎\\ \multicolumn{5}{c}{\quad\;\raisebox{1.5ex}{ \underbrace{\hspace{22em}}_{(0.75)} }} &‎ &‎ ‎(0.25) ‎&& ‎(0.25)‎ \end{array}$

\end{document}


If you want to align all numbers in the last row, you can use the makecell package:

\documentclass{article}
\usepackage{array, amsmath, makecell}
\usepackage{geometry}%

\begin{document}

$\begin{array}{*{9}{c}}‎ ‎‏‎\text{Saturday}‎ & ‎‏\text{Sunday} &‎ ‎‏\text{Monday} &‎ ‎‏\text{Tuesday} &‎ ‎‏\text{Wednesday} ‎‎‏‏& &‎‎ ‎‏‎\text{Saturday} =‎ 4‎ &&‎ ‎‏\text{Wednesday} = 324 ‎‎‏\\ x‎ & ‎3‎x & 9x & 27x & ‎81‎ x = ‎324‎ ‎‎ & =⇒ & x ‎‎‎‎‎‎ = ‎4‎, && \text{Differenc‏e}‎ =‎ ‎320 ‎\\[-1.5ex] \multicolumn{5}{c}{\quad\;\makecell[bc]{\underbrace{\hspace{22em}}_{}\\[-1.5ex] (0.75)}} &‎ &‎ ‎(0.25) ‎&& ‎(0.25)‎ \end{array}$

\end{document}


• @gernot: I'll change that. My editor is configured for some ‘pretty printing’ and displays some symbols instead of the LaTeX code. – Bernard Dec 30 '16 at 12:26
• @Mico: I've added another solution to solve the problem you pointed. – Bernard Dec 30 '16 at 12:43

With tikz (needs two compilations):

 \documentclass{article}
\usepackage{array, amsmath}
\usepackage{geometry}%
\usepackage{tikz}
\usetikzlibrary{positioning,calc,decorations.pathreplacing,tikzmark}

\begin{document}

$\begin{array}{*{9}{c}} \tikzmark{left}‏\text{Saturday} & ‏\text{Sunday} & ‏\text{Monday} & ‏\text{Tuesday} & ‏\text{Wednesday}\tikzmark{right} ‏‏& & ‏\text{Saturday} = 4 && ‏\text{Wednesday} = 324 ‏\\ x & 3x & 9x & 27x & 81 x = 324 & \Longrightarrow & x = 4, && \text{Differenc‏e} = 320\tikzmark{row}\\[0.8\normalbaselineskip] \multicolumn{5}{c}{(0.75)} & & (0.25) && (0.25) \end{array}$

\tikz[overlay,remember picture]
\draw[decorate, decoration={brace, amplitude=10pt,raise=2pt}]  ({pic cs:row} -| {pic cs:right}) -- ({pic cs:row} -| {pic cs:left});
\end{document}