[Tex/LaTex] LaTeX Table – How to draw cells with multiple rows

pdftextables

I am trying to create a table similar to the one that can be seen below. In the Description column (4th column) one can see that the text takes multiple rows whilst in the Procedure column (5th column) there are two rows fitting in the same space with an hline dividing each cell. How may I achieve this effect?
Result that I want to obtain

I've spent hours playing around with this but lines aren't coming right.

\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}

Thanks for your patience and your time.

Best Answer

You don't want to use [H] as an option for tabular, generally.

When you have a \multirow, you need to have a "phantom column" in the next lower row. For example, if you have \multirow{2}{*}{stuff} & more stuff \\ then the row below it requires something like & second row stuff \\.

So, in your example, you'll need six phantom rows in the first column. In the second column, you'll have \multirow, below it a phantom column, below it \multirow, below it a phantom column, etc.

The @{} means no padding on that side of the cell(s). Whereas @{\hskip 5pt} means a padding of 5pt between the cells. This was arbitrary and just to reduce the space slightly from the default padding. You can change the value or delete @{\hskip 5pt} altogether, depending on your preference.

You need \\ after every single row in your table. There are eight rows here, and you'll see eight \\. In your code snippet, there were only two \\. (If you have four rows and two \multirow{2}{...}{...}, you'll still want two phantom rows/columns with \\.

\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}

table with a bunch of \multirow

Lastly, many people will tell you that you shouldn't use vertical lines in your table. I put them in because that's what your image has. I think there are certain case where they are ok, and I know some cases where they are required. But just be aware that this table looks better with only horizontal lines, as in the snippet below:

\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}

table with many \multirow and no vertical lines