LaTeX 表格 - 如何绘制多行单元格?

LaTeX 表格 - 如何绘制多行单元格?

我正在尝试创建一个类似于下面所示的表格。在“描述”列(第 4 列)中,可以看到文本占据多行,而在“过程”列(第 5 列)中,两行位于同一空间中,每个单元格由一条水平线分隔。我该如何实现此效果? 我想要获得的结果

我已经花了好几个小时来研究这个问题,但结果却不太对。

\begin{table}[H]
\begin{tabular}{C{3cm} | C{3cm} | C{4cm} | C{2cm} | C{2cm}}
    \bfseries{Use Case} & \bfseries{Test Case} & \bfseries{Description} & \bfseries{Procedure} & \bfseries{Expected Result} \\ \hline
    \multirow{2}{*}{UC01: Field Creator} & \multirow{2}{*}{TC01: Save a new job} & {Admin creates necessary variables associated with a job and names the job. The admin then saves the file. & Procedure 1 & bla bla bla \\ \cline{4-5}
\end{tabular}
\end{table}

感谢您的耐心和时间。

答案1

一般情况下,您不想将其用作[H]选项tabular

如果您有\multirow,则需要在下一行中有一个“幻像列”。例如,如果您有 ,\multirow{2}{*}{stuff} & more stuff \\则其下方的行需要类似 的内容& second row stuff \\

因此,在您的示例中,您将在第一列中设置六个幻像行。在第二列中,您将有\multirow,其下方有一个幻像列,\multirow其下方有一个幻像列,等等。

表示@{}单元格该侧无填充。而@{\hskip 5pt}表示单元格之间有填充。这是任意的,只是为了从默认填充中稍微减少空间。您可以根据自己的喜好5pt更改值或完全删除。@{\hskip 5pt}

您需要\\在表格中的每一行后面添加 。这里有八行,您将看到八个\\。在您的代码片段中,只有两个\\。(如果您有四行和两个\multirow{2}{...}{...},您仍然需要两个带有 的幻像行/列\\

\documentclass{article}

\usepackage{multirow}


\begin{document}

\begin{table}[htpb]
\begin{tabular}{|@{}p{0.175\textwidth}@{\hskip 5pt}|%
p{0.175\textwidth}@{\hskip 5pt}|%
p{0.175\textwidth}@{\hskip 5pt}|%
p{0.275\textwidth}@{\hskip 5pt}|%
p{0.275\textwidth}@{}|}%
    \hline
    \multicolumn{1}{|c|}{\textbf{Use Case}} & \multicolumn{1}{c|}{\textbf{Test Case}} & \multicolumn{1}{c|}{\textbf{Description}} & \multicolumn{1}{c|}{\textbf{Procedure}} & \multicolumn{1}{c|}{\textbf{Expected Result}} \\
    \hline
    \multirow[t]{7}{0.175\textwidth}{UC01: Field Creator} & \multirow[t]{2}{0.175\textwidth}{TC01: Stuff 1} & \multirow[t]{2}{0.175\textwidth}{two-row description two-row} & one-row procedure one-row & one-row expected result one-row \\
    \cline{4-5}
    &&& one-row procedure one-row &  one-row expected result one-row \\
    \cline{2-5}
    & \multirow[t]{2}{0.175\textwidth}{TC02: Stuff 2} & \multirow[t]{2}{0.175\textwidth}{two-row description two-row} & one-row procedure one-row & one-row expected result one-row \\
    \cline{4-5}
    &&& one-row procedure one-row & one-row expected result one-row \\
    \cline{2-5}
    & \multirow[t]{3}{0.175\textwidth}{TC03: Stuff 3} & \multirow[t]{3}{0.175\textwidth}{three-row description three-row} & one-row procedure & one-row expected result one-row \\
    \cline{4-5}
    &&& one-row procedure one-row & one-row expected result one-row \\
    \cline{4-5}
    &&& one-row procedure one-row & one-row expected result one-row \\
    \hline
\end{tabular}
\end{table}

\end{document}

带有一堆 \multirow 的表格

最后,很多人会告诉你,你不应该在表格中使用垂直线。我之所以添加垂直线,是因为你的图片上有垂直线。我认为在某些情况下使用垂直线是可以的,而且我知道在某些情况下垂直线是必须的。但请注意,这个表格如果只使用水平线看起来会更好,如下面的代码片段所示:

\begin{tabular}{@{}p{0.175\textwidth}@{\hskip 5pt}%
p{0.175\textwidth}@{\hskip 5pt}%
p{0.175\textwidth}@{\hskip 5pt}%
p{0.275\textwidth}@{\hskip 10pt}%
p{0.275\textwidth}@{}}%
    \hline
    \multicolumn{1}{c}{\textbf{Use Case}} & \multicolumn{1}{c}{\textbf{Test Case}} & \multicolumn{1}{c}{\textbf{Description}} & \multicolumn{1}{c}{\textbf{Procedure}} & \multicolumn{1}{c}{\textbf{Expected Result}} \\
    \hline
    \multirow[t]{7}{0.175\textwidth}{UC01: Field Creator} & \multirow[t]{2}{0.175\textwidth}{TC01: Stuff 1} & \multirow[t]{2}{0.175\textwidth}{two-row description two-row} & one-row procedure one-row & one-row expected result one-row \\
    \cline{4-5}
    &&& one-row procedure one-row &  one-row expected result one-row \\
    \cline{2-5}
    & \multirow[t]{2}{0.175\textwidth}{TC02: Stuff 2} & \multirow[t]{2}{0.175\textwidth}{two-row description two-row} & one-row procedure one-row & one-row expected result one-row \\
    \cline{4-5}
    &&& one-row procedure one-row & one-row expected result one-row \\
    \cline{2-5}
    & \multirow[t]{3}{0.175\textwidth}{TC03: Stuff 3} & \multirow[t]{3}{0.175\textwidth}{three-row description three-row} & one-row procedure & one-row expected result one-row \\
    \cline{4-5}
    &&& one-row procedure one-row & one-row expected result one-row \\
    \cline{4-5}
    &&& one-row procedure one-row & one-row expected result one-row \\
    \hline
\end{tabular}

包含多个 \multirow 且无垂直线的表格

相关内容