5

Thanks to the example provided by @cfr I was able to create a stylish, text-heavy table in an academic paper I am preparing. However, there are issues with rivering and the justification of the text blocks. Is there a way to make a table ragged right to tighten up the typography? I receive an error when I add ragged right as an argument to the tabular environment, as in...

        \begin{tabular}{*{4}{p{.28\linewidth}}}{\raggedright}

I'm also wondering if there's a nice way to add bulleted lists in the cells without sacrificng so much white space.

My output: Minimum working example Here is the minimum working example. I've left the original notes from @cfr.

\documentclass[12pt,times]{elsarticle}
%\usepackage{setspace}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{url}
\usepackage{lineno}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{graphicx}
\graphicspath{ {images/} }
\usepackage[font=normalsize,labelfont=bf]{caption}
\captionsetup{justification=raggedright,
singlelinecheck=false
}
\usepackage{color}

\begin{document}

\begin{table}

    \centering% This is an environment - we probably don't want the extra spacing of center in addition to that added by table etc.
    \caption{Title}

    \small
    \begin{tabular}{*{4}{p{.28\linewidth}}}% The target layout does not centre the text so we don't want \centering
      \toprule% nicer rules courtesy of booktabs - but then we need to drop the verticals 
      & \textbf{Heading 1} &  \textbf{Heading 2} & \textbf{Heading 3}\\\midrule% Note that there is no & before the first column - & only comes between columns so if you define n columns, you can have at most n-1 & symbols in any row
     \textbf{Row 1} & Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure & I would like this text to be bulleted with ragged right.I would also like this text to be bulleted with ragged right. 

I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right. 
 &  I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right. 

I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right. 
\\% No need for 6 rows of space for each title!
     \\\midrule% the p{} setting automatically lets these be multi-line - we don't want multiple rows on top of that and this is simpler as TeX does the hard work for us
       \textbf{Row 2} & Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure & I would like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right. 

I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right. 
 &  I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right. 

I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right. 
 \\
 \\\midrule
  \textbf{Row 3} & Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure & I would like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right. 

I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right. 
 &  I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right. 

I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right. 
      \\
      \bottomrule
    \end{tabular}
  \end{table}
\end{document}
  • 1
    BTW: 4 times 0.28 equals 1.12. Plus some \tabcolsep means that the table is definitely wider than \linewidth, which may be intentional, of course. – Jürgen Mar 30 '17 at 13:33
  • I was just using the MWE of @cfr and so am tagging that user herein. Thank you for this answer. – AllanM Mar 30 '17 at 13:39
1

I would propose some minor changes, eg using tabularx.

\documentclass[12pt,times]{elsarticle}
%\usepackage{setspace}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{url}
\usepackage{lineno}
\usepackage{tabularx} % <---
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{graphicx}
\graphicspath{ {images/} }
\usepackage[font=normalsize,labelfont=bf]{caption}
\captionsetup{justification=raggedright, singlelinecheck=false }
\usepackage{color}

\begin{document}

\begin{table}

    \centering% This is an environment - we probably don't want the extra spacing of center in addition to that added by table etc.
    \caption{Title}

    \small
    \begin{tabularx}{\linewidth}{l>{\raggedright}X>{\raggedright}X>{\raggedright}X}% The target layout does not centre the text so we don't want \centering
      \toprule% nicer rules courtesy of booktabs - but then we need to drop the verticals
      & \textbf{Heading 1} &  \textbf{Heading 2} & \textbf{Heading 3}\tabularnewline\midrule% Note that there is no & before the first column - & only comes between columns so if you define n columns, you can have at most n-1 & symbols in any row
     \textbf{Row 1} & Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure & I would like this text to be bulleted with ragged right.I would also like this text to be bulleted with ragged right.

I would also like this text to be bulleted with ragged right. I
would also like this text to be bulleted with ragged right.
 &  I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right.

I would also like this text to be bulleted with ragged right. I
would also like this text to be bulleted with ragged right.
\tabularnewline% No need for 6 rows of space for each title!
     \tabularnewline\midrule% the p{} setting automatically lets these be multi-line - we don't want multiple rows on top of that and this is simpler as TeX does the hard work for us
       \textbf{Row 2} & Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure & I would like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right.

I would also like this text to be bulleted with ragged right. I
would also like this text to be bulleted with ragged right.
 &  I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right.

I would also like this text to be bulleted with ragged right. I
would also like this text to be bulleted with ragged right.
 \tabularnewline
 \tabularnewline\midrule
  \textbf{Row 3} & Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure & I would like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right.

I would also like this text to be bulleted with ragged right. I
would also like this text to be bulleted with ragged right.
 &  I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right.

I would also like this text to be bulleted with ragged right. I
would also like this text to be bulleted with ragged right.
      \tabularnewline
      \bottomrule
    \end{tabularx}
  \end{table}
\end{document}

The variant with \RaggedRight (package ragged2e) might be interesting, too.

\documentclass[12pt,times]{elsarticle}
%\usepackage{setspace}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{url}
\usepackage{ragged2e} % <---
\usepackage{lineno}
\usepackage{tabularx} % <---
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{graphicx}
\graphicspath{ {images/} }
\usepackage[font=normalsize,labelfont=bf]{caption}
\captionsetup{justification=raggedright, singlelinecheck=false }
\usepackage{color}

\begin{document}

\begin{table}

    \centering% This is an environment - we probably don't want the extra spacing of center in addition to that added by table etc.
    \caption{Title}

    \small
    \begin{tabularx}{\linewidth}{l>{\RaggedRight}X>{\RaggedRight}X>{\RaggedRight}X}% The target layout does not centre the text so we don't want \centering
      \toprule% nicer rules courtesy of booktabs - but then we need to drop the verticals
      & \textbf{Heading 1} &  \textbf{Heading 2} & \textbf{Heading 3}\tabularnewline\midrule% Note that there is no & before the first column - & only comes between columns so if you define n columns, you can have at most n-1 & symbols in any row
     \textbf{Row 1} & Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure & I would like this text to be bulleted with ragged right.I would also like this text to be bulleted with ragged right.

I would also like this text to be bulleted with ragged right. I
would also like this text to be bulleted with ragged right.
 &  I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right.

I would also like this text to be bulleted with ragged right. I
would also like this text to be bulleted with ragged right.
\tabularnewline% No need for 6 rows of space for each title!
     \tabularnewline\midrule% the p{} setting automatically lets these be multi-line - we don't want multiple rows on top of that and this is simpler as TeX does the hard work for us
       \textbf{Row 2} & Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure & I would like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right.

I would also like this text to be bulleted with ragged right. I
would also like this text to be bulleted with ragged right.
 &  I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right.

I would also like this text to be bulleted with ragged right. I
would also like this text to be bulleted with ragged right.
 \tabularnewline
 \tabularnewline\midrule
  \textbf{Row 3} & Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure & I would like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right.

I would also like this text to be bulleted with ragged right. I
would also like this text to be bulleted with ragged right.
 &  I would also like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right.

I would also like this text to be bulleted with ragged right. I
would also like this text to be bulleted with ragged right.
      \tabularnewline
      \bottomrule
    \end{tabularx}
  \end{table}
\end{document}
  • Could you also recommend a way to itemize the text within the third and fourth columns? Using an itemize environment creates a lot of white space to the left of the bullet points. – AllanM Mar 30 '17 at 13:33
  • 1
    Yes, there are packages like enumitem which allow compact lists. Please have a look at the manual. – Jürgen Mar 30 '17 at 13:36
2

Here are two ways to have itemize environments in a table without blank spaces, using enumitem and etoolbox.

The first way consists in setting adapted values of the list parameters at the beginning of the table environment, and inserting in the cells an itemize environment. Of course, if there is ordinary text in the cell before or after itemize, you have to set different values of the itemize parameters first.

The second way defines a new column type, I which is dedicated to cells containing only itemize environments. It is an X column type automatically entering and leaving itemize on entering and leaving the cells:

\documentclass[12pt,times]{elsarticle}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{url}
\usepackage{ragged2e} % <---
\usepackage{lineno}
\usepackage{tabularx} % <---
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{graphicx}
\graphicspath{ {images/} }
\usepackage[font=normalsize,labelfont=bf]{caption}
\captionsetup{justification=raggedright, singlelinecheck=false }

\usepackage{enumitem, etoolbox}
\AtBeginEnvironment{table}{\setlist[itemize, 1]{wide=0pt, leftmargin= *, topsep=0pt, itemsep=0pt, labelsep=.333em,
before=\leavevmode\vspace*{-\baselineskip},after= \vspace*{-\baselineskip}}}

\newcolumntype{I}{ >{\itemize}X<{\enditemize}}

\usepackage{makecell}
\renewcommand\theadfont{\normalsize\bfseries}

\usepackage{xcolor}

\begin{document}

\begin{table}[!htb]
  \centering%
  \setlength{\tabcolsep}{4pt}
  \caption{Title}
  \small
  \begin{tabularx}{\linewidth}{@{}l>{\RaggedRight}X>{\RaggedRight}X%
    >{\RaggedRight}I}% The target layout does not centre the text so we don't want \centering
    \toprule% nicer rules courtesy of booktabs - but then we need to drop the verticals
      & \thead{Heading 1} & \thead{Heading 2} & \multicolumn{1}{c}{\bfseries Heading 3}%
    \tabularnewline\midrule%
    \textbf{Row 1} & Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure &
    \begin{itemize}
    \item I would like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right.
    \item I would also like this text to be bulleted with ragged right.
    \item I would also like this text to be bulleted with ragged right.
    \end{itemize}
    &
    \item I would also like this text to be bulleted with ragged right.
    \item I would also like this text to be bulleted with ragged right.
    \item I would also like this text to be bulleted with ragged right.
    \item I would also like this text to be bulleted with ragged right.
    \tabularnewline
    \addlinespace\midrule%
    \textbf{Row 2} & Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
    & \begin{itemize}
    \item I would like this text to be bulleted with ragged right. I would also like this text to be bulleted with ragged right.
    \item I would also like this text to be bulleted with ragged right. I
    would also like this text to be bulleted with ragged right.
    \end{itemize}
    & \item I would also like this text to be bulleted with ragged right.
    \item I would also like this text to be bulleted with ragged right.
    \item I would also like this text to be bulleted with ragged right. I
    would also like this text to be bulleted with ragged right.
    \tabularnewline
    \bottomrule
  \end{tabularx}
\end{table}

\end{document} 

enter image description here

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.