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!

1
  • 1
    It is possible with the ltablex package, but be aware it won't break the table inside a row.
    – Bernard
    Commented Apr 18, 2018 at 12:34

1 Answer 1

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

11
  • 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
    Commented Apr 18, 2018 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
    Commented Apr 18, 2018 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
    Commented Apr 18, 2018 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
    Commented Apr 18, 2018 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
    Commented Apr 18, 2018 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .