2

I am using springer journal latex format. I have problem in drawing tables since text inside each cell stretches out to the adjacent cell and table is drawn out of paper. I have used following code and screenshot of table drawn is also attached.

enter image description here

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

3 Answers 3

3

Your habit of encasing the contents of almost every cell in a single-column tabular environment, with column type l, is preventing automatic line breaking from occurring. The remedy? Get rid of the tabular wrappers.

Oh, and do employ a tabularx environment and the L column type you've already defined for columns 2 thru 4. I can see no reason for \scriptsize; in the code below, I employ \small. Finally, there's no compelling reason for bold-facing the contents of the header cells, is there?

enter image description here

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

Addendum to address the OP's follow-up comment: Since the solution shown above employs a table float, it can occupy at most a full page. If your table's length (including caption) exceeds the \textheight parameter, I suggest you proceed by switching from a combined table/tabularx framework to a xltabular framework. Basically, an xltabular environment combines the capabilities of the longtable and tabularx environments.

You have also expressed a desire to be able to set unequal column widths.

  • To do so by specifying relative rather than absolute column widths, I suggest to generalize the L column type (which, itself, is a generalization of the X column type) that's defined in your code to allow for unequal relative widths.

  • In the code below, this is done by specifying the Y column type, which differs from the L column type by taking an explicit argument. The main rule to remember is that the relative column widths have to sum up to the number of Y-type columns.

  • You've mentioned wanting to use absolute (usable) widths of 2cm, 3cm, 3cm, and 4cm; that's a ratio of 2:3:3:4. A quick calculation shows that the arguments of the 4 Y columns should be 0.667, 1, 1, and 1.333. Why? It's because (a) 1.333 is 33.3% larger than 1 and twice as large as 0.667, and (b) 0.667+1+1+1.333 = 4 = number of Y-type columns.

  • To sum up: use

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

    instead of

    \begin{tabularx}{\textwidth}{|l|L|L|L|}
    
  • Just to provide an additional example of how to derive the arguments of the Y columns: Suppose that instead of employing the Y column type for all 4 columns with a ratio of 2:3:3:4, you decide to employ the l column type for the first column, while still assigning a 3:3:4 ratio to the remaining 3 columns. A quick calculation shows that you should now write

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

    because 1.2 is 33.3% larger than 0.9 and 0.9+0.9+1.2 = 3 = # of Y-type columns.

The following screenshot shows how the two approaches differ in appearance.

enter image description here

\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
  • Thanks @Mico it works but as i add more rows to the table then the table moves to the last page of the document due to the overall increase in the table size. But I see enough space available on a page to stretch column's width individually to fit within the width of a page. So I tried this ''\begin(tabularx}{\textwidth}{|p{2cm}|p{3cm}|p{3cm}|p{4cm}|}'' but now the horizontal border lines disappear in all the cells of last column. How can I increase individual column width without any problem? Commented Feb 26, 2023 at 3:13
  • @user3696623 - I don't think it's a good idea to define absolute (usable) column widths, as the overall width of the table will exceed the sum of the usable widths. Instead, I suggest you employ an xltabular environment, which combines the capabilities of the longtable and tabularx environments. See the addendum I posted for an example of how this idea might be implemented.
    – Mico
    Commented Feb 26, 2023 at 10:01
1
\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}

enter image description here

1

How about this?

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

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .