尝试将表格嵌入表格中

尝试将表格嵌入表格中

我正在尝试将一个表添加到另一个表内作为子表来表示其一部分。

特克斯:

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{float} % Better figure and table placements
\usepackage{tabularx}
\usepackage{tabularray}
\usepackage{multirow}
\begin{document}

{\renewcommand{\arraystretch}{1.3}%
    \begin{table}[H]
        \centering
        \small
        \noindent\begin{tabular}{ | p{1cm} | p{1.6cm} | p{11.9cm} |}\hline
            \multicolumn{3}{|l|}{Program requirements} \\ \hline
            Type & Priority  & Requirement \\ \hline
            FR & MUST   & The system must present the user with a feed. \\ \hline
            FR & MUST   & The system must be user-friendly. \\ \hline
            & & \\[-1ex]
            \multicolumn{3}{|c|}{
                \begin{tabular}{ | p{1cm} | p{1.5cm} | p{12cm} |}\hline
                    \multicolumn{3}{|c|}{User module requirements} \\
                    \hline
                    Type & Priority & Requirement \\ \hline
                    FR & MUST & First name property. \\ \hline 
                    FR & MUST & Last name property. \\ \hline
                    FR & MUST & Base class. \\
                    \hline
                \end{tabular}
            } \\[10ex] 
            \hline
        \end{tabular}
\end{table}}

\end{document}

电流输出:

在此处输入图片描述

答案1

这可确保表格适合可用宽度(假设规则宽度为 0.4pt)。我还包含了一些关于您可能想要更改的内容的评论,例如,使用专业样式的表格规则,这意味着没有垂直线和水平线权重的变化。booktabs提供经典的解释和实现。

\documentclass{article}
\usepackage{float} % Better figure and table placements
\usepackage{tabularx}
\usepackage{calc}
\begin{document}

\begin{table}[H]% H is NOT a good idea - if you don't want it to move from here, don't use a float
  \renewcommand{\arraystretch}{1.3}% the group table will limit the effect - no need for another group  
  \centering
  \small
  %\noindent% not necessary with \centering
  % consider using sans serif, especially for column heads
  \begin{tabularx}\linewidth{ | p{1cm} | p{1.6cm} | X |}
    \hline % consider using professional tabular rules e.g. booktabs (but not with vertical lines!)
    \multicolumn{3}{|l|}{Program requirements} \\ \hline
    Type & Priority  & Requirement \\ \hline
    FR & MUST   & The system must present the user with a feed. \\ \hline
    FR & MUST   & The system must be user-friendly. \\\hline
    \multicolumn{3}{|c|}{}\\[-1ex]
    \multicolumn{3}{|c|}{
      \begin{tabularx}{\linewidth-2\tabcolsep-0.8pt}{ | p{1cm} | p{1.5cm} | X |}\hline
        \multicolumn{3}{|c|}{User module requirements} \\
        \hline
        Type & Priority & Requirement \\ \hline
        FR & MUST & First name property. \\ \hline 
        FR & MUST & Last name property. \\ \hline
        FR & MUST & Base class. \\
        \hline
      \end{tabularx}
    } \\[10ex] 
    \hline
  \end{tabularx}
\end{table}

\end{document}

表格适合可用宽度的表格适合

相关内容