多行表中的文本溢出

多行表中的文本溢出

我有一张包含四列的表格。问题是:

  • 文本在第三列和第四列溢出,如下图所示。这些列包含密集文本。
  • 文本应在表格内。

我尝试搜索现有答案(12),但大多数都是使用p{width}列类型。此方法不适用于多行的情况。

在此处输入图片描述

所需表格:

在此处输入图片描述

下面举一个例子来说明这个问题:

\documentclass{article}
\usepackage{multirow}
\usepackage{graphicx}
\begin{document}
\begin{table}[H]
\caption{}
\label{tab:my-table}
\resizebox{\textwidth}{!}{%
\begin{tabular}{|l|l|l|l|}
\hline
\textbf{Research group} & \textbf{Ref} & \textbf{Common attributes} & \textbf{features noted} \\ \hline
(Yasir et al., 2020) &
  [1] &
  \multirow{9}{*}{\begin{tabular}[c]{@{}l@{}}1) blah blah blah blah blah blah blah blah blah blah blah.\\ ---------------------------------------------------------\\ \\ -------------------------------------------------------\\ \\ ------------------------------------------------------\\ \\ \\ \\ 2). blah blah blah blah blah blah blah blah blah blah blah.\\ ---------------------------------------------------------\\ \\ -------------------------------------------------------\\ \\ ------------------------------------------------------\\ \\ \\ \\ 3)- blah blah blah blah blah blah blah blah blah blah blah.\\ ---------------------------------------------------------\\ \\ -------------------------------------------------------\\ \\ -----------------------------------------------------\\ \\ \\ \\ \\ blah blah blah blah blah blah blah blah blah blah blah.\\ \\ ---------------------------------------------------------\\ \\ -------------------------------------------------------\\ \\ ------------------------------------------------------\end{tabular}} &
  \multirow{9}{*}{\begin{tabular}[c]{@{}l@{}}1).blah blah blah blah blah blah blah blah blah blah blah.\\ \\ ---------------------------------------------------------\\ -------------------------------------------------------\\ ------------------------------------------------------\\ \\ 2). blah blah blah blah blah blah blah blah blah blah blah.\\ \\ ---------------------------------------------------------\\ -------------------------------------------------------\\ ------------------------------------------------------\\ \\ \\ 3).blah blah blah blah blah blah blah blah blah blah blah.\\ \\ ---------------------------------------------------------\\ -------------------------------------------------------\\ -----------------------------------------------------\\ \\ \\ \\ 4). blah blah blah blah blah blah blah blah blah blah blah.\\ ---------------------------------------------------------\\ \\ ------------------------------------------------------\\ \\ ------------------------------------------------------\end{tabular}} \\ \cline{1-2}
(Yasir et al., 2020)    & [1]          &                            &                         \\ \cline{1-2}
(Yasir et al., 2020)    & [1]          &                            &                         \\ \cline{1-2}
(Yasir et al., 2020)    & [1]          &                            &                         \\ \cline{1-2}
(Yasir et al., 2020)    & [1]          &                            &                         \\ \cline{1-2}
(Yasir et al., 2020)    & [1]          &                            &                         \\ \cline{1-2}
(Yasir et al., 2020)    & [1]          &                            &                         \\ \cline{1-2}
(Yasir et al., 2020)    & [1]          &                            &                         \\ \cline{1-2}
(Yasir et al., 2020)    & [1]          &                            &                         \\ \hline
\end{tabular}%
}
\end{table}
\end{document}

答案1

从您想要的表来看,我想您可能想要这样的东西。

在此处输入图片描述

\documentclass{article}

\usepackage{tabularray}
\usepackage{lipsum}
\UseTblrLibrary{booktabs}

\begin{document}
\begin{table}
\caption{}
\label{tab:my-table}
    \begin{tblr}{
        width = \textwidth,
        stretch = 1.5,
        colspec={X[0.5,m] Q[c,m] *{2}{X[m]}},
        row{1} = {font=\bfseries},
        vspan = even
    }
        \toprule
        Research group & Ref & Common attributes & features noted \\\midrule
        (Yasir et al., 2020)   & [1]          &
          \SetCell[r=3]{halign=l, valign=h} \lipsum[1][1-2]
          &
          \SetCell[r=3]{halign=l, valign=h} \lipsum[1][1-2]\\
        (Yasir et al., 2020)    & [1]          &                            &                         \\
        (Yasir et al., 2020)    & [1]          &                            &                         \\ \midrule
        (Yasir et al., 2020)    & [1]          &
          \SetCell[r=2]{halign=l, valign=h} \lipsum[1][1-2]
          &
          \SetCell[r=2]{halign=l, valign=h} \lipsum[1][1-2]\\
        (Yasir et al., 2020)    & [1]          &                            &                         \\ \midrule
        (Yasir et al., 2020)    & [1]          &
          \SetCell[r=2]{halign=l, valign=h} \lipsum[1][1-2]
          &
          \SetCell[r=2]{halign=l, valign=h} \lipsum[1][1-2]\\
        (Yasir et al., 2020)    & [1]          &                            &                         \\ \midrule
        (Yasir et al., 2020)    & [1]          &
          \SetCell[r=2]{halign=l, valign=h} \lipsum[1][1-2]
          &
          \SetCell[r=2]{halign=l, valign=h} \lipsum[1][1-2]\\
        (Yasir et al., 2020)    & [1]          &                            &                         \\
        \bottomrule
    \end{tblr}%
\end{table}
\end{document}

编辑(根据OP的评论):使用Ulrike Fischer 的回答在这里

\documentclass{article}

\usepackage{tabularray}
\usepackage{enumitem}
\usepackage{lipsum}
\UseTblrLibrary{booktabs}

%to remove space from top of the list
\makeatletter
\newcommand\novspace{\@minipagetrue}
\makeatother

\begin{document}
\begin{table}
\caption{}
\label{tab:my-table}
    \begin{tblr}{
        width = \textwidth,
        stretch = 1.5,
        % vlines, %uncomment if you want vertical lines
        colspec={X[0.5,m] Q[c,m] *{2}{X[c,m]}},
        row{1} = {font=\bfseries},
        vspan = even
    }
        \toprule
        Research group & Ref & Common attributes & features noted \\\midrule
        (Yasir et al., 2020)   & [1]          &
          \SetCell[r=9]{halign=l, valign=h} 
          \parbox[t]{\linewidth}{\novspace %to remove space from the bottom of the list
          \begin{itemize}[leftmargin=*]
              \item \lipsum[1][1-3]
              \item \lipsum[1][1-3]
              \item \lipsum[1][1-3]
              \item \lipsum[1][1-3]
          \end{itemize}}
          &
          \SetCell[r=9]{halign=l, valign=h} 
          \parbox[t]{\linewidth}{\novspace
          \begin{itemize}[leftmargin=*]
              \item \lipsum[1][1-3]
              \item \lipsum[1][1-3]
              \item \lipsum[1][1-3]
              \item \lipsum[1][1-3]
          \end{itemize}}\\\cmidrule{1-2}
        (Yasir et al., 2020)    & [1] & & \\\cmidrule{1-2}
        (Yasir et al., 2020)    & [1] & & \\\cmidrule{1-2} 
        (Yasir et al., 2020)    & [1] & & \\\cmidrule{1-2}
        (Yasir et al., 2020)    & [1] & & \\\cmidrule{1-2}
        (Yasir et al., 2020)    & [1] & & \\\cmidrule{1-2}
        (Yasir et al., 2020)    & [1] & & \\\cmidrule{1-2}
        (Yasir et al., 2020)    & [1] & & \\\cmidrule{1-2}
        (Yasir et al., 2020)    & [1] & & \\\bottomrule
    \end{tblr}%
\end{table}
\end{document}

在此处输入图片描述

答案2

@Imran 答案的一个小变化(+1):

  • 用于列表设置etoolbox
  • parbox
  • 使用的是垂直线(正如你在问题中展示的那样)
\documentclass{article}
\usepackage[margin=25mm]{geometry}              % new
\usepackage[skip=1ex, 
            font=small, labelfont=bf]{caption}  % new

\usepackage{tabularray}
\UseTblrLibrary{varwidth}                       % new

\usepackage{enumitem}
\usepackage{etoolbox}                           % new
\AtBeginEnvironment{table}%                     % new
{
\setlist[itemize]{label=\textbullet,
                  wide,
                  after=\end{minipage},                  
                  before=\begin{minipage}[t]{\linewidth} 
                    }
}
\usepackage{lipsum}

\begin{document}
    \begin{table}[ht]
    \caption{}
    \label{tab:my-table}
\begin{tblr}{hlines, vlines,
             colspec={X[0.5,l] c X[h, j] X[h, j]},
             colsep = 4pt,
             row{1} = {font=\small\bfseries},
             measure = vbox,
             vspan =even
             }
Research group  
    & Ref.  & Common attributes
                & Features noted        \\
(Yasir et al., 2020) 
    & [1]   & \SetCell[r=9] {j}
                \begin{itemize}
            \item \lipsum[1][1-3]
            \item \lipsum[1][1-3]
            \item \lipsum[1][1-3]
            \item \lipsum[1][1-3]
                \end{itemize}
                & \SetCell[r=9] {j}
                    \begin{itemize}
                \item \lipsum[1][1-3]
                \item \lipsum[1][1-3]
                \item \lipsum[1][1-3]
                \item \lipsum[1][1-3]
                    \end{itemize} \\
(Yasir et al., 2020)    
    & [2]   &   &                   \\
(Yasir et al., 2020)    
    & [3]   &   &                   \\
(Yasir et al., 2020)    
    & [4]   &   &                   \\
(Yasir et al., 2020)    
    & [5]   &   &                   \\
(Yasir et al., 2020)    
    & [6]   &   &                   \\
(Yasir et al., 2020)    
    & [7]   &   &                   \\
(Yasir et al., 2020)    
    & [8]   &   &                   \\
(Yasir et al., 2020)    
    & [9]   &   &                   \\
\end{tblr}%
    \end{table}
\end{document}

在此处输入图片描述

相关内容