2

I have a table created using tabularx which is too big to fit onto one page. Is is possible to make it break across pages, whilst maintaining the current style?

I have tried to remove the table environment and keep the tabularxas suggested in this link TEX link but still have problems.

MWE:

    \documentclass[a4paper,11pt]{article}
\usepackage{booktabs, makecell, tabularx}
\usepackage{caption}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\tabularxcolumn[1]{m{#1}}

\usepackage[table]{xcolor}

\usepackage{pdflscape,afterpage}

\begin{document}
    \begin{landscape}% Landscape page
\begin{table}[ht]
\caption{Cognitive walkthrough goals, tasks and actions}
\label{table:comparison of techniques}
    \small
    \setlength\extrarowheight{2pt}
\begin{tabularx}{\linewidth}{
       >{\columncolor{red!30}} l
                          *{4}{X}
                            }
    \Xhline{1pt}
    \rowcolor{red!30}
\multicolumn{1}{c}{}
    & \thead{Column 2} & \thead{Column 3}
    & \thead{Column 4} & \thead{Column 5}       \\
    \rowcolor{black}
\multicolumn{5}{l}{\textcolor{white}{Title 1}}  \\
Part 1
    &   To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
        & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
            & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
                & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.                      \\
    \Xhline{0.25pt}
Part 2
   &   To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
        & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
            & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
                & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.                      \\
    \rowcolor{black}
\multicolumn{5}{l}{\textcolor{white}{Title 2}}  \\
Part 3
    &   To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
            & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
                & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
                    & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.                      \\
        \rowcolor{black}
\multicolumn{5}{l}{\textcolor{white}{Title 3}}  \\
Part 1
    &   To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
        & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
            & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
                & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.                      \\
    \Xhline{0.25pt}
Part 2
    &   To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
        & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
            & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
    & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.                      \\
    \Xhline{0.25pt}
Part 3
    &   To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
        & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
            & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
                & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.                      \\
    \Xhline{1pt}
\end{tabularx}%
    \end{table}
\end{landscape}
\end{document}

Picture - current output enter image description here

Grateful for any advice and thanks in advance!

Bernard
  • 271,350
Kevin
  • 367
  • 1
  • 4
  • 16

1 Answers1

2

Here is a code with ltablex. Note the syntax, in particular for the caption, is the same as for longtable (\endhead, \endfoot and the like):

\documentclass[a4paper,11pt]{article}
\usepackage{geometry}
\usepackage{booktabs, makecell, ltablex}
\usepackage{caption}
\renewcommand\theadfont{\small\bfseries \cellcolor{red!30}}
\renewcommand\tabularxcolumn[1]{m{#1}}
\usepackage[usestackEOL]{stackengine}

\usepackage[table]{xcolor}

\usepackage{pdflscape,afterpage}

\begin{document}

    \begin{landscape}% Landscape page
    \small
    \setlength\extrarowheight{2pt}
\begin{tabularx}{\linewidth}{
       >{\columncolor{red!30}} l
                          *{3}{X}X@{}
                            }\caption{Cognitive walkthrough goals, tasks and actions}
\label{table:comparison of techniques}\\
  \Xhline{1pt}
\multicolumn{1}{c}{\cellcolor{red!30}}
    &\thead{Column 2} &\thead{Column 3}
    & \thead{Column 4} &\multicolumn{1}{>{\columncolor{red!30}[6pt][0pt]\bfseries}c@{}}{\Centerstack{Column 5\\Lalala}} \\
    \Xhline{0.25pt}
 \endfirsthead
  \Xhline{1pt}
% \rowcolor{red!30}
\multicolumn{1}{c}{\cellcolor{red!30}}
    &\thead{Column 2} &\thead{Column 3}
    & \thead{Column 4} &\multicolumn{1}{>{\columncolor{red!30}[6pt][0pt]\bfseries}c@{}}{\Centerstack{Column 5\\Lalala}} \\
    \Xhline{0.25pt}
 \endhead
 \Xhline{0.25pt}
 \endfoot
 \Xhline{1pt}
 \endlastfoot
    \rowcolor{black}
\multicolumn{5}{l}{\textcolor{white}{\bfseries Title 1}} \\
Part 1
    & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
        & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
            & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
                & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries. \\
    \Xhline{0.25pt}
Part 2
   & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
        & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
            & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
                & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries. \\
    \rowcolor{black}
\multicolumn{5}{l}{\textcolor{white}{\bfseries Title 2}} \\*
Part 3
    & To make your document look professionally pro\bfseries duced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
            & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
                & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
                    & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries. \\
        \rowcolor{black}
\multicolumn{5}{l}{\textcolor{white}{\bfseries Title 3}} \\
Part 1
    & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
        & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
            & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
                & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries. \\
    \Xhline{0.25pt}
Part 2
    & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
        & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
            & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
    & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries. \\
    \Xhline{0.25pt}
Part 3
    & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
        & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
            & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
                & To make your document look professionally produced, Word provides header, footer, cover page, and text box designs that complement each other. For example, you can add a matching cover page, header, and sidebar. Click Insert and then choose the elements you want from the different galleries.
\end{tabularx}%
% \end{table}
\end{landscape}

\end{document} 

enter image description here enter image description here enter image description here

CarLaTeX
  • 62,716
Bernard
  • 271,350
  • Thank you, the code works perfectly! I have one follow-up query. Is it possible to wrap the text in 'Column 2,3 etc...'? If so, can you direct me to the part of the code which I need to alter? – Kevin Apr 18 '18 at 16:21
  • @Kevin: I'm n't sure to understand fully what you'd like. Do you mean wrap the text in the cells with Column 2, &c. (these marked with \thead)? In the other cells, as we have X columns, that is automatic. – Bernard Apr 18 '18 at 16:36
  • Yes, when I add text to the other cells, it is wrapped nicely (as per your output image). However, if I replace the words 'Column 2' with 'Is the effect of the current action the same as the user's goals' I lose the text wrapping. I am not sure if this is due to the text exceeding column width or the text wrap feature has been lost (the \thead does not seem to work). If you can advise to what I need to change that would be greatly appreciated. – Kevin Apr 18 '18 at 16:47
  • No it's normal: you have to make line breaks by hand (makecellis for use with standard cells, where normally there can be no line break). Other solution: let the cell normal (X type), but add \bfseries. – Bernard Apr 18 '18 at 16:54
  • Thanks! Adding bfseries works for Columns 2-4 but Column 5 is part of a multicolumn. I amended the code to\multicolumn{1}{>{\columncolor{red!30}[6pt][0pt]}c@{}}\bfseries{Will the user understand the feedback?} but this disrupts the the cells directly below it. Have I missed a key step? – Kevin Apr 18 '18 at 17:30
  • No, it's fine. B.t.w. , Column 5 is not a in \thead line the others for colour overflowing outside the table reasons (I've set the last \tabcolsep to 0 in the table preamble). – Bernard Apr 18 '18 at 17:59
  • Ok. But how do I wrap the text in Column 5? Are you able to paste an example code please? – Kevin Apr 18 '18 at 22:08
  • @Kevin: I've updated my code for that. Unforfotunately we can't use a \multicolumn{\thead} in the last column, as makecell has some problems with colouring cells, so I replaced it with\Centerstackfromstackengine`. Please see the updated answer, if it's OK. – Bernard Apr 18 '18 at 22:43
  • many thanks for the updated answer. Unfortunately the problem is unchanged. Centerstack disrupts the cells directly below it. If you replace the text 'Column 5 Lalala' with 'Will the user understand the feedback?', then you will see that the text in the cells below take up half the cell width. – Kevin Apr 19 '18 at 07:37
  • @Kevin: I have no such problem (manually inserting line breaks, of course). Did you compile twice? – Bernard Apr 19 '18 at 08:07
  • I was missing the manual line breaks. The code works perfectly now. Thank you so much! – Kevin Apr 19 '18 at 14:23