I would like to create this long table:
2 Answers
- Please in question always provide MWE (Minimal Working Example), a complete small document which reproduce your problem.
- The MWE must not be presented as an image of your code but must be a copy from the editor Which we can copy in our computers and test as it is.
- I sugest to use
xltabularpackage, which is combination oflongtableandtabularxpackage. - Having
multirows in long table can cause problems at splitting table between pages. Therefore in the MWE below is used\pagebreakwhich inserted in table such, that on each page is completemultirowcells:
\documentclass{article}
\usepackage{geometry}
\usepackage{ragged2e}
\usepackage{multirow, xltabular}
\newcolumntype{L}{>{\RaggedRight}X}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}
\begin{document}
\begin{xltabular}{\linewidth}{| c | l | L |}
\hline
\endfirsthead
\hline
\endhead
%
\multicolumn{3}{|l|}{Test Script} \
\hline
\multirow{6}{}{1}
& Status & \ \cline{2-3}
& Details & \ \cline{2-3}
& Test Data & \ \cline{2-3}
& Expected Result & \ \cline{2-3}
& Actual Result & \ \cline{2-3}
& Issues & \
\hline
\multirow{6}{}{2}
& Status & \ \cline{2-3}
& Details & \ \cline{2-3}
& Test Data & \ \cline{2-3}
& Expected Result & \ \cline{2-3}
& Actual Result & \ \cline{2-3}
& Issues & \
\hline
\multirow{6}{}{3}
& Status & \ \cline{2-3}
& Details & \ \cline{2-3}
& Test Data & \ \cline{2-3}
& Expected Result & \ \cline{2-3}
& Actual Result & \ \cline{2-3}
& Issues & \
\hline
\multirow{6}{}{4}
& Status & \ \cline{2-3}
& Details & \ \cline{2-3}
& Test Data & \ \cline{2-3}
& Expected Result & \ \cline{2-3}
& Actual Result & \ \cline{2-3}
& Issues & \
\hline
\multirow{6}{}{5}
& Status & \ \cline{2-3}
& Details & \ \cline{2-3}
& Test Data & \ \cline{2-3}
& Expected Result & \ \cline{2-3}
& Actual Result & \ \cline{2-3}
& Issues & \
\hline
\multirow{6}{}{6}
& Status & \ \cline{2-3}
& Details & \ \cline{2-3}
& Test Data & \ \cline{2-3}
& Expected Result & \ \cline{2-3}
& Actual Result & \ \cline{2-3}
& Issues & \
\hline
\multirow{6}{*}{7}
& Status & \ \cline{2-3}
& Details & \ \cline{2-3}
& Test Data & \ \cline{2-3}
& Expected Result & \ \cline{2-3}
& Actual Result & \ \cline{2-3}
& Issues & \
\hline
\pagebreak % <---
\multirow{6}{}{8}
& Status & \ \cline{2-3}
& Details & \ \cline{2-3}
& Test Data & \ \cline{2-3}
& Expected Result & \ \cline{2-3}
& Actual Result & \ \cline{2-3}
& Issues & \
\hline
\multirow{6}{}{9}
& Status & \ \cline{2-3}
& Details & \ \cline{2-3}
& Test Data & \ \cline{2-3}
& Expected Result & \ \cline{2-3}
& Actual Result & \ \cline{2-3}
& Issues & \
\hline
\end{xltabular}
\end{document}
The top part of the first page:
The second page:
- 296,517
You should define a command, instead of repeating over and over the same tokens, which is error prone.
The code below is based on Žarko's, but with a trick from longtable multirow problem with cline and nopagebreak to avoid unwanted page breaks.
The macro \block has seven arguments, which can be filled with the actual data in the specified order.
\documentclass{article}
\usepackage{multirow,xltabular}
\makeatletter % https://tex.stackexchange.com/a/52101/4427
\def@cline#1-#2@nil{%
\omit
@multicnt#1%
\advance@multispan\m@ne
\ifnum@multicnt=@ne@firstofone{&\omit}\fi
@multicnt#2%
\advance@multicnt-#1%
\advance@multispan@ne
\leaders\hrule@height\arrayrulewidth\hfill
\cr
\noalign{\nobreak\vskip-\arrayrulewidth}}
\makeatother
\newcommand{\block}[7]{%
% #1 = number, #2 = Status, #3 = Details, #4 = Test Data,
% #5 = Expected Result, #6 = Actual Result, #7 = Issues
\multirow{6}{*}{#1}
& Status & #2 \* \cline{2-3}
& Details & #3 \* \cline{2-3}
& Test Data & #4 \* \cline{2-3}
& Expected Result & #5 \* \cline{2-3}
& Actual Result & #6 \* \cline{2-3}
& Issues & #7 \ \hline
}
\begin{document}
\begin{xltabular}{\textwidth}{|c|l|X|}
\hline
\multicolumn{3}{|l|}{Test Script} \
\hline
\endhead
\block{1}{}{}{}{}{}{}
\block{2}{}{}{}{}{}{}
\block{3}{}{}{}{}{}{}
\block{4}{}{}{}{}{}{}
\block{5}{}{}{}{}{}{}
\block{6}{}{}{}{}{}{}
\block{7}{}{}{}{}{}{}
\block{8}{}{}{}{}{}{}
\block{9}{}{}{}{}{}{}
\block{10}{}{}{}{}{}{}
\block{11}{}{}{}{}{}{}
\block{12}{}{}{}{}{}{}
\block{13}{}{}{}{}{}{}
\block{14}{}{}{}{}{}{}
\block{15}{}{}{}{}{}{}
\end{xltabular}
\end{document}
What's the advantage, besides shortening the input? With just a change to the definition and to the table preamble, you can get a different output.
\documentclass{article}
\usepackage{xltabular,booktabs}
\makeatletter % https://tex.stackexchange.com/a/52101/4427
\def@cline#1-#2@nil{%
\omit
@multicnt#1%
\advance@multispan\m@ne
\ifnum@multicnt=@ne@firstofone{&\omit}\fi
@multicnt#2%
\advance@multicnt-#1%
\advance@multispan@ne
\leaders\hrule@height\arrayrulewidth\hfill
\cr
\noalign{\nobreak\vskip-\arrayrulewidth}}
\makeatother
\newcommand{\block}[7]{%
% #1 = number, #2 = Status, #3 = Details, #4 = Test Data,
% #5 = Expected Result, #6 = Actual Result, #7 = Issues
\multicolumn{2}{l}{\itshape Test #1} \*
Status & #2 \*
Details & #3 \*
Test Data & #4 \*
Expected Result & #5 \*
Actual Result & #6 \*
Issues & #7 \ \midrule
}
\begin{document}
\begin{xltabular}{\textwidth}{lX}
\toprule
\multicolumn{2}{l}{Test Script} \
\midrule
\endhead
\endfoot
\bottomrule
\endlastfoot
\block{1}{}{}{}{}{}{}
\block{2}{}{}{}{}{}{}
\block{3}{}{}{}{}{}{}
\block{4}{}{}{}{}{}{}
\block{5}{}{}{}{}{}{}
\block{6}{}{}{}{}{}{}
\block{7}{}{}{}{}{}{}
\block{8}{}{}{}{}{}{}
\block{9}{}{}{}{}{}{}
\block{10}{}{}{}{}{}{}
\block{11}{}{}{}{}{}{}
\block{12}{}{}{}{}{}{}
\end{xltabular}
\end{document}
- 1,121,712






\multirowwithlongtable? You can use the\multirowcommand inside of a longtable as you can use it inside of a regular tabular environment. However, you should be aware that it might interfere with pagebreaks, so caution there. Probably a customized enumerate list with a nested description list could be an alternative for you? – leandriis Jun 21 '20 at 16:18\begin{document} \begin{longtable}{|l|l|p{7cm}|} \hline \multicolumn{3}{|l|}{multicolumn text here}\ \hline \multirow{6}{*}{1} & text & \ \cline{2-3} & text & \ \cline{2-3} & text & \ \cline{2-3} & text & \ \cline{2-3} & text & \ \cline{2-3} & text & \ \hline \end{longtable} \end{document}` should serve as a place to start from.
– leandriis Jun 21 '20 at 18:51