使用 tabularx 包时,如何在表格中添加垂直线并将内容放在同一单元格的第二行

使用 tabularx 包时,如何在表格中添加垂直线并将内容放在同一单元格的第二行

我想在表格中添加一条垂直线,这是我的代码。这是一篇使用模板的论文,可以看到 这里带有完整源代码。在我的 latex 实现中

\documentclass[twoside,mtp]{iiitg}

\usepackage{makecell,tabularx} % for 'tabularx' env. and 'X' col. type
\renewcommand\theadfont{\normalsize}


    \begin{table}[ht]
        \centering
        \begin{tabularx}{\textwidth}{|@{} X | @{}X | @{}X |}
    \hline       
    \thead{Algorithm}   & \thead{Pros}  & \thead{Cons} \\ \hline
    \multirow{2}{*}{1. K Nearest Neighbour:  K-NN }   & Very easy to understand 
    Good for creating models that include non standard data types such as
    text             & Large Storage requirements
    Computationally Expensive
    Sensitive to the choice of the similarity function for comparing instances             \\ \hline
    Local Outlier Factor(LOF)  & 3             & 5             \\ \hline
    1               & 3             & 5             \\ \hline
        \end{tabularx}
        \caption{Anomaly Detection Algorithms comparison}
        \label{tab:my_label}
    \end{table}

算法比较
我希望 KNN 进入上述实现中同一单元格的第二行,但这并没有发生,并且使用垂直线作为边界。

答案1

您可以使用方括号中的选项来获得所需的间距等结果 [label={}, wide = 0pt, leftmargin = *, nosep, itemsep = 0pt, before = \vspace*{\baselineskip}, after =\vspace*{\baselineskip} ]

--label={}消除标签 1,2 --- 等等 在此处输入图片描述

\documentclass{article}
\usepackage{multirow}
\usepackage[shortlabels]{enumitem}





\usepackage{makecell,tabularx} % for 'tabularx' env. and 'X' col. type
\renewcommand\theadfont{\normalsize}

\begin{document}


    \begin{table}[ht]
        \centering
        \begin{tabularx}{\textwidth}{|X |X | X |}
    \hline       
    \thead{Algorithm}   & \thead{Pros}  & \thead{Cons} \\ \hline
    \begin{enumerate}[label={}, wide = 0pt, leftmargin = *, nosep, itemsep = 0pt, before = \vspace*{\baselineskip}, after =\vspace*{\baselineskip} ]
\item K Nearest Neighbour
\item K-NN
    \end{enumerate}   & 
\begin{enumerate}
    \item Very easy to understand 
    \item Good for creating models that include non standard data types such as
    text
\end{enumerate}             &
\begin{enumerate}
 \item Large Storage requirements
\item Computationally Expensive
\item Sensitive to the choice of the similarity function for comparing instances
\end{enumerate}             \\ \hline

        \end{tabularx}
        \caption{Anomaly Detection Algorithms comparison}
        \label{tab:my_label}
    \end{table}
\end{document}

相关内容