Braces spanning multiple tables (whole tables, not rows or pages)

I've got a bunch of tables arranged like so:

\documentclass{article}

\begin{document}
\begin{table}
\begin{minipage}[c][1\totalheight][t]{0.45\textwidth}%
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\par\end{center}
\caption{Table \#1}

\begin{center}
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}%
\par\end{center}
\caption{Table \#2}
\end{minipage}\hfill{}%
\begin{minipage}[c][1\totalheight][t]{0.45\textwidth}%

\begin{center}
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\par\end{center}
\caption{Table \#3}

\begin{center}
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}%
\par\end{center}
\caption{Table \#4}
\end{minipage}
\end{table}

\end{document}


And I'm trying to get braces to span multiple tables like so:

Or:

Or:

Here's an example of something I tried that uses the page margins. It works great for regular text, but not with objects like tables it seems:

\newcommand\BrText[2]{%
\par\smallskip
\noindent\makebox[\textwidth][r]{$\text{#1}\left\{ \begin{minipage}{\textwidth} #2 \end{minipage} \right.\nulldelimiterspace=0pt$}\par\smallskip
}


I tried working the problem a few other ways, but didn't think to hang on to non-working code at the time. Anyway, I recall reading somewhere that it's possible, but not sure where. Any ideas how to do this would be much appreciated.

• You really want the braces not to encompass the “Table 2” and “Table 4” captions? – frougon Aug 8 '19 at 14:57
• @frougon I think either way is probably fine. Dealers choice :) Or both if you know both. Someone else might need the alternative – voices Aug 8 '19 at 15:24

\documentclass{article}

\begin{document}
\begin{table}
$\left\{ \begin{minipage}[c]{0.45\textwidth}% \begin{center} \begin{tabular}{|c|c|c|c|c|c|c|c|} \hline a & b & c & d & e & f & g & h\\ \hline 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\ \hline a & b & c & d & e & f & g & h\\ \hline \end{tabular} \end{center} \caption{Table \#1} \begin{center} \begin{tabular}{|c|c|c|c|c|c|c|c|} \hline a & b & c & d & e & f & g & h\\ \hline 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\ \hline a & b & c & d & e & f & g & h\\ \hline \end{tabular}% \end{center} \caption{Table \#2} \end{minipage} \begin{minipage}[c]{0.45\textwidth}% \begin{center} \begin{tabular}{|c|c|c|c|c|c|c|c|} \hline a & b & c & d & e & f & g & h\\ \hline 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\ \hline a & b & c & d & e & f & g & h\\ \hline \end{tabular} \end{center} \caption{Table \#3} \begin{center} \begin{tabular}{|c|c|c|c|c|c|c|c|} \hline a & b & c & d & e & f & g & h\\ \hline 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\ \hline a & b & c & d & e & f & g & h\\ \hline \end{tabular}% \end{center} \caption{Table \#4} \end{minipage} \right\}$
\end{table}

\end{document}

• Beautiful, thanks. I actually tried that a bunch of times with minor variations and kept getting Not in outer par mode, Undefined control sequence, etc. Guess I didn't have it quite right. – voices Aug 8 '19 at 15:54
• \par\end{center}? – egreg Aug 8 '19 at 17:32
• @egreg hmm yes copied from OP, I'll delete the \par – David Carlisle Aug 8 '19 at 17:53
• what's the problem – voices Aug 9 '19 at 6:41
• @tjt263 the \par does nothing useful (I simply deleted it) it might also be better to use \centering rather than \begin{center} here to avoid extra vertical space, but I left that. – David Carlisle Aug 9 '19 at 7:14

I provide two environments, mybraceleft and mybraceright, for conveniently bracing horizontal material. They both produce horizontal material (you can use them in the middle of a paragraph) of just the required size.

One notable property of my solution as compared to David's one is that it produces horizontal material that tightly wraps the tabular environments, or whatever you decide to use in their place (you don't have to guess the 0.45\textwidth length). If you reduce the width of these elements, you'll see that my braces remain at the customizable distance \myhsep from the braced contents, which is not the case with David's solution (you'll have a larger gap between braces and contents because the minipage will have more whitespace inside, on the left and on the right of the tabular material).

A tricky part of the work with the requirements I set is to find the appropriate width for centering two tabular environments and two captions that go together. For this, I use the eqparbox package. This package relies on proper use of tags (for each tag, it finds the maximum width and allows you to use it as a normal length—this is extremely convenient, great package!). Watch for the tags in the source, they go by three (one for a minipage that tightly encloses two tabular environments and their associated captions). This process requires to compile the document at least twice.

With no table environment

In this solution, the table environment isn't used, therefore nothing floats. This is mainly boxing work. \captionof from the caption package is used to produce the customary appearance of standard table captions.

\documentclass{article}
\usepackage[hscale=0.65]{geometry} % enlarge margins a little bit for the example
\usepackage{eqparbox}
\usepackage{caption}

\makeatletter

\newsavebox{\mybox}
\newlength{\myhsep} % Horizontal separation between brace and contents
\setlength{\myhsep}{0.7em}

\newenvironment{mybraceleft}{%
\begin{lrbox}{\mybox}
}{%
\end{lrbox}%
$\m@th \left\{ \kern\myhsep \vcenter{\hbox{\usebox{\mybox}}} \right.$%
\kern-\nulldelimiterspace
\ignorespacesafterend
}

\newenvironment{mybraceright}{%
\begin{lrbox}{\mybox}
}{%
\end{lrbox}%
\leavevmode
\kern-\nulldelimiterspace
$\m@th \left. \vcenter{\hbox{\usebox{\mybox}}} \kern\myhsep \right\}$%
\ignorespacesafterend
}

\makeatother

\begin{document}

\noindent
\begin{mybraceleft}
\begin{minipage}{\eqboxwidth{tag1}}
\centering
\begin{eqminipage}[c]{tag1}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\captionof{table}{Table \#1}
\bigskip

\begin{eqminipage}[c]{tag1}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\captionof{table}{Table \#2}
\end{minipage}
\end{mybraceleft}% spaces would be ignored here anyway because of the
% \ignorespacesafterend we used
\hfill
\begin{mybraceleft}
\begin{minipage}{\eqboxwidth{tag2}}
\centering
\begin{eqminipage}[c]{tag2}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\captionof{table}{Table \#3}
\bigskip

\begin{eqminipage}[c]{tag2}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\captionof{table}{Table \#4}
\end{minipage}
\end{mybraceleft}

\vspace{2cm}
\noindent
\begin{mybraceleft}
\begin{minipage}{\eqboxwidth{tag3}}
\centering
\begin{eqminipage}[c]{tag3}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\captionof{table}{Table \#5}
\bigskip

\begin{eqminipage}[c]{tag3}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\captionof{table}{Table \#6}
\end{minipage}
\end{mybraceleft}% spaces would be ignored here anyway because of the
% \ignorespacesafterend we used
\hfill
\begin{mybraceright}
\begin{minipage}{\eqboxwidth{tag4}}
\centering
\begin{eqminipage}[c]{tag4}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\captionof{table}{Table \#7}
\bigskip

\begin{eqminipage}[c]{tag4}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\captionof{table}{Table \#8}
\end{minipage}
\end{mybraceright}

\end{document}


Wrapping braced material inside tables

This is close to the previous example, the only difference is that we allow two big chunks (each containing four tabular environments) to float. Thus, we use the table environment and can use \caption instead of \captionof. No need for the caption package in this case. This is similar to what David did, except for the input syntax (mybraceleft and mybraceright here) and horizontal spacing around the braces: my braces stay at a constant, customizable distance from the braced material (\myhsep).

As already mentioned, this requires two compilation runs to allow eqparbox to do its work.

\documentclass{article}
\usepackage[hscale=0.65]{geometry} % enlarge margins a little bit for the example
\usepackage{eqparbox}

\makeatletter

\newsavebox{\mybox}
\newlength{\myhsep} % Horizontal separation between brace and contents
\setlength{\myhsep}{0.7em}

\newenvironment{mybraceleft}{%
\begin{lrbox}{\mybox}
}{%
\end{lrbox}%
$\m@th \left\{ \kern\myhsep \vcenter{\hbox{\usebox{\mybox}}} \right.$%
\kern-\nulldelimiterspace
\ignorespacesafterend
}

\newenvironment{mybraceright}{%
\begin{lrbox}{\mybox}
}{%
\end{lrbox}%
\leavevmode
\kern-\nulldelimiterspace
$\m@th \left. \vcenter{\hbox{\usebox{\mybox}}} \kern\myhsep \right\}$%
\ignorespacesafterend
}

\makeatother

\begin{document}

\begin{table}
\centering
\begin{mybraceleft}
\begin{minipage}{\eqboxwidth{tag1}}
\centering
\begin{eqminipage}[c]{tag1}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\caption{Table \#1}
\bigskip

\begin{eqminipage}[c]{tag1}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\caption{Table \#2}
\end{minipage}
\end{mybraceleft}% spaces would be ignored here anyway because of the
% \ignorespacesafterend we used
\hfill
\begin{mybraceleft}
\begin{minipage}{\eqboxwidth{tag2}}
\centering
\begin{eqminipage}[c]{tag2}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\caption{Table \#3}
\bigskip

\begin{eqminipage}[c]{tag2}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\caption{Table \#4}
\end{minipage}
\end{mybraceleft}
\end{table}

\begin{table}
\centering
\begin{mybraceleft}
\begin{minipage}{\eqboxwidth{tag3}}
\centering
\begin{eqminipage}[c]{tag3}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\caption{Table \#5}
\bigskip

\begin{eqminipage}[c]{tag3}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\caption{Table \#6}
\end{minipage}
\end{mybraceleft}% spaces would be ignored here anyway because of the
% \ignorespacesafterend we used
\hfill
\begin{mybraceright}
\begin{minipage}{\eqboxwidth{tag4}}
\centering
\begin{eqminipage}[c]{tag4}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\caption{Table \#7}
\bigskip

\begin{eqminipage}[c]{tag4}
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|@{}}
\hline
a & b & c & d & e & f & g & h\\
\hline
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
\hline
a & b & c & d & e & f & g & h\\
\hline
\end{tabular}
\end{eqminipage}%
\caption{Table \#8}
\end{minipage}
\end{mybraceright}
\end{table}

\end{document}


• I am wondering if you could solve this problem. – user121799 Aug 8 '19 at 21:46
• @user121799 Well, well, well... I love parsing tasks (cf. link title), unfortunately the question you linked to is about 3D in TikZ and I haven't explored this field yet. I'm not even sure I understand what is missing from the already-accepted answer. I guess it has to do with the internal representation of 3D points in TikZ and how they undergo transformations, but I'm afraid I'm still too ignorant in these areas to contribute. :-/ – frougon Aug 8 '19 at 22:23
• OK, well. Anyway, maybe you can keep this question in the back of your mind if you ever go 3d. It would be great if one could somehow associate three instead of two coordinates to a symbolic coordinate, and if then veclen would spit out the distance between those. And so on. All my attempts to make 3d operations simpler struggled with that obstacle. – user121799 Aug 8 '19 at 23:20
• Thanks. What benefit does this provide that the much simpler alternative doesn't? – voices Aug 9 '19 at 6:53
• I explained the in the answer. 1) The mybraceleft and mybraceright environments allow to very simply brace arbitrary horizontal material (no need to switch to math mode and manually do the work). 2) You don't have to guess a suitable minipage width. 3) The horizontal space next to braces doesn't depend on the braced contents and is customizable (\myhlen). Try with narrower tables and you'll see. 4) The braced contents is tightly boxed (try wrapping it with \frame or adding stuff to its right after narrowing the tables). But you are not forced to use it! – frougon Aug 9 '19 at 7:37