# Force longtabu width + skip vertical space between tables

Here is an MWE:

\documentclass[10pt]{article}
\usepackage[a6paper]{geometry}
\usepackage{longtable}
\usepackage{tabu}

\begin{document}

\begin{longtabu} to \textwidth {|X|p{10mm}|p{10mm}|p{10mm}|}
\hline
\multicolumn{4}{|p{60mm}|}{
\centering \textbf{W2014-000001}

Heading text for first type: this one has start and end
} \\
\hline
\textbf{Name} & \textbf{Start} & \textbf{End} & \textbf{Value} \\
\hline
\hline
\textbf{Name} & \textbf{Start} & \textbf{End} & \textbf{Value} \\
\hline
Name1 & Start1 & End1 & Val 1 \\ \hline
Name2 & Start2 & End2 & Val 2 \\ \hline
Name3 & Start3 & End3 & Val 3 \\ \hline
Name X & StartX & EndX & ValX \\ \hline
\end{longtabu}

\begin{longtabu} to \textwidth {|X|p{10mm}|p{10mm}|p{10mm}|}
\hline
\multicolumn{4}{|p{60mm}|}{
\centering \textbf{W2014-000002}

Heading text for second type: it has longer names
} \\
\hline
\multicolumn{3}{|p{50mm}|}{\textbf{Long name}} & \textbf{Value} \\
\hline
\hline
\multicolumn{3}{|p{50mm}|}{\textbf{Long name}} & \textbf{Value} \\
\hline
\multicolumn{3}{|p{50mm}|}{This is a bit longer name 1} & Value1 \\ \hline
\multicolumn{3}{|p{50mm}|}{This is a bit longer name 2} & Value2 \\ \hline
\multicolumn{3}{|p{50mm}|}{This is a bit longer name 3} & Value3 \\ \hline
\multicolumn{3}{|p{50mm}|}{This is a bit longer name X} & ValueX \\ \hline
\end{longtabu}

\end{document}


Looks like this:

I want to make them the very same width, and also have zero vertical space between them. In other words, they should look like a single table. Using a single longtabu is not an option, because first heading and other headings are different for the two tables! I wonder why it is not stretching to \textwidth?

• the second table has no X column to allow it to stretch. (You have one in the preamble for the first column but that is never used as you replace every entry with \multicolumn – David Carlisle Sep 13 '14 at 13:52
• If I use \multicolumn{4}{|X|} instead of \multicolumn{4}{|p{60mm}|} then I get an error "Illegal pream-token (X): c' used.", so how do I add stretching to a multicolumn? – nagylzs Sep 13 '14 at 14:01
• why use multicolumn at all the second table could just be {Xp{10mm}} no reason to put \multicolumn in every cell – David Carlisle Sep 13 '14 at 22:05
• You are right, although this was just a MWE. In fact I have many columns, some are stretching some are not. Creating expressions manually like the one Harish recommended, and using them in each and every cell is a burden. But since I'm generating the file from a program, I can live with it. – nagylzs Sep 14 '14 at 6:48

Here is some dirty method. you have to use proper widths

\documentclass[10pt]{article}
\usepackage[a6paper]{geometry}
\usepackage{longtable}
\usepackage{tabu}
\tabulinesep = 1mm    %% for better look

\begin{document}

\begin{longtabu} to \textwidth {|X|p{10mm}|p{10mm}|p{10mm}|}
\hline
\multicolumn{4}{|p{\linewidth}|}{
\centering \textbf{W2014-000001}

Heading text for first type: this one has start and end
} \\
\hline
\textbf{Name} & \textbf{Start} & \textbf{End} & \textbf{Value} \\
\hline
\hline
\textbf{Name} & \textbf{Start} & \textbf{End} & \textbf{Value} \\
\hline
Name1 & Start1 & End1 & Val 1 \\ \hline
Name2 & Start2 & End2 & Val 2 \\ \hline
Name3 & Start3 & End3 & Val 3 \\ \hline
Name X & StartX & EndX & ValX \\ \hline
\end{longtabu}
\vskip-2\baselineskip
\begin{longtabu} to \textwidth {|X|p{10mm}|p{10mm}|p{10mm}|}
%\hline
\multicolumn{4}{|p{\linewidth}|}{
\centering \textbf{W2014-000002}

Heading text for second type: it has longer names
} \\
\hline
\multicolumn{3}{|p{0.8\hsize}|}{\textbf{Long name}} & \textbf{Value} \\
\hline
\hline
\multicolumn{3}{|p{0.8\hsize}|}{\textbf{Long name}} & \textbf{Value} \\
\hline
\multicolumn{3}{|p{0.8\hsize}|}{This is a bit longer name 1} & Value1 \\ \hline
\multicolumn{3}{|p{0.8\hsize}|}{This is a bit longer name 2} & Value2 \\ \hline
\multicolumn{3}{|p{0.8\hsize}|}{This is a bit longer name 3} & Value3 \\ \hline
\multicolumn{3}{|p{0.8\hsize}|}{This is a bit longer name X} & ValueX \\ \hline
\end{longtabu}

\end{document}


• Thanks. I did not know that I had to use \linewidth instead of X within a multicolumn. Sometimes LaTeX is not straightforward to me. Long learning curve. But this is still the best. – nagylzs Sep 13 '14 at 14:25
• Is there a way to use 10mm column on the right and the remaining space on the left? I understand that 0.8\hsize kinda works. But this was just an MWE. In reality, I have more columns and in some cases, I will have to specify column widths in absolute values. – nagylzs Sep 13 '14 at 15:26
• @nagylzs: Use p{\dimexpr\linewidth-10mm-4\tabcolsep-3\arrayrulewidth\relax} instead of p{0.8\hsize} (where 10mm` is the width of right column). – user11232 Sep 13 '14 at 15:44
• Okay, so if I have more than one stretching X columns and many more fixed ones, then I have to figure out the right formula and manually enter that into each cell? Is there a better way? :s – nagylzs Sep 13 '14 at 16:15
• Something like \mymulticolumn{2}{content here} that would calculate the dimension expression for that 2 columns? – nagylzs Sep 13 '14 at 16:16