0

I'm relatively new to LaTeX, but I have been using it successfully for the past few months. Right now, I'm collaborating on a book chapter with people from four different countries. This is one of the reasons for me to switch to LaTeX and Overleaf: no more Word files being sent back and forth and having the need to wait for someone's contributions in order to keep your own work. Of course, I could use Google Docs or something like that, but I'm sure I don't need to defend LaTeX as the best option here, hehe.

So, I was trying to rebuild our chapter in LaTeX and almost everything went very smoothly. I've downloaded the Springer Book Chapter Template, as they will be the ones publishing the book, and then went to create the file with all the images, tables and everything else that was needed. The problem was, by the end of the chapter I have an annexe with four long tables with lots of text, and I can't seem to find a way to make it work. Usually, I can find the answers to most of my doubts here, at Stackexchange, but one problem has been quite impossible to deal with: creating long, wide tables, with lots of text in them.

Each table is structured like this:

Table example

And here is the minimum working code for this:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{longtable}

\begin{document}

\begin{longtable}[c]{@{}|l|l|l|l|l|@{}}
\caption{My table caption here}
\label{tab:table1}\\
\toprule
 &
  Category 1 &
  Category 2 &
  Category 3 &
  Category 4 \\* \midrule
\endfirsthead
%
\endhead
%
\begin{tabular}[c]{@{}l@{}}First \\ Subcategory\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\\ Topic 3\\ Topic 4\\ Topic 5\\ Topic 6\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\\ Topic 3\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\end{tabular} &
  \multirow{5}{*}{Topic 1} \\* \cmidrule(r){1-4}
\begin{tabular}[c]{@{}l@{}}Second\\ Subcategory\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\\ Topic 3\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\\ Topic 3\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\end{tabular} &
   \\* \cmidrule(r){1-4}
\begin{tabular}[c]{@{}l@{}}Third\\ Subcategory\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\\ Topic 3\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\end{tabular} &
   \\* \cmidrule(r){1-4}
\begin{tabular}[c]{@{}l@{}}Fourth\\ Subcategory\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\\ Topic 3\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\\ Topic 3\\ Topic 4\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\end{tabular} &
   \\* \cmidrule(r){1-4}
\begin{tabular}[c]{@{}l@{}}Fifth\\ Subcategory\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\\ Topic 3\\ Topic 4\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Topic 1\\ Topic 2\\ Topic 3\\ Topic 4\\ Topic 5\\ Topic 6\end{tabular} &
   \\* \bottomrule
\end{longtable}
\footnotesize{Here I have a table footnote, of about 50 words}
\end{document}

The problem is that each one of the "Topics" is a sentence from 15 to 30 words. So, in my original Word document, each table takes two pages (portrait orientation), but I've tried a lot of things to make it work within LaTeX without success: landscape environment, make cell, tabulary, resize box, etc.

Here is the minimum working code with sentences around the size they would have in the final version:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{longtable}

\begin{document}

\begin{longtable}[c]{@{}|l|l|l|l|l|@{}}
\caption{My table caption here}
\label{tab:table1}\\
\toprule
 &
  Category 1 &
  Category 2 &
  Category 3 &
  Category 4 \\* \midrule
\endfirsthead
%
\endhead
%
\begin{tabular}[c]{@{}l@{}}First \\ Subcategory\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  3\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  4\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  5\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  6\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  3\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\end{tabular} &
  \multirow{5}{*}{Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1} \\* \cmidrule(r){1-4}
\begin{tabular}[c]{@{}l@{}}Second\\ Subcategory\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  3\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  3\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\end{tabular} &
   \\* \cmidrule(r){1-4}
\begin{tabular}[c]{@{}l@{}}Third\\ Subcategory\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  3\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\end{tabular} &
   \\* \cmidrule(r){1-4}
\begin{tabular}[c]{@{}l@{}}Fourth\\ Subcategory\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  3\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  3\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  4\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\end{tabular} &
   \\* \cmidrule(r){1-4}
\begin{tabular}[c]{@{}l@{}}Fifth\\ Subcategory\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  3\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  4\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  3\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  4\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  5\\ Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  6\end{tabular} &
   \\* \bottomrule
\end{longtable}
\footnotesize{Sed volutpat erat eget sem eleifend imperdiet. Integer convallis iaculis pretium. Aenean sed dui nec libero rhoncus ultricies at a ex. Nulla facilisi. Phasellus non dui ultrices, viverra lacus vel, pharetra massa. Vivamus quis hendrerit justo, sed vestibulum felis. Suspendisse sit amet lacinia sapien. Nunc mi felis, tristique eu volutpat.}
\end{document}

So, any help will be very much appreciated. The most straightforward approach would be to replicate in LaTeX what I have in word (a two-page table in portrait orientation), but I could go landscape, single page, etc. In fact, I would welcome any suggestion not only about how to code the desired table, but also to alternative ways to better present this type of information in LaTeX (considering each of the tables is actually a matrix).

Thanks in advance,

André Brasil

4
  • 2
    l is for one-line entries use >{\RaggedRight}p{3cm} or whatever width you want for the columns (ragged2e package for the \RaggedRight variant of \raggedright) Jun 27, 2020 at 11:28
  • Horizontal lines from the booktabs package are intended to be used without vertical lines. This is the reason for the small gaps in the vertical lines around the intersections.
    – leandriis
    Jun 27, 2020 at 11:29
  • How to make your table fit into the available space depends a lot on the amount of space that is actually available to you. The documentclass that you actually use might play an important role here. Judjing from the MWE you included, I would say you will have quite a hard time even fitting the first subcategory part onto a single page, let alone even more of the table.
    – leandriis
    Jun 27, 2020 at 11:35
  • Probably a list of some kind would be better suited to present the information.
    – leandriis
    Jun 27, 2020 at 11:37

1 Answer 1

2

As starting point:

\documentclass{article}
\usepackage{geometry}
\usepackage{microtype}
\usepackage{ragged2e}
\usepackage{booktabs, multirow, xltabular}
\newcolumntype{L}{>{\RaggedRight}X}

\begin{document}

\footnotesize
\setlength\tabcolsep{4pt}
\begin{xltabular}{\linewidth}{@{} *{3}{ L} l @{}}
    \caption{My table caption here}
    \label{tab:table1}\\
    \toprule
Category 1
    &   Category 2
        &   Category 3
            &   Category 4      \\*
    \midrule
\endfirsthead
%
\endhead
%
\multicolumn{4}{l}{\textbf{First Subcategory}}   \\
    \addlinespace
Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu  efficitur nisi. Pellentesque elementum quis urna  1 

Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna   2 
 Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  3 

Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  4
 Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  5 

Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  6
    &   Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1
  
  Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2
  
  Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  3
        &   Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1
  
            Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2
            &   \multirow{55}{*}{Topic 1}\\
  \cmidrule(r){1-3}
\multicolumn{4}{l}{\textbf{Second Subcategory}}   \\
    \addlinespace
Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1

Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2

Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  3
    &   Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1

        Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2

        Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  3 
        &   Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  1

        Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  2

        Praesent egestas feugiat odio, quis tempor libero sodales vitae. Integer in feugiat augue, eu efficitur nisi. Pellentesque elementum quis urna  3  
            &   \\
  \cmidrule(r){1-3}
\end{xltabular}
\end{document}

enter image description here

You may consider to rotate table in landscape orientation.

1
  • Thanks for that! In fact, the answer was a great starting point. I was not familiar with xltabular and it was just what I needed to get started. I was able to tweak the code and complement to get what I needed and my document is now complete. Thanks again! Jun 30, 2020 at 8:59

You must log in to answer this question.

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