使用多行和多列时集中表格单元格

使用多行和多列时集中表格单元格

在此处输入图片描述

我有一张上面显示的大表格,其中存在一些问题:

1-我想将除第二列之外的所有单元格的内容(水平和垂直)集中起来,垂直和水平。同时将所有标题集中起来。

2- 最后 3 列标题(“用户定义”下方的三项)上方和下方应该留出一点空间。

3- 下面有额外的空间“方法 1 [1]”并在“方法 1 的描述”

4-最后一行(第一列)上的名称“InformationRetrieval1”应该自动中断,因为它位于固定长度的列中,但事实并非如此。

请注意,我在这里展示的是 MWE 示例,实际表格要大得多,适合整个页面(加上一些边距)。因此,请不要建议更改布局或删除调整框, ETC。:

代码如下:

\RequirePackage{fix-cm}
\RequirePackage{amsmath}
\documentclass{svjour3}
\usepackage[backend=biber, maxnames=10, minnames=10]{biblatex}
\addbibresource{project.bib}
\smartqed  % flush right qed marks, e.g. at end of proof
\usepackage{graphicx}
\usepackage{floatrow}
\usepackage{lipsum}
\usepackage{multirow}
\usepackage{hhline}
\usepackage[group-separator={,},group-minimum-digits=4]{siunitx}
\usepackage{geometry}
\usepackage{adjustbox}
\usepackage{changepage}
\usepackage{makecell}
\usepackage{afterpage}
\usepackage{amssymb}
\usepackage{comment}
\usepackage{array}
\newcolumntype{?}{!{\vrule width 2pt}}

\makeatletter
\def\cl@chapter{\@elt {theorem}}
\makeatother
\usepackage{cleveref}%[2013/12/28]
\crefformat{footnote}{#2\footnotemark[#1]#3}
\journalname{Empirical Software Engineering}

\begin{document}
\title{Test project}
\author{Author 1         \and
        Author 2
}
\institute{Author 1 \at
              University of X \\
              \email{[email protected]}           
           \and
           Author 2 \at
              University of X
}
\date{Received: date / Accepted: date}
\maketitle

\begin{abstract}
Abstract
\keywords{keywords}
\end{abstract}

\section{Introduction}
Intro here ...

\section{Literature Review}
Lit review here \cite{Test1} ...

\newgeometry{bottom=0.5cm}
\begin{table}[htbp]
\centering
  \begin{adjustbox}{center}
  \caption{A review of previous methods and their used information for solving the problem}
\setlength\tabcolsep{2pt}
\hskip-13mm 
    \begin{tabular}{|m{16mm}?c|p{120mm}|c|c|c|}
    \hline
    \multirow{2}{*}{Method} & \multirow{2}{*}{Year} & \multicolumn{1}{c|}{\multirow{2}{*}{A summary of the techniques used}} & \multicolumn{3}{c|}{Definition of users} \\
\cline{4-6}          &       &       & \parbox{14mm}{\linespread{1}\selectfont{}\centering Final commenter} & \parbox{11mm}{\linespread{1}\selectfont{}\centering Closer / opener} & \parbox{11mm}{\linespread{1}\selectfont{}\centering Drafted login ...} \\
    \Xhline{5\arrayrulewidth}
    Method 1 \cite{Test1}  & 2004  & Method 1's description: This shows how the method works in different situations and what it has that is not mentioned in other works.  &       & \checkmark     & \checkmark \\ \hline
    ML1 & 2006  & Uses \textbf{Support Vector Machines (SVM)} classifier and text categorization to classify and label the input data (documents) into people (categories). Also used other machine learning approaches like and Naive Bayes to solve the problem. There are some Natural Language Processing (NLP) methods used in this method in order to remove stop words and filter extra keywords. &       & \checkmark     &  \\ \hline
    InformationRetrieval1  & 2009  & This method utilizes Bag of words;
    It Employed the \textbf{Vector Space Model (VSM)} and relies on a vocabulary of ``technical terms'' collected from the users' messages in the Facebook posts and the comments people made on his posts. The users' posts are  modeled as a big document and then a term vector, based on each user's history. Given a new topic, their approach finds closest user --according to the \textbf{cosine distance}-- is identified. & \checkmark     &       & \checkmark \\ \hline
    \end{tabular}
  \label{tab:previousMethods}
  \end{adjustbox}
  \vspace{-10pt}
\enlargethispage{-\baselineskip}
\end{table}
\restoregeometry

Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
Continue literature review ... 
\printbibliography % Prints the bibliography
\end{document}

模板中的完整代码在这里:https://www.overleaf.com/9886798djbxjmvvhnjv#/36227506/

我尝试了不同的解决方案,这些解决方案可以单独运行,但它们在本例中不起作用,可能是因为使用的模板(上例中 overleaf 中当前可用的 .clo 和 .cls 文件)。请随意复制整个项目并在 overleaf 中单独测试。

我非常感激能够解决上述任何问题。

答案1

在此处输入图片描述

您的表格非常大……\resizebox导致其内容几乎无法阅读。除此之外,列类型不允许将单元格文本拆分成多行。

我建议在第一列中使用列类型tabularx的变体X,减少最宽列的宽度并更改表格的页面大小(使用\newgeometry):

\RequirePackage{fix-cm}
\RequirePackage{amsmath}
\documentclass{article}%{svjour3}
\usepackage[showframe]{geometry}
%\usepackage[backend=biber, maxnames=10, minnames=10]{biblatex}
%\addbibresource{project.bib}
%\smartqed  % flush right qed marks, e.g. at end of proof
%\usepackage{graphicx}
%\usepackage{floatrow}
\usepackage{lipsum}
\usepackage[group-separator={,},group-minimum-digits=4]{siunitx}
%\usepackage{adjustbox}
\usepackage{changepage}
%\usepackage{afterpage}
\usepackage{amssymb}
%\usepackage{comment}
\usepackage{makecell, multirow, tabularx}
\usepackage{ragged2e}
\newcolumntype{?}{!{\vrule width 2pt}}
\newcolumntype{L}{>{\RaggedRight}X}
%\usepackage{hhline}

\begin{document}

\newgeometry{hmargin=25mm,bottom=0.5cm}
\begin{table}[htp]
    \small
\centering
  \caption{A review of previous methods and their used information for solving the problem}
\setlength\tabcolsep{4pt}
    \begin{tabularx}{\linewidth}{|L ? c | p{105mm} |c|c|c|}
    \hline
    \multirow{2}{=}{Method} & \multirow{2}{*}{Year} & \multicolumn{1}{c|}{\multirow{2}{*}{A summary of the techniques used}} & \multicolumn{3}{c|}{Definition of users} \\
\cline{4-6}          &       &       & FC* & C/O* & DL* \\
    \Xhline{5\arrayrulewidth}
    Method 1 \cite{Test1}  & 2004  & Method 1's description: This shows how the method works in different situations and what it has that is not mentioned in other works.  &       & \checkmark     & \checkmark \\ \hline
    ML1 & 2006  & Uses \textbf{Support Vector Machines (SVM)} classifier and text categorization to classify and label the input data (documents) into people (categories). Also used other machine learning approaches like and Naive Bayes to solve the problem. There are some Natural Language Processing (NLP) methods used in this method in order to remove stop words and filter extra keywords. &       & \checkmark     &  \\ \hline
    Infor\-mation Retrieval1  & 2009  & This method utilizes Bag of words;
    It Employed the \textbf{Vector Space Model (VSM)} and relies on a vocabulary of ``technical terms'' collected from the users' messages in the Facebook posts and the comments people made on his posts. The users' posts are  modeled as a big document and then a term vector, based on each user's history. Given a new topic, their approach finds closest user --according to the \textbf{cosine distance}-- is identified. & \checkmark     &       & \checkmark \\ \hline
    \multicolumn{6}{l}{FC: Final Commenter, C/O: Closer/Opener, DL: Drafted Login}
    \end{tabularx}
  \label{tab:previousMethods}
\end{table}
\restoregeometry
\end{document}

答案2

这是第二种解决方案,它还使用tabularx环境来保证表格材料适合文本块的宽度。第一个主要区别是@Zarko 的回答是第三列(而不是第一列)被分配了(修改后的)X列类型。第二个主要区别是第一列和第三列都使用底层m列类型,以实现 OP 指定的垂直居中。

备注:我有adjustbox与此相关的代码,因为对于手头的表格来说它不是必需的。如果“实际”表格相当大,只需继续恢复与调整表格材料宽度相关的代码即可。

在此处输入图片描述

\documentclass{svjour3}
\usepackage[english]{babel}
\usepackage{multirow} % \multirow macro
\usepackage{geometry} % change text block size
\usepackage{makecell} % \Xhline macro
\usepackage{amssymb}  % \checkmark symbol
\usepackage{ragged2e} % \RaggedRight
\usepackage{tabularx} % 'tabularx' env., loads 'array' package
\renewcommand{\tabularxcolumn}[1]{m{#1}} % 'm' col. type
\newcolumntype{?}{!{\vrule width 2pt}}

\journalname{Empirical Software Engineering}

\begin{document}

\begin{table}[htbp]
\caption{A review of previous methods and their used information for solving the problem}
\label{tab:previousMethods}

\setlength\tabcolsep{3pt} % default: 6pt
\setlength\extrarowheight{2pt} % for a more open "look"

\begin{tabularx}{\textwidth}{|%
   >{\hspace{0pt}\RaggedRight}m{16mm} % allow hyphenation
   ? c | 
   >{\RaggedRight}X|
   c | c| c| }
\hline
\multirow{3}{*}{Method} & \multirow{3}{*}{Year} & \multicolumn{1}{c|}{\multirow{3}{*}{A summary of the techniques used}} & \multicolumn{3}{c|}{Definition of users} \\
\cline{4-6}
& & & Final & Closer/ & Drafted \\[-2pt]
& & & commenter & opener & login\dots \\
\Xhline{5\arrayrulewidth}

Method 1 \cite{Test1}  & 2004  & Method 1's description: This shows how the method works in different situations and what it has that is not mentioned in other works.  
&  & \checkmark & \checkmark \\ 
\hline

ML1 & 2006  & Uses \textbf{Support Vector Machines (SVM)} classifier and text categorization to classify and label the input data (documents) into people (categories). Also used other machine learning approaches like and Naive Bayes to solve the problem. There are some Natural Language Processing (NLP) methods used in this method in order to remove stop words and filter extra keywords. 
& & \checkmark & \\ 
\hline

Information\-Retrieval1  & 2009  & This method utilizes Bag of words; It Employed the \textbf{Vector Space Model (VSM)} and relies on a vocabulary of ``technical terms'' collected from the users' messages in the Facebook posts and the comments people made on his posts. The users' posts are modeled as a big document and then a term vector, based on each user's history. Given a new topic, their approach finds closest user---according to the \textbf{cosine distance}---is identified. 
& \checkmark & & \checkmark \\ 
\hline
\end{tabularx}

\end{table}
\end{document}

相关内容