如何使乳胶表中的多列延伸到多行而不超出页面边缘

如何使乳胶表中的多列延伸到多行而不超出页面边缘

我有一张长表,我想让最上面一行跨越多行,这样我就可以输入表格的详细描述,而不会使文本重叠并消失在边框的边缘。

我该如何实现这一点?我已尝试以下方法并提供我获得的当前输出?

 \FloatBarrier
    \begin{longtable}[H]{|>{\RaggedRight}p{3.0cm}|p{9.7cm}|}
    \caption{Requirements \cite{ref-book-3-2}.\label{tab1}} 
    \hline
     \multicolumn{2}{|c|}{Here I put the detailed description of the table, and i want to stretch over multiple rows as there is a lot of text that must fit without overshooting the edge of the pages} \\
    \hline
    \textbf{Feature} & \textbf{Requirement}\\
    \hline
    One & Requirement 4 \\
    \hline
    Two & Requirement 4 \\
    \hline
    Three & Requirement 4 \\
    \hline
    Four & Requirement 4 \\
    \hline
    \end{longtable}

输出显示顶行不符合宽度内的描述,如下所示在此处输入图片描述

答案1

使用新的表格包tabullarray很简单。多列单元格的宽度可以通过选项自动确定hspan=minimal

\documentclass{article}
\usepackage{tabularray}
\usepackage{xcolor}

\begin{document}
    \begin{longtblr}[caption={Requirements \cite{ref-book-3-2}},
                    \label={tab1}
                    ]%
                    {hlines, vlines,
                     hspan=minimal,     % <---
                     colspec={X[1,l] X[3,l]},
                     row{2} = {font=\bfseries}
                    }
\SetCell[c=2]{l}
    Here I put the detailed description of the table, and I want to stretch over multiple rows as there is a lot of text that must fit without overshooting the edge of the pages
        &                   \\
Feature &   Requirement     \\
One     &   Requirement 1   \\
Two     &   Requirement 2   \\
Three   &   Requirement 3   \\
Four    &   Requirement 4   \\
    \end{longtblr}
\end{document}

在此处输入图片描述

答案2

很容易确定p表头列宽的准确值:

\documentclass[]{article}
\usepackage{ragged2e} 
\usepackage{array, longtable}
\setlength{\extrarowheight}{2pt}

\begin{document}

 \begin{longtable}{|>{\RaggedRight}p{3.0cm}|p{9.7cm}|}
\caption{Requirements \cite{ref-book-3-2}.\label{tab1}}\\
\hline
 \multicolumn{2}{| p{\dimexpr12.7cm + 2\tabcolsep + \arrayrulewidth}|}{Here I put the detailed description of the table, and I want to stretch over multiple rows as there is a lot of text that must fit without overshooting the edge of the pages} \\
\hline
\textbf{Feature} & \textbf{Requirement}\\
\hline
One & Requirement 4 \\
\hline
Two & Requirement 4 \\
\hline
Three & Requirement 4 \\
\hline
Four & Requirement 4 \\
\hline
\end{longtable}

\end{document} 

在此处输入图片描述

相关内容