Springer latex 表格边框和文字换行

Springer latex 表格边框和文字换行

我使用的是 Springer Journal Latex 格式。我在绘制表格时遇到了问题,因为每个单元格内的文本会延伸到相邻的单元格,并且表格会超出纸张范围。我使用了以下代码,并附上了绘制表格的屏幕截图。

在此处输入图片描述

\documentclass{sn-jnl}
\usepackage{tabularx,ragged2e}
\newcolumntype{L}{>{\RaggedRight}X}
\begin{document}
\begin{table}[h]    
\caption{}
\label{table:Literature}
\scriptsize
\begin{tabular}{|p{3cm}|p{4cm}|p{3cm}|p{4cm}|}
        
    \hline
    \multicolumn{1}{|c|}{\textbf{Item}} & 
    \multicolumn{1}{ c|}{\textbf{Actions}} & 
    \multicolumn{1}{ c|}{\textbf{Preposition}} & 
    \multicolumn{1}{ c|}{\textbf{Outcome}}
    \\ \hline
    Work-1 &
    \begin{tabular}[c]{@{}l@{}}
       Modification in Group formation for set creation.  
       Removes all irrelevant and invisible users from list.
    \end{tabular} & 
    \begin{tabular}[c]{@{}l@{}}
       Claims increase in size by reducing parameter number one
    \end{tabular} & 
    \begin{tabular}[c]{@{}l@{}}
       Its not clear what the author wants to achieve from this research 
    \end{tabular}  \\
\hline                                                                              
\end{tabular}   
\end{table}
\end{document}

答案1

您习惯在单列tabular环境中用 来包裹几乎每个单元格的内容,l这妨碍了自动换行。补救措施是什么?去掉tabular包装器。

哦,请采用tabularx环境和L您已经为第 2 至第 4 列定义的列类型。我看不出有什么理由\scriptsize;在下面的代码中,我采用了\small。最后,没有令人信服的理由大胆的标题单元格的内容有吗?

在此处输入图片描述

\documentclass{sn-jnl}
\usepackage{tabularx,ragged2e}
\newcolumntype{L}{>{\RaggedRight}X}

\begin{document}
\begin{table}[h]  

\setlength\extrarowheight{2pt} % for a less cramped look
\setlength\tabcolsep{4pt}      % default: 6pt
\small                         % why "\scriptsize" ?

\caption{}
\label{table:Literature}


\begin{tabularx}{\textwidth}{|l|L|L|L|}
\hline
Item & Actions & Proposition & Outcome \\ 
\hline
Work-1 
& Modification in group formation for set creation.  
  Removes all irrelevant and invisible users from list. 
& Claims increase in size by reducing parameter number one. 
& It's not clear what the author wants to achieve from 
  this research.
\\ \hline
\end{tabularx}   

\end{table}
\end{document}

附录回应 OP 的后续评论:由于上面显示的解决方案使用了浮动table,因此它最多可以占据一整页。如果您的表格长度(包括标题)超出了参数\textheight,我建议您从组合的table/tabularx框架切换到xltabular框架。基本上,环境结合了和环境xltabular的功能。longtabletabularx

您还表示希望能够设置不等的列宽。

  • 要通过指定相对而不是绝对列宽来实现这一点,我建议概括代码中定义的L列类型(它本身是列类型的概括X),以允许不平等的相对宽度。

  • 在下面的代码中,这是通过指定Y列类型来实现的,L列类型与采用显式参数的列类型不同。要记住的主要规则是相对列宽的总和必须等于Y-type 列的数量。

  • 您提到要使用 2cm、3cm、3cm 和 4cm 的绝对(可用)宽度;即 2:3:3:4 的比例。快速计算表明,4 列的参数Y应为 0.667、1、1 和 1.333。为什么?这是因为 (a) 1.333 比 1 大 33.3%,是 0.667 的两倍,并且 (b) 0.667+1+1+1.333 = 4 =Y类型列的数量。

  • 总结一下:使用

    \begin{xltabular}{\textwidth}{|Y{0.667}|Y{1}|Y{1}|Y{1.333}|}
    

    代替

    \begin{tabularx}{\textwidth}{|l|L|L|L|}
    
  • 仅提供一个如何推导列参数的附加示例Y:假设您决定对第一列使用Y列类型,而不是对所有 4 列使用比例为 的列类型,同时仍为其余 3 列分配 3:3:4 的比例。快速计算表明,您现在应该写2:3:3:4l

    \begin{xltabular}{\textwidth}{|l|Y{0.9}|Y{0.9}|Y{1.2}|}
    

    因为 1.2 比 0.9 大 33.3%,并且 0.9+0.9+1.2 = 3 = Y 型列的数量。

下面的截图显示了两种方法在外观上的不同。

在此处输入图片描述

\documentclass{sn-jnl}
\usepackage{xltabular} % For 'xltabular' env. Loads the 'tabularx'
                       % and 'longtable' packages automatically
\usepackage{ragged2e}  % For '\RaggedRight' macro
\newcolumntype{L}{>{\RaggedRight}X}
\newcolumntype{Y}[1]{>{\RaggedRight\hsize=#1\hsize}X}

\begin{document}


%% Version 1: table/tabularx (repeated from above)
\begin{table}[h]  
\setlength\tabcolsep{4pt}      % default: 6pt
\setlength\extrarowheight{2pt} % for a less cramped look

\caption{}
\label{table:Literature_1}
\small

\begin{tabularx}{\textwidth}{|l|L|L|L|}
\hline
Item & Actions & Proposition & Outcome \\ 
\hline
Work-1 
& Modification in group formation for set creation.  
  Removes all irrelevant and invisible users from list. 
& Claims increase in size by reducing parameter number one. 
& It's not clear what the author wants to achieve from 
  this research.
\\ \hline
\end{tabularx}     
\end{table}

%% Version 2: xltabular approach
\begingroup % Limit the scope of the next 3 instructions
\setlength\tabcolsep{4pt}      % default: 6pt
\setlength\extrarowheight{2pt} % for a less cramped look
\small

\begin{xltabular}{\textwidth}{|Y{0.667}|Y{1}|Y{1}|Y{1.333}|}

%% headers and footers

\multicolumn{4}{@{}l}{\refstepcounter{table}\textbf{Table \thetable} \label{table:Literature_1a}}
\\[1.5ex]
\hline
Item & Actions & Proposition & Outcome \\ 
\hline
\endfirsthead

\multicolumn{4}{@{}l}{\textbf{Table \thetable}, cont'd}  \\[1.5ex]
\hline
Item & Actions & Proposition & Outcome \\ 
\hline
\endhead

\multicolumn{4}{r@{}}{\footnotesize\em(continued on next page)}\\
\endfoot

\hline
\endlastfoot

%% body of table
Work-1 
& Modification in group formation for set creation.  
  Removes all irrelevant and invisible users from list. 
& Claims increase in size by reducing parameter number one. 
& It's not clear what the author wants to achieve from 
  this research. \\ % note: no \hline directive here
   
\end{xltabular}     
\endgroup

\end{document}

答案2

\documentclass{sn-jnl}
\usepackage{tabularray}
\begin{document}
\begin{table}
\centering
\caption{title}
\begin{tblr}
{
colspec = {*{4}{X[-1,c,m]}},
row{1}  = {font=\bfseries},
hlines,
vlines,
}
Item   & Actions                                                                                                 & Preposition                                              & Outcome                                                           \\
Work-1 & Modification in Group formation for set creation. Removes all irrelevant and invisible users from list. & Claims increase in size by reducing parameter number one & Its not clear what the author wants to achieve from this research \\
\end{tblr}
\end{table}
\end{document}

在此处输入图片描述

答案3

这个怎么样?

\documentclass{sn-jnl}
\usepackage{ragged2e,booktabs,tabularx}

\newcolumntype{L}{>{\raggedright}p{3.2cm}}
\setlength\tabcolsep{4pt}  % default 6 pt
\begin{document}
\begin{table}[h]    
\caption{}
\label{table:Literature}
\footnotesize

\begin{tabular}{lLLL}
    \toprule
    \textbf{Item} & \multicolumn{1}{c}{\textbf{Actions}} & \multicolumn{1}{c}{\textbf{Preposition}} & \multicolumn{1}{c}{\textbf{Outcome}} \\ \midrule
    Work-1 & Modification in Group formation for set creation.  
       Removes all irrelevant and invisible users from list. & Claims increase in size by reducing parameter number one & Its not clear what the author wants to achieve from this research \\
    \bottomrule
\end{tabular}

\end{table}
\end{document}

在此处输入图片描述

相关内容