![使用 tabularx 包时,如何在表格中添加垂直线并将内容放在同一单元格的第二行](https://linux22.com/image/413292/%E4%BD%BF%E7%94%A8%20tabularx%20%E5%8C%85%E6%97%B6%EF%BC%8C%E5%A6%82%E4%BD%95%E5%9C%A8%E8%A1%A8%E6%A0%BC%E4%B8%AD%E6%B7%BB%E5%8A%A0%E5%9E%82%E7%9B%B4%E7%BA%BF%E5%B9%B6%E5%B0%86%E5%86%85%E5%AE%B9%E6%94%BE%E5%9C%A8%E5%90%8C%E4%B8%80%E5%8D%95%E5%85%83%E6%A0%BC%E7%9A%84%E7%AC%AC%E4%BA%8C%E8%A1%8C.png)
我想在表格中添加一条垂直线,这是我的代码。这是一篇使用模板的论文,可以看到 这里带有完整源代码。在我的 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}
答案1
您可以使用方括号中的选项来获得所需的间距等结果
[label={}, wide = 0pt, leftmargin = *, nosep, itemsep = 0pt, before = \vspace*{\baselineskip}, after =\vspace*{\baselineskip} ]
\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}