如何在表格环境中添加空单元格并逐项列出一列?

如何在表格环境中添加空单元格并逐项列出一列?

我想要像这样的表格,其中有一列中有空单元格和项目

\documentclass{proc}
%\documentclass[10pt,twocolumn,letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{url, graphicx}
%\usepackage[margin=1in]{geometry}
\usepackage{adjustbox}
\usepackage{graphicx}
 \usepackage{amsmath}
 \usepackage{amssymb}
 \usepackage{amsfonts}
\usepackage{booktabs}
% included packages
\usepackage{makecell}
\usepackage{colortbl}
      \usepackage{xcolor}
        \usepackage{cite}
       \usepackage{textcomp}
       \usepackage{tcolorbox}


       \usepackage{caption}

        \begin{table*}[]
      \begin{tabular}{@{}lllll@{}}
      \toprule
                  & Optimization methods                      & Ref & \multicolumn{1}{c|}{Merits}                                                                                                                  & Demerits                                                                          \\ \midrule
                  &                                           &     &                                                                                                                         &                                                                                   \\
                  & Gravitational Search Algorithm   (GSA)    & 147 & \tabitem Robust against initialization   \tabitem simple and easy to implement \tabitem has ability to explore local solutions         & local search ability is weak                                                      \\
                  &                                           &     &                                                                                                                         &                                                                                   \\
                  & Simulated Annealing (SA)                  & 152 & i) obtains the global optimum in   large-scale problems. Ii) not dependent on the initial solution                      & need more computation time                                                        \\
        Physics-based   algorithm &                                           &     &                                                                                                                         &                                                                                   \\
                  & intelligent Water Drops   algorithm (IWD) & 217 & i) get better solution ii) can   effectively jump out of the local optimal solution iii) approximate optimal   solution & update object is single; high   probability of global search capability           \\
                  &                                           &     &                                                                                                                         &                                                                                   \\
                  & Chaotic Optimization Algorithm   (COA)     & 218 & i) Avoid getting into the local   best and get the global optimum                                                       & aperiodicity and local   instability; blind repeat search within the search space \\
                  &                                           &     &                                                                                                                         &                                                                                   
\\ \bottomrule
    \end{tabular}
      \end{table*}

       \end{document}

答案1

以下内容可能对你来说是一个很好的起点。我的主要建议如下:

  • 加载enumitem包并使用其\newlist\setlist宏来创建一个定制的类似 itemize 的环境,tabitemize在下面的代码中调用,它在水平和垂直填充方面比基本的 LaTeXitemize环境更加节俭
  • 用允许在第 1、3 和 4 列自动换行的环境替换该tabular环境tabularx

在此处输入图片描述

\documentclass{proc}
%% \usepackage[utf8]{inputenc} % that's the default nowadays

%% [I've also streamlined the preamble to the bare essentials]
\usepackage{booktabs,tabularx,ragged2e}
\newcolumntype{L}{>{\RaggedRight}X}

% new:
\usepackage{enumitem} % see https://www.ctan.org/pkg/enumitem
\newlist{tabitemize}{itemize}{1}
\setlist[tabitemize,1]{label=\textbullet,
            nosep,left=0pt,
            before=\begin{minipage}[t]{\hsize},
            after=\end{minipage}}

\begin{document}

\begin{table*}
\begin{tabularx}{\textwidth}{@{} LlLL @{}}
\toprule
Optimization methods & Ref & Merits & Demerits  \\ 
\midrule
Gravitational Search Algorithm (GSA) 
       & 147 
       & \begin{tabitemize}
           \item robust against initialization   
           \item simple and easy to implement 
           \item has ability to explore local solutions 
         \end{tabitemize}         
       & local search ability is weak \\
\addlinespace
Simulated Annealing (SA)  
       & 152 
       & \begin{tabitemize}
           \item obtains the global optimum in large-scale problems. 
           \item not dependent on the initial solution 
         \end{tabitemize}
       & needs more computation time \\
\addlinespace
\multicolumn{4}{@{}l}{\em Physics-based algorithms} \\[0.5ex]
Intelligent Water Drops Algorithm (IWD)  
       & 217 
       & \begin{tabitemize}
           \item get better solution 
           \item can effectively jump out of the local optimal solution 
           \item approximate optimal solution 
         \end{tabitemize}
       & \begin{tabitemize}
           \item update object is single
           \item high probability of global search capability 
         \end{tabitemize} \\
\addlinespace
Chaotic Optimization Algorithm (COA)  
       & 218 
       & \begin{tabitemize}
           \item avoid getting into the local best and get the 
                 global optimum
         \end{tabitemize}
       & \begin{tabitemize}
           \item aperiodicity and local instability
           \item blind repeat search within the search space 
         \end{tabitemize} \\ 
\bottomrule
\end{tabularx}
\end{table*}

\end{document}

附录回答 OP 在评论中提出的后续问题。为了将所讨论表格的当前单页设置切换到多页设置,您需要将当前table*/tabularx组合替换为单个xltabular环境。该机制使用的语法xltabular长桌包裹。

\documentclass{elsarticle}
%%%\documentclass{proc}
%% \usepackage[utf8]{inputenc} % that's the default nowadays

%% [I've also streamlined the preamble to the bare essentials]
\usepackage{booktabs,xltabular,ragged2e} % load 'xltabular', not 'tabularx'
\newcolumntype{L}{>{\RaggedRight}X}

% new:
\usepackage{enumitem} % see https://www.ctan.org/pkg/enumitem
\newlist{tabitemize}{itemize}{1}
\setlist[tabitemize,1]{label=\textbullet,
            nosep,left=0pt,
            before=\begin{minipage}[t]{\hsize},
            after=\end{minipage}}

\begin{document}

%\begin{table*}
%\begin{tabularx}{\textwidth}{@{} LlLL @{}}
%\toprule
%Optimization methods & Ref & Merits & Demerits  \\
%\midrule

\begin{xltabular}{\textwidth}{@{} LlLL @{}}

%% headers and footers

\toprule
Optimization methods & Ref & Merits & Demerits  \\
\midrule
\endfirsthead

\multicolumn{4}{@{}l}{\small (Continued from preceding page)}\\
\addlinespace
\toprule
Optimization methods & Ref & Merits & Demerits  \\
\midrule
\endhead

\midrule
\multicolumn{4}{r@{}}{\small (continued on next page)}\\
\endfoot

\bottomrule
\endlastfoot


%% body of table

Gravitational Search Algorithm (GSA)
       & 147
       & \begin{tabitemize}
           \item robust against initialization
           \item simple and easy to implement
           \item has ability to explore local solutions
         \end{tabitemize}
       & local search ability is weak \\
\addlinespace
Simulated Annealing (SA)
       & 152
       & \begin{tabitemize}
           \item obtains the global optimum in large-scale problems.
           \item not dependent on the initial solution
         \end{tabitemize}
       & needs more computation time \\
       
\addlinespace
\multicolumn{4}{@{}l}{\em Physics-based algorithms} \\[0.5ex]

Intelligent Water Drops Algorithm (IWD)
       & 217
       & \begin{tabitemize}
           \item get better solution
           \item can effectively jump out of the local optimal solution
           \item approximate optimal solution
         \end{tabitemize}
       & \begin{tabitemize}
           \item update object is single
           \item high probability of global search capability
         \end{tabitemize} \\
\addlinespace
Chaotic Optimization Algorithm (COA)
       & 218
       & \begin{tabitemize}
           \item avoid getting into the local best and get the
                 global optimum
         \end{tabitemize}
       & \begin{tabitemize}
           \item aperiodicity and local instability
           \item blind repeat search within the search space
         \end{tabitemize} \\

%\end{tabularx}
%\end{table*}
\end{xltabular}

\end{document} 

相关内容