0

I apologise - I realise this has been asked a million times already, but I've been struggling as I'm not very well-versed in LaTeX.

I have a wide table that goes over several pages that I am trying to fit onto the page. I have re-created the table with dummy text (and many rows shorter).

Copy-pasting from excel into word tells me that it should fit on an A4 page when everything wraps. desired output

But this is the output I get in overleaf

output

I've made this using a table generator, which has worked well for me for other tables.

I'm currently not concerned about the text on the second page floating up - I've had that before and I just force a page break to fix that (or the missing backslash for leftrightarrow - that's just a find/replace job)

I guess I'm trying to figure out how to get the contents of the columns to wrap?

Finally, the code: I used this template (which in hindsight I now very much regret)

\documentclass[
11pt, % The default document font size, options: 10pt, 11pt, 12pt
oneside, % Two side (alternating margins) for binding by default, uncomment to switch to one side
english, % ngerman for German
doublespacing, % Single line spacing, alternatives: onehalfspacing or doublespacing
%draft, % Uncomment to enable draft mode (no pictures, no links, overfull hboxes indicated)
nolistspacing, % If the document is onehalfspacing or doublespacing, uncomment this to set spacing in lists to single
liststotoc, % Uncomment to add the list of figures/tables/etc to the table of contents
%toctotoc, % Uncomment to add the main table of contents to the table of contents
parskip, % Uncomment to add space between paragraphs
%nohyperref, % Uncomment to not load the hyperref package
headsepline, % Uncomment to get a line under the header
%chapterinoneline, % Uncomment to place the chapter title next to the number on one line
consistentlayout, % Uncomment to change the layout of the declaration, abstract and acknowledgements pages to match the default layout
]{MastersDoctoralThesis} % The class file specifying the document structure

\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{lscape}
\usepackage{longtable}
\usepackage{pdflscape}
% i think these are all the relevant packages to my question - there are a lot in the preamble since it's a whole thesis using a template 

\begin{landscape}
\begin{longtable}[c]{|c|c|c|c|c|c|c|c|c|c|}
\caption{}
\label{tab:my-table}\\
\hline
\rowcolor[HTML]{D0CECE} 
\textbf{Reference} &
  \textbf{Column 1} &
  \textbf{Column 2 that is   descriptive} &
  \textbf{Column 3 that   also contains more information and is long} &
  \textbf{Column 4 is also   long and needs space} &
  \textbf{Column 5} &
  \textbf{Column 6} &
  \textbf{Column 7} &
  \textbf{Column 8 ABC} &
  \textbf{Column9 ABCDE} \\ \hline
\endhead
%
 &
   &
   &
   &
   &
   &
  Male &
  ↑   Result &
   &
  results   that are a little long too \\ \cline{7-8} \cline{10-10} 
\multirow{-2}{*}{Smith et al., 2004} &
  \multirow{-2}{*}{Rat Rat Mouse} &
  \multirow{-2}{*}{Stress Type} &
  \multirow{-2}{*}{short description} &
  \multirow{-2}{*}{ABC} &
  \multirow{-2}{*}{PND100} &
  Female &
  leftrightarrow No Change &
  \multirow{-2}{*}{description that is a bit long to add detail} &
  results   that are a little longer and need to go here too ABCD 1234 \\ \hline
Smith et al., 2004 &
  Rat   Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  NOT   TESTED &
  NOT   TESTED \\ \hline
Smith et al., 2004 &
  Rat Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  description   that is a bit long to add detail &
  results   that are a little long too \\ \hline
 &
   &
   &
   &
   &
   &
  Male &
  leftrightarrow No Change &
   &
  results   that are a little long too \\ \cline{7-8} \cline{10-10} 
\multirow{-2}{*}{Smith et al., 2004} &
  \multirow{-2}{*}{Rat Rat Mouse} &
  \multirow{-2}{*}{Stress Type} &
  \multirow{-2}{*}{long description bla bla bla bla} &
  \multirow{-2}{*}{ABC} &
  \multirow{-2}{*}{PND100} &
  Female &
  ↑   Result &
  \multirow{-2}{*}{description that is a bit long to add detail} &
  leftrightarrow No Change \\ \hline
 &
   &
   &
   &
   &
   &
  Male &
  ↑   Result &
   &
   \\ \cline{7-8}
\multirow{-2}{*}{Smith et al., 2004} &
  \multirow{-2}{*}{Rat Rat Mouse} &
  \multirow{-2}{*}{Stress Type} &
  \multirow{-2}{*}{long description bla bla bla bla} &
  \multirow{-2}{*}{ABC} &
  \multirow{-2}{*}{PND100} &
  Female &
  ↑   Result &
  \multirow{-2}{*}{NOT TESTED} &
  \multirow{-2}{*}{NOT TESTED} \\ \hline
 &
   &
   &
  long   description bla bla bla bla &
   &
   &
  Male &
  ↑   Result &
   &
  results   that are a little longer and need to go here too ABCD 1234 \\ \cline{4-4} \cline{7-8} \cline{10-10} 
\multirow{-2}{*}{Smith et al., 2004} &
  \multirow{-2}{*}{Rat Rat Mouse} &
  \multirow{-2}{*}{Stress Type} &
  long description bla bla bla bla &
  \multirow{-2}{*}{ABC} &
  \multirow{-2}{*}{PND100 but more detail required} &
  Female &
  leftrightarrow No Change &
  \multirow{-2}{*}{description that is a bit long to add detail} &
  results   that are a little longer and need to go here too ABCD 1234 \\ \hline
 &
   &
   &
  long   description bla bla bla bla &
   &
   &
  Male &
  leftrightarrow No Change &
   &
  results   that are a little longer and need to go here too ABCD 1234 \\ \cline{4-4} \cline{7-8} \cline{10-10} 
\multirow{-2}{*}{Smith et al., 2004} &
  \multirow{-2}{*}{Rat Rat Mouse} &
  \multirow{-2}{*}{Stress Type} &
  long description bla bla bla bla &
  \multirow{-2}{*}{ABC} &
  \multirow{-2}{*}{PND100 but more detail required} &
  Female &
  ↑   Result &
  \multirow{-2}{*}{description that is a bit long to add detail} &
  results   that are a little longer and need to go here too ABCD 1234 \\ \hline
 &
   &
   &
  long   description bla bla bla bla &
   &
   &
  Male &
  leftrightarrow No Change &
   &
  results   that are a little longer and need to go here too ABCD 1234 \\ \cline{4-4} \cline{7-8} \cline{10-10} 
\multirow{-2}{*}{Smith et al., 2004} &
  \multirow{-2}{*}{Rat Rat Mouse} &
  \multirow{-2}{*}{Stress Type} &
  long description bla bla bla bla &
  \multirow{-2}{*}{ABC} &
  \multirow{-2}{*}{PND100 but more detail required} &
  Female &
  ↑   Result &
  \multirow{-2}{*}{description that is a bit long to add detail} &
  results   that are a little longer and need to go here too ABCD 1234 \\ \hline
 &
   &
   &
  long   description bla bla bla bla &
   &
   &
  Male &
  leftrightarrow No Change &
   &
  results   that are a little longer and need to go here too ABCD 1234 \\ \cline{4-4} \cline{7-8} \cline{10-10} 
\multirow{-2}{*}{Smith et al., 2004} &
  \multirow{-2}{*}{Rat Rat Mouse} &
  \multirow{-2}{*}{Stress Type} &
  long description bla bla bla bla &
  \multirow{-2}{*}{ABC} &
  \multirow{-2}{*}{PND100 but more detail required} &
  Female &
  ↑   Result &
  \multirow{-2}{*}{description that is a bit long to add detail} &
  results   that are a little longer and need to go here too ABCD 1234 \\ \hline
 &
   &
   &
  long   description bla bla bla bla &
   &
   &
  Male &
  leftrightarrow No Change &
   &
  results   that are a little longer and need to go here too ABCD 1234 \\ \cline{4-4} \cline{7-8} \cline{10-10} 
\multirow{-2}{*}{Smith et al., 2004} &
  \multirow{-2}{*}{Rat Rat Mouse} &
  \multirow{-2}{*}{Stress Type} &
  long description bla bla bla bla &
  \multirow{-2}{*}{ABC} &
  \multirow{-2}{*}{PND100 but more detail required} &
  Female &
  ↑   Result &
  \multirow{-2}{*}{description that is a bit long to add detail} &
  results   that are a little longer and need to go here too ABCD 1234 \\ \hline
\end{longtable}
\end{landscape}

\end{document}

3
  • Can you please complete your given code to be compilable? Then we do not have to guess what you are doing....
    – Mensch
    Dec 7, 2022 at 23:00
  • 1
    @Mensch sorry I'm a newbie - what do you mean? I copied the whole thing in...
    – DS14
    Dec 7, 2022 at 23:06
  • We nned to know which documentclass and which options and which packages you are using. Then we can copy the code and test it on the own computer without guessing ...
    – Mensch
    Dec 7, 2022 at 23:18

1 Answer 1

1
  • You use private documentclass. Instead it I use book and define page layout with geometry package.
  • Your table is very large, so you need to do the following:
    • reduce font size
    • allow line breaks in cell with defined column types with prescribed column width
    • replace \multirow{...}{*}{...} with \multirow{-1}{=}{Rat Rat Mouse} when text in this cell has only one line or width \multirow{-1}[<number of lines in cell]{=}{Rat Rat Mouse}
    • redefine horizontal alignment in €multirow cells with \renewcommand\multirowsetup{\centering} before table

With correcting all errors in table and defining column width with trial and correcting errors, MWE can be:

\documentclass[11pt]{book} % The class file specifying the document structure
\usepackage[margin=20mm]{geometry}
\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{lscape}
\usepackage{longtable}
\usepackage{pdflscape}
% i think these are all the relevant packages to my question - there are a lot in the preamble since it's a whole thesis using a template
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}
\begin{landscape}
\footnotesize
\setlength\tabcolsep{3pt}
\setlength\extrarowheight{2pt}
\renewcommand\multirowsetup{\centering}
\begin{longtable}{|C{5.5em}|C{5.5em}|C{6em}
                  |C{9em}|  C{8em}|  C{5em}|
                  c|        C{5em}|  C{7em}|
                  C{10em}|}
\caption{}
\label{tab:my-table}\\
\hline
\rowcolor[HTML]{D0CECE}
\textbf{Reference} &
  \textbf{Column 1} &
  \textbf{Column 2 that is   descriptive} &
  \textbf{Column 3 that   also contains more information and is long} &
  \textbf{Column 4 is also   long and needs space} &
  \textbf{Column 5} &
  \textbf{Column 6} &
  \textbf{Column 7} &
  \textbf{Column 8 ABC} &
  \textbf{Column 9 ABCDE} \\ \hline
\endhead
%
    &   &   &   &   &   & Male
                            & Result
                                &   &   results that are a
                                        little long too     \\
    \cline{7-8} \cline{10-10}
\multirow{-1}[2]{=}{Smith et al., 2004} &
  \multirow{-1}[2]{=}{Rat Rat Mouse} &
  \multirow{-1}{=}{Stress Type} &
  \multirow{-1}{=}{short description} &
  \multirow{-1}{=}{ABC} &
  \multirow{-1}{=}{PND100} &
  Female &
  $\leftrightarrow$ No Change &
  \multirow{-1}[4]{=}{description that is a bit long to add detail} &
  results   that are a little longer and need to go here too ABCD 1234 \\ \hline
  \hline
Smith et al., 2004 &
  Rat   Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  NOT   TESTED &
  NOT   TESTED \\ \hline
Smith et al., 2004 &
  Rat Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  description   that is a bit long to add detail &
  results   that are a little long too          \\
  \hline
     &   &   &   &   &   & Male
                            & Result
                                &   &   results that are a
                                        little long too     \\
    \cline{7-8} \cline{10-10}
\multirow{-1}[2]{=}{Smith et al., 2004} &
  \multirow{-1}[2]{=}{Rat Rat Mouse} &
  \multirow{-1}{=}{Stress Type} &
  \multirow{-1}{=}{short description} &
  \multirow{-1}{=}{ABC} &
  \multirow{-1}{=}{PND100} &
  Female &
  $\leftrightarrow$ No Change &
  \multirow{-1}[4]{=}{description that is a bit long to add detail} &
  results   that are a little longer and need to go here too ABCD 1234 \\ \hline
  \hline
Smith et al., 2004 &
  Rat   Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  NOT   TESTED &
  NOT   TESTED \\ \hline
Smith et al., 2004 &
  Rat Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  description   that is a bit long to add detail &
  results   that are a little long too          \\
  \hline
    &   &   &   &   &   & Male
                            & Result
                                &   &   results that are a
                                        little long too     \\
    \cline{7-8} \cline{10-10}
\multirow{-1}[2]{=}{Smith et al., 2004} &
  \multirow{-1}[2]{=}{Rat Rat Mouse} &
  \multirow{-1}{=}{Stress Type} &
  \multirow{-1}{=}{short description} &
  \multirow{-1}{=}{ABC} &
  \multirow{-1}{=}{PND100} &
  Female &
  $\leftrightarrow$ No Change &
  \multirow{-1}[4]{=}{description that is a bit long to add detail} &
  results   that are a little longer and need to go here too ABCD 1234 \\ \hline
  \hline
Smith et al., 2004 &
  Rat   Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  NOT   TESTED &
  NOT   TESTED \\ \hline
Smith et al., 2004 &
  Rat Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  description   that is a bit long to add detail &
  results   that are a little long too          \\
  \hline
    &   &   &   &   &   & Male
                            & Result
                                &   &   results that are a
                                        little long too     \\
    \cline{7-8} \cline{10-10}
\multirow{-1}[2]{=}{Smith et al., 2004} &
  \multirow{-1}[2]{=}{Rat Rat Mouse} &
  \multirow{-1}{=}{Stress Type} &
  \multirow{-1}{=}{short description} &
  \multirow{-1}{=}{ABC} &
  \multirow{-1}{=}{PND100} &
  Female &
  $\leftrightarrow$ No Change &
  \multirow{-1}[4]{=}{description that is a bit long to add detail} &
  results   that are a little longer and need to go here too ABCD 1234 \\ \hline
  \hline
Smith et al., 2004 &
  Rat   Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  NOT   TESTED &
  NOT   TESTED \\ \hline
Smith et al., 2004 &
  Rat Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  description   that is a bit long to add detail &
  results   that are a little long too          \\
  \hline
    &   &   &   &   &   & Male
                            & Result
                                &   &   results that are a
                                        little long too     \\
    \cline{7-8} \cline{10-10}
\multirow{-1}[2]{=}{Smith et al., 2004} &
  \multirow{-1}[2]{=}{Rat Rat Mouse} &
  \multirow{-1}{=}{Stress Type} &
  \multirow{-1}{=}{short description} &
  \multirow{-1}{=}{ABC} &
  \multirow{-1}{=}{PND100} &
  Female &
  $\leftrightarrow$ No Change &
  \multirow{-1}[4]{=}{description that is a bit long to add detail} &
  results   that are a little longer and need to go here too ABCD 1234 \\ \hline
  \hline
Smith et al., 2004 &
  Rat   Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  NOT   TESTED &
  NOT   TESTED \\ \hline
Smith et al., 2004 &
  Rat Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  description   that is a bit long to add detail &
  results   that are a little long too          \\
  \hline
    &   &   &   &   &   & Male
                            & Result
                                &   &   results that are a
                                        little long too     \\
    \cline{7-8} \cline{10-10}
\multirow{-1}[2]{=}{Smith et al., 2004} &
  \multirow{-1}[2]{=}{Rat Rat Mouse} &
  \multirow{-1}{=}{Stress Type} &
  \multirow{-1}{=}{short description} &
  \multirow{-1}{=}{ABC} &
  \multirow{-1}{=}{PND100} &
  Female &
  $\leftrightarrow$ No Change &
  \multirow{-1}[4]{=}{description that is a bit long to add detail} &
  results   that are a little longer and need to go here too ABCD 1234 \\ \hline
  \hline
Smith et al., 2004 &
  Rat   Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  NOT   TESTED &
  NOT   TESTED \\ \hline
Smith et al., 2004 &
  Rat Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  description   that is a bit long to add detail &
  results   that are a little long too          \\
  \hline
    &   &   &   &   &   & Male
                            & Result
                                &   &   results that are a
                                        little long too     \\
    \cline{7-8} \cline{10-10}
\multirow{-1}[2]{=}{Smith et al., 2004} &
  \multirow{-1}[2]{=}{Rat Rat Mouse} &
  \multirow{-1}{=}{Stress Type} &
  \multirow{-1}{=}{short description} &
  \multirow{-1}{=}{ABC} &
  \multirow{-1}{=}{PND100} &
  Female &
  $\leftrightarrow$ No Change &
  \multirow{-1}[4]{=}{description that is a bit long to add detail} &
  results   that are a little longer and need to go here too ABCD 1234 \\ \hline
  \hline
Smith et al., 2004 &
  Rat   Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  NOT   TESTED &
  NOT   TESTED \\ \hline
Smith et al., 2004 &
  Rat Rat Mouse &
  Stress   Type &
  long   description bla bla bla bla &
  ABC &
  PND100 &
  Male &
  ↑   Result &
  description   that is a bit long to add detail &
  results   that are a little long too          \\
  \hline
\end{longtable}
\end{landscape}
\end{document}

enter image description here

2
  • thank you @Zarko ! I haven't had a chance to try this yet, but will this work in the longtable environment as I have many, many rows?
    – DS14
    Dec 8, 2022 at 9:52
  • @DS14, MWE use longtable table. This means, that table can span as many pages as you wish. Table in it span two pages, but I show only first. Since your document example you not define first head, first foot and last foot, I also left them out. If you interested for them, I can add them to my MWE.
    – Zarko
    Dec 8, 2022 at 16:11

You must log in to answer this question.

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