2

I would like to create this long table:

enter image description here

enter image description here

  • 3
    Welcome to TeX.SX! What did you try so far in order tom combine \multirow with longtable? You can use the \multirow command 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 at 16:18
  • 1
    What you try so far? – Zarko Jun 21 at 16:27
  • What you mean with "longtable"? That your table is longer than one page? And what is the problem at writing (this relative simply) table. Basic information you can find in en.wikibooks.org/wiki/LaTeX/Tables – Zarko Jun 21 at 17:08
  • Yes, My table is longer than one page. When I add \multyrow in my code in this longtable Latex bring me a error. – Arturo Carretero Simon Jun 21 at 18:28
  • My code is something like this (in a table, no longtable): – Arturo Carretero Simon Jun 21 at 18:31
4
  • 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 xltabular package, which is combination of longtable and tabularx package.
  • Having multirows in long table can cause problems at splitting table between pages. Therefore in the MWE below is used \pagebreak which inserted in table such, that on each page is complete multirow cells:
\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<.

enter image description here

The second page:

enter image description here

| improve this answer | |
1

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}

enter image description here

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}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.