如何在表格中添加段落

如何在表格中添加段落

带段落的表格

\begin{table}[thb]\centering
    \caption{Summary of present reviews.}
    \label{tab:table2}
    %\resizebox{0.48\textwidth}{!}{
    \large
    \begin{tabular}{l l}
        \toprule
       Ref. & Key contribution\\
        \midrule
        \cite{prema2021critical} &  Several machine learning models have been reviewed by the author. Comparative analysis suggested that combination models, deep learning, and principle component analysis(PCA) based models, Random forest(RF) algorithm have performed better in terms of accuracy and stability. 
      The clustered PSO-SVM-ARMA model provided better results \\
        B &  4 \\
        Ours & 4 \\
        \bottomrule
    \end{tabular}
    %}
\end{table}

我想创建一个像我所附的表格,以及我尝试过的代码。我无法添加段落,表格中只有一行

答案1

这是一个根据您发布的屏幕截图格式化所有三列的解决方案。第三列提供自动悬挂缩进。

在此处输入图片描述

\documentclass{article} % or some other suitable document class

\usepackage{tabularx,ragged2e}
% format of third column
\newcolumntype{L}{>{\RaggedRight\hangafter=1\hangindent=1em}X}

% format of second column
\newlength\mylen % create a scratch length variable
\settowidth\mylen{September 2017}            % measure max. width of 2nd column
\newcolumntype{B}{>{\raggedright}b{\mylen}}  % allow automatic line breaking

\usepackage{caption}
\captionsetup[table]%
             {justification=RaggedRight, 
              singlelinecheck=off,
              labelfont=bf,
              labelsep=quad,
              skip=0.333\baselineskip,
             }
             
\usepackage{booktabs} % for well-spaced horizontal rules  
\usepackage{lipsum}   % filler text

\begin{document}

\begin{table}
\caption{Summary of present reviews.}
\label{tab:table2}
\begin{tabularx}{\textwidth}{@{} l B L @{}}
\toprule
\textbf{Work} & \textbf{Date of publication} & \textbf{Main contribution} \\
\midrule 
\cite{some_source} & September 2016 & \lipsum[1][1-5] \\
\bottomrule
\end{tabularx}
\end{table}

\end{document}

答案2

对于第二列,您应该使用“段落”类型的列p{<width>X列类型。后者在tabularax包中定义,它使列宽由 LaTeX 决定。

最简单的方法是使用tabularx包中的表和第二列的X列类型:

\documentclass{article}
\usepackage{booktabs, tabularx}

\begin{document}
    \begin{table}[htb]
    \centering
\caption{Summary of present reviews.}
\label{tab:table2}
\begin{tabularx}{\linewidth}{l X}% <<<- changed
    \toprule
Ref.    & Key contribution\\
    \midrule
\cite{prema2021critical}    
        &  Several machine learning models have been reviewed by the author. Comparative analysis suggested that combination models, deep learning, and principle component analysis (PCA) based models, Random forest(RF) algorithm have performed better in terms of accuracy and stability. The clustered PSO-SVM-ARMA model provided better results \\
B       &  4 \\
Ours    & 4 \\
    \bottomrule
\end{tabularx}
    \end{table}
\end{document}

在此处输入图片描述

附录:

我的第一个答案版本是基于提供的 MWE。它还考虑了所写的问题。但是,现在我看到(认识到),你想要的不仅仅是你要求的:显示图像的复制,即一个有三列的表格和花哨的段落样式(我不喜欢,但我还是添加了它)。

对于这些更改,我估计使用包是(非常)合适的tabularray。使用它的代码简单而简短:

\documentclass{article}
\usepackage{microtype}   % if you liked
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{caption}   
\captionsetup[table]% for reproducing table caption style
             {singlelinecheck=off,
              labelfont=sc,
              labelsep=quad,
              skip=1ex
             }

\begin{document}
    \begin{table}[htb]
    \centering
\caption{Summary of present reviews.}
\label{tab:table2}
\begin{tblr}{colspec={l Q[l, b] X[j, cmd={\hangafter=1\hangindent=1em}]},
             row{1} ={font=\small\bfseries}
             }
    \toprule
Ref.    
    & {Date of\\ publication}
            &   Key contribution\\
    \midrule
\cite{prema2021critical}
        & September 2016
            &  Several machine learning models have been reviewed by the author. Comparative analysis suggested that combination models, deep learning, and principle component analysis(PCA) based models, Random forest (RF) algorithm have performed better in terms of accuracy and stability. The clustered PSO-SVM-ARMA model provided better results \\
B       &   & 4 \\
Ours    &   & 4 \\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

相关内容