align columns in multiple tables
What you describe is basically what longtable
does internally so that the various parts of the table line up, so it is fairly easy to use longtable but redefine things so the two tables share longtable width data:
\documentclass{article}
\usepackage{longtable}
\makeatletter
\def\dontchopLT{\let\LT@entry@chop\relax}
\def\resumeLT{%
\let\zzz\stepcounter
\def\yyy{LT@tables}
\def\stepcounter##1{%
\def\xxx{##1}%
\ifx\xxx\yyy\else\zzz{##1}\fi}}
\makeatother
\begin{document}
Output both tables together as one table and then output each
individual table. We had hoped that this would cause the subsequent
tables to be the same width as the first since the first contains all
columns of the subsequent tables but it seems that that does not work.
\noindent X\dotfill X
{\dontchopLT
\begin{longtable}{ll}
1 & 2 \\
3 & 4 \\
\end{longtable}}
\noindent X\dotfill X
{\resumeLT
\begin{longtable}{ll}
abcdefghijklmnopqrstuvwxyz & 10 \\
5 & 6 \\
\end{longtable}}
\end{document}
The tabu
environment will need to use the X columns in order to be able to scale them and remember the calculations with savetabu
.
since you do not want the table to occupy the full line width, you can use the spread
definition with a value a 0pt
and have your X
columns with a negative coefficient:
\begin{tabu} spread 0pt {|X[-1]|X[-1]|}\savetabu{mytabu2}
1 & 2 \\
3 & 4 \\
abcdefghijklmnopqrstuvwxyz & 10 \\
5 & 6 \\
\end{tabu}
\end{center}
\begin{center}
\begin{tabu}{\usetabu{mytabu2}}
1 & 2 \\
3 & 4 \\
\end{tabu}
\end{center}
\begin{center}
\begin{tabu}{\usetabu{mytabu2}}
abcdefghijklmnopqrstuvwxyz & 10 \\
5 & 6 \\
\end{tabu}