如何才能改善包含大量文字的表格的排版?

如何才能改善包含大量文字的表格的排版?

感谢 @cfr 提供的示例,我能够在我正在准备的一篇学术论文中创建一个时尚的、文本丰富的表格。但是,存在文本块的对齐和对齐问题。有没有办法让表格右侧不齐以收紧排版?当我将右侧不齐作为参数添加到表格环境中时,我收到错误,如下所示...

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

我还想知道是否有一种好的方法可以在单元格中添加项目符号列表而又不牺牲太多的空白空间。

我的输出: 最小工作示例 这是最小工作示例。我保留了@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

我建议进行一些小的改动,例如使用 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}

带有(包 ragged2e)的变体\RaggedRight可能也很有趣。

\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}

答案2

这里有两种方法可以使itemize表中的环境不带空格,即使用enumitemetoolbox

第一种方式是在环境的开头设置适当的列表参数值table,并在单元格中插入环境 itemize。当然,如果 itemize 之前或之后的单元格中有普通文本,则必须先设置不同的 itemize 参数值。

第二种方式定义了一种新的列类型,I专用于仅包含 itemize 环境的单元格。它是一种在进入和离开单元格时X自动进入和离开的列类型:itemize

\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} 

在此处输入图片描述

相关内容