强制 longtabu 宽度 + 跳过表格之间的垂直空间

强制 longtabu 宽度 + 跳过表格之间的垂直空间

以下是 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
    \endfirsthead
    \hline
    \textbf{Name} & \textbf{Start} & \textbf{End} & \textbf{Value} \\
    \hline
    \endhead
    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
    \endfirsthead
    \hline
    \multicolumn{3}{|p{50mm}|}{\textbf{Long name}} & \textbf{Value} \\
    \hline
    \endhead
    \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}

看起来像这样:

在此处输入图片描述

我想让它们宽度完全相同,并且它们之间没有垂直间距。换句话说,它们应该看起来像一个表格。使用单个 longtabu 不是一个选择,因为两个表格的第一个标题和其他标题是不同的!我想知道为什么它没有拉伸到 \textwidth?

答案1

这是一些肮脏的方法。你必须使用适当width

\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
    \endfirsthead
    \hline
    \textbf{Name} & \textbf{Start} & \textbf{End} & \textbf{Value} \\
    \hline
    \endhead
    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
    \endfirsthead
    \hline
    \multicolumn{3}{|p{0.8\hsize}|}{\textbf{Long name}} & \textbf{Value} \\
    \hline
    \endhead
    \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}

在此处输入图片描述

相关内容