1

I have a tabular which relies on a number of packages to achieve the desired appearance, specifically:

  • Scale text to a particular (smaller) size
  • Force column wrapping instead of shrinking text further
  • Increase space between different rows to distinguish between wrapped items
  • Disable right justification and hyphenation for a tidier look

I discovered that the table will end up needing to span multiple pages, but in this situation longtable is not a drop-in replacement for tabular and I am getting confused with the number of packages involved. How can I achieve the desired effect (a tabular spanning multiple pages, with all other visual elements, including the float caption, retained)? As a second question, can what I've written be simplified in some way?

\documentclass{scrartcl}
\usepackage{booktabs,array,parskip,adjustbox,enumitem}
\usepackage[UKenglish]{babel}
\newcolumntype{x}[1]{>{\raggedright}p{#1}}
\begin{document}


\begin{table}
\begin{hyphenrules}{nohyphenation}
\renewcommand{\arraystretch}{1.5}
\caption{Example table}\label{tab:example}
\centering
\begin{adjustbox}{width=1\textwidth}
\begin{tabular}{x{.2\columnwidth}@{\hskip 6\tabcolsep}x{.4\columnwidth}@{\hskip 6\tabcolsep}x{.4\columnwidth}}
\toprule
{\textbf{Column One}} & {\textbf{Column Two}} & {\textbf{Column Three}}
\tabularnewline
\midrule

ABC &
\begin{itemize}[leftmargin=*]
\item This is an item in column two.
\item This is another item in column two.
\end{itemize} &
\begin{itemize}[leftmargin=*]
\item Here is something in column three:
  \begin{itemize}
  \item It
  \item consists
  \item of
  \item many
  \item different
  \item lines
  \end{itemize}
\end{itemize}
\tabularnewline

DEF &
\begin{itemize}[leftmargin=*]
\item Additional blah blah making for a long sentence spanning multiple lines.
\item Another item.
\item Continuing the theme of items in column two.
\end{itemize} &
\begin{itemize}[leftmargin=*]
\item Here we also have a rather long item that needs multiple lines to fit.
\item Yet another item.
\item Blah, blah:
  \begin{itemize}
  \item It's a very long example of a sub-item in this column, here
  \item Yet more
  \end{itemize}
\end{itemize} 
\tabularnewline

GHI &
\begin{itemize}[leftmargin=*]
\item Another long, long long long long long long long long long long long
block of text.
\item This particular one is medium-medium medium in lenght.
\item This sentence means nothing in particular, it's blah.
\end{itemize} &
\begin{itemize}[leftmargin=*]
\item Blah
\end{itemize} 
\tabularnewline

JKL &
\begin{itemize}[leftmargin=*]
\item Blah, blah, blah, blah, blah.
\item Putting in fake data gets tedious.
\item Reading it is probably more boring still.
\end{itemize} &
\begin{itemize}[leftmargin=*]
\item Blah
\end{itemize}
\tabularnewline

MNO &
\begin{itemize}[leftmargin=*]
\item This was also a really long item so I am going to type and type and
type until I run out of words.
\end{itemize} &
\begin{itemize}[leftmargin=*]
\item Blah
\item Can
\item we
\item span
\item multiple
\item pages
\item with
\item lots
\item of
\item text?
\item Becauase
\item this
\item really
\item needs
\item to
\item be
\item multipage.
\end{itemize}
\tabularnewline

\bottomrule
\end{tabular}
\end{adjustbox}
\renewcommand{\arraystretch}{1}
\end{hyphenrules}
\end{table}

\end{document}

Output of LaTeX example

1

The first page:

enter image description here

The second page:

enter image description here

MWE (in preamble are considered only used packages):

\documentclass{scrartcl}

\usepackage{enumitem}
\usepackage{array, booktabs, longtable}
\newcolumntype{x}[1]{>{\raggedright}p{#1}}

\usepackage{etoolbox}
\AtBeginEnvironment{longtable}{%
    \setlist[itemize]{nosep,     % <-- new list setup
                      topsep     = 0pt       ,
                      partopsep  = 0pt       ,
                      leftmargin = *         ,
                      label      = $\bullet$ ,
                      before     = \vspace{-\baselineskip},
                      after      = \vspace{-0.5\baselineskip}
                        }
                           }% end of AtBeginEnvironment

%\usepackage{showframe}
\begin{document}
%\renewcommand{\arraystretch}{1.5}
\begin{longtable}{x{\dimexpr.2\columnwidth-2\tabcolsep}
                  x{\dimexpr.4\columnwidth-2\tabcolsep}
                  x{\dimexpr.4\columnwidth-2\tabcolsep}}
%\begin{hyphenrules}{nohyphenation}
    \caption{Example table}\label{tab:example}  \\
\toprule
{\textbf{Column One}} & {\textbf{Column Two}} & {\textbf{Column Three}}
\tabularnewline
\midrule
    \endfirsthead
%%%%
    \caption{Example table (cont.)}\label{tab:example}  \\
\toprule
{\textbf{Column One}} & {\textbf{Column Two}} & {\textbf{Column Three}}
\tabularnewline
\midrule
    \endhead
%%%%
\midrule[\heavyrulewidth]
\multicolumn{3}{r}{\footnotesize\itshape
                   Continue on the next page}
    \endfoot
%%%%
\bottomrule
    \endlastfoot
%%%%
ABC &
\begin{itemize}
\item This is an item in column two.
\item This is another item in column two.
\end{itemize} &
\begin{itemize}
\item Here is something in column three:
    \bigskip
  \begin{itemize}
  \item It
  \item consists
  \item of
  \item many
  \item different
  \item lines
  \end{itemize}
\end{itemize}
\tabularnewline\addlinespace

DEF &
\begin{itemize}
\item Additional blah blah making for a long sentence spanning multiple lines.
\item Another item.
\item Continuing the theme of items in column two.
\end{itemize} &
\begin{itemize}
\item Here we also have a rather long item that needs multiple lines to fit.
\item Yet another item.
\item Blah, blah:
    \bigskip
  \begin{itemize}
  \item It's a very long example of a sub-item in this column, here
  \item Yet more
  \end{itemize}
\end{itemize}
\tabularnewline\addlinespace

GHI &
\begin{itemize}
\item Another long, long long long long long long long long long long long
block of text.
\item This particular one is medium-medium medium in lenght.
\item This sentence means nothing in particular, it's blah.
\end{itemize} &
\begin{itemize}
\item Blah
\end{itemize}
\tabularnewline\addlinespace

JKL &
\begin{itemize}
\item Blah, blah, blah, blah, blah.
\item Putting in fake data gets tedious.
\item Reading it is probably more boring still.
\end{itemize} &
\begin{itemize}
\item Blah
\end{itemize}
\tabularnewline\addlinespace

MNO &
\begin{itemize}
\item This was also a really long item so I am going to type and type and
type until I run out of words.
\end{itemize} &
\begin{itemize}
\item Blah
\item Can
\item we
\item span
\item multiple
\item pages
\item with
\item lots
\item of
\item text?
\item Becauase
\item this
\item really
\item needs
\item to
\item be
\item multipage.
\end{itemize}
\tabularnewline
\end{longtable}
| improve this answer | |
  • Thank you, that is elegantly abstract and hides much of the complexity of the table design outside the table data. – Ann Jul 22 '17 at 23:41
1

I would do this with ltablex, which brings the functionalities of longtable to tabularx, and replace arraystretch with adequate \addlinespace between rows. Bo adjustbox, which shouldn't be used with tables. So here's a proposition:

\documentclass[UKenglish]{scrartcl}
\usepackage{booktabs,array,parskip, caption, enumitem, ltablex}
\usepackage{babel}
\captionsetup{labelfont = bf}
\keepXColumns

\begin{document}

\begin{hyphenrules}{nohyphenation}%
  \setlist[itemize, 1]{topsep=0pt, before=\vspace{-\baselineskip}\raggedright, after=\vspace{-\baselineskip}}
  \setlist[itemize]{leftmargin=*}
  \setlength\defaultaddspace{2.5ex}
  \begin{tabularx}{\textwidth}{>{\hsize=0.6\hsize}X@{\hskip 5\tabcolsep}>{\hsize=1.2\hsize}X@{\hskip 5\tabcolsep}>{\hsize=1.2\hsize}X}
    \caption{Example table}\label{tab:example} \\
    \addlinespace%[1.5ex]
    \toprule
    {\textbf{Column One}} & {\textbf{Column Two}} & {\textbf{Column Three}} \\
    \midrule
    \endfirsthead
    \multicolumn{3}{c}{Table \thetable{} (continued)} \\
    \addlinespace[1.5ex]
    \toprule
    {\textbf{Column One}} & {\textbf{Column Two}} & {\textbf{Column Three}} \\
    \midrule
    \endhead
    \\
    \midrule
    \multicolumn{3}{r}{\footnotesize To be continued}
    \endfoot
    \\
    \bottomrule
    \endlastfoot
    ABC &
    \begin{itemize}
      \item This is an item in column two.
      \item This is another item in column two.
    \end{itemize} &
    \begin{itemize}
      \item Here is something in column three:
            \begin{itemize}
              \item It
              \item consists
              \item of
              \item many
              \item different
              \item lines
            \end{itemize}
    \end{itemize}
    \\
    \addlinespace
    DEF &
    \begin{itemize}
      \item Additional blah blah making for a long sentence spanning multiple lines.
      \item Another item.
      \item Continuing the theme of items in column two.
    \end{itemize} &
    \begin{itemize}
      \item Here we also have a rather long item that needs multiple lines to fit.
      \item Yet another item.
      \item Blah, blah:
            \begin{itemize}
              \item It's a very long example of a sub-item in this column, here
              \item Yet more
            \end{itemize}
    \end{itemize}
    \\
    \addlinespace
    GHI &
    \begin{itemize}
      \item Another long, long long long long long long long long long long long
            block of text.
      \item This particular one is medium-medium medium in lenght.
      \item This sentence means nothing in particular, it's blah.
    \end{itemize} &
    \begin{itemize}[leftmargin=*]
      \item Blah
    \end{itemize}
    \\
    \addlinespace
    JKL &
    \begin{itemize}
      \item Blah, blah, blah, blah, blah.
      \item Putting in fake data gets tedious.
      \item Reading it is probably more boring still.
    \end{itemize} &
    \begin{itemize}[leftmargin=*]
      \item Blah
    \end{itemize}
    \\
    \addlinespace
    MNO &
    \begin{itemize}
      \item This was also a really long item so I am going to type and type and
            type until I run out of words.
    \end{itemize} &
    \begin{itemize}
      \item Blah
      \item Can
      \item we
      \item span
      \item multiple
      \item pages
      \item with
      \item lots
      \item of
      \item text?
      \item Because
      \item this
      \item really
      \item needs
      \item to
      \item be
      \item multipage.
    \end{itemize}
  \end{tabularx}
\end{hyphenrules}

\end{document}

enter image description here enter image description here

| improve this answer | |
  • Thank you. This alternative is equally effective and cleaner than my original attempt. I already applied the other solution, but for anyone reading this thread later, this is also effective. – Ann Jul 23 '17 at 1:57

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.