简体   繁体   English

在 LaTex 中使用 tabularx 关闭列表

[英]close column table with tabularx in LaTex

I'm new to LaTex and I'm trying to create a table with items, but I'm having issues with closing the table borders.我是 LaTex 的新手,我正在尝试创建一个包含项目的表格,但我在关闭表格边框时遇到了问题。 When I add "|"当我添加“|” to the {tabularx}, I get a new column that I don't want.到 {tabularx},我得到一个我不想要的新列。 I tried to follow different LaTex examples, but I'm stuck on how to close my table: My code is我尝试遵循不同的 LaTex 示例,但我被困在如何关闭我的桌子上:我的代码是

\documentclass{article}
\usepackage{tabularx}

\usepackage{paralist}

\makeatother
\begin{document}
\begin{table}[!b]
\centering


 
\caption{ Comparison between ST-Kriging, Bayesian inference, and ANNs.}
\label{tab:2}
\renewcommand{\arraystretch}{1.5}
\scriptsize

\begin{tabularx}{\textwidth} {|p{2.3cm}|p{3.5cm}|p{3.5cm}|p{3.5cm}}

\hline
\textbf{} & \textbf{Bayesian Inferences} & \textbf{ST-Kriging} & \textbf{ANNs}  \\ \hline
\textbf{Computational Complexity}   & NP-hard \cite{ref-satria2020spatial} & $O(N^2)$ & $O(i\times o\times n + n\times o)$ or $O(n \times o \times (i+1))$ for training a single epoch. \cite{ref-taylor1995freeway} \\ \hline
\textbf{Performance Evaluation }  & Provides a posterior probability distribution with confidence interval.  & 
Ensure linear unbiased predictors. & Epoch with the lowest sum of squared error.\\ \hline
\textbf{Weaknesses}   & Very computationally intensive due to choosing the proper prior distribution. 
& 

\begin{compactitem}
\item Missing value causes error in unmatched dimensions.
\item Can not handle large datasets.
\item Require normal distribution.
 \end{compactitem} 

 &
 Require intensive data training, and this might lead to an overfitting problem. \\ \hline
\textbf{Strengths }  
& 
\begin{compactitem}

\item Handle large and small data. 
\item Handle missing values.
\item Prior knowledge about uncertain input is not required.

\end{compactitem}
 &
\begin{itemize} 
\item Handle small data.
\item Computational efficiency.
\end{itemize}
&

\begin{compactitem}
\item Handle big data and small data.
\item Accommodate missing values without a separate estimation step [108]
\item Computational efficiency due to the parallelity feature.
\item Prior knowledge about uncertain input is not required.
\end{compactitem}
\\ \hline
\textbf{Overcoming the Limitation}   
&
Use uninformative prior to reduce the computational time, however, it can affect the prediction accuracy negatively.
&
Remove observations that include missing values.  
& 
\begin{compactitem}

\item Decrease the number of layers of the network.

\item  Use iterative methods to stop the training process such as gradient descent.
\end{compactitem}
    \\ \hline
\end{tabularx}


\end{table}

\end{document}

The table will look like this:该表将如下所示: 在此处输入图像描述

I believe that the issue is with this line, but I can't find a way to fix it:我相信问题出在这条线上,但我找不到解决方法:

\begin{tabularx}{\textwidth} {|p{2.3cm}|p{3.5cm}|p{3.5cm}|p{3.5cm}}

If I add "|"如果我添加“|” it will create another column instead of closing the table.它将创建另一列而不是关闭表格。 Any thoughts on what could be the issue?关于可能是什么问题的任何想法? I used "tabular" here instead of "tabularx" and I had no issue, but because I wanted to reduce the space between the list indented text, therefore I had to switch to "tabularx".我在这里使用“tabular”而不是“tabularx”,我没有问题,但是因为我想减少列表缩进文本之间的空间,所以我不得不切换到“tabularx”。

The problem is that when one sums up all your manually defined columns widths, they are larger than the available \textwidth .问题是,当总结所有手动定义的列宽度时,它们大于可用的\textwidth As you are using a tabularx environment, you could instead use X columns and latex will automatically calculate a suitable width:当您使用tabularx环境时,您可以改用X列,并且 latex 将自动计算合适的宽度:

\documentclass{article}
\usepackage{tabularx}

\usepackage{paralist}

\makeatother
\begin{document}
\begin{table}[!b]
\centering


 
\caption{ Comparison between ST-Kriging, Bayesian inference, and ANNs.}
\label{tab:2}
\renewcommand{\arraystretch}{1.5}
\scriptsize

\begin{tabularx}{\textwidth}{|X|X|X|X|}

\hline
\textbf{} & \textbf{Bayesian Inferences} & \textbf{ST-Kriging} & \textbf{ANNs}  \\ \hline
\textbf{Computational Complexity}   & NP-hard \cite{ref-satria2020spatial} & $O(N^2)$ & $O(i\times o\times n + n\times o)$ or $O(n \times o \times (i+1))$ for training a single epoch. \cite{ref-taylor1995freeway} \\ \hline
\textbf{Performance Evaluation }  & Provides a posterior probability distribution with confidence interval.  & 
Ensure linear unbiased predictors. & Epoch with the lowest sum of squared error.\\ \hline
\textbf{Weaknesses}   & Very computationally intensive due to choosing the proper prior distribution. 
& 

\begin{compactitem}
\item Missing value causes error in unmatched dimensions.
\item Can not handle large datasets.
\item Require normal distribution.
 \end{compactitem} 

 &
 Require intensive data training, and this might lead to an overfitting problem. \\ \hline
\textbf{Strengths }  
& 
\begin{compactitem}

\item Handle large and small data. 
\item Handle missing values.
\item Prior knowledge about uncertain input is not required.

\end{compactitem}
 &
\begin{itemize} 
\item Handle small data.
\item Computational efficiency.
\end{itemize}
&

\begin{compactitem}
\item Handle big data and small data.
\item Accommodate missing values without a separate estimation step [108]
\item Computational efficiency due to the parallelity feature.
\item Prior knowledge about uncertain input is not required.
\end{compactitem}
\\ \hline
\textbf{Overcoming the Limitation}   
&
Use uninformative prior to reduce the computational time, however, it can affect the prediction accuracy negatively.
&
Remove observations that include missing values.  
& 
\begin{compactitem}

\item Decrease the number of layers of the network.

\item  Use iterative methods to stop the training process such as gradient descent.
\end{compactitem}
    \\ \hline
\end{tabularx}


\end{table}

\end{document}

在此处输入图像描述

If you use tabularx one of the column should be X which adapts its width to a remaining available width.如果您使用tabularx ,其中一列应该是X ,它将其宽度调整为剩余的可用宽度。

Your table is quite wordy and due to number of columns there doesn't seem to be enough space for long texts.您的表格非常冗长,并且由于列数似乎没有足够的空间容纳长文本。 You could consider rotating a table and use a pageheight as an available space for a width of the table.您可以考虑旋转表格并将页面高度用作表格宽度的可用空间。

While correcting your table, I have also made a few adjustments:在修正你的表格的同时,我也做了一些调整:

  • indentation removed in lists to increase horizontal space在列表中删除缩进以增加水平空间
  • the caption moved upwards to add a little space between title and the table标题向上移动以在标题和表格之间添加一点空间
  • increased vertical spacing in the first row by inserting a strut通过插入支柱增加第一行的垂直间距
  • space between columns slightly decreased列之间的空间略有减少
  • added rules from booktabsbooktabs添加规则
  • reduced margins on the page with the table.减少表格页边距。

在此处输入图像描述

\documentclass{article}
\usepackage{tabularx}
\usepackage{calc}
\usepackage{paralist}
%% Added packages
\usepackage{booktabs}   % For improved rules
\usepackage{caption}    % For extra space between table and caption
\usepackage{rotating}   % For sidewaystable
\usepackage{ragged2e}   % Improves typesetting in
\usepackage{microtype}  %   in narrow environments
\usepackage{geometry}
\captionsetup[table]{position=top,skip=3pt,font=normalsize}
%% END Added packages

\setdefaultleftmargin{0em}{}{}{}{}{}


\begin{document}

\newgeometry{top=1in,bottom=1in}
\begin{sidewaystable}
  \RaggedLeft
  \setlength\tabcolsep{4pt}
  \newcommand\xstrut[1][1]{%
    \rule[-0.35\normalbaselineskip*\real{#1}]{0pt}{#1\normalbaselineskip}}
  \newcommand\xthead[1]{\normalsize\textbf{#1}}
  \renewcommand{\arraystretch}{1.25}
  \centering
  \caption{Comparison between ST-Kriging, Bayesian inference, and ANNs.}
  \label{tab:2}
  \footnotesize
  \begin{tabularx}{0.9\textwidth} {p{3cm}XXX}
    \specialrule{\heavyrulewidth}{0pt}{0pt}
    \xstrut[2.2]
    & \xthead{Bayesian Inferences}
    & \xthead{ST-Kriging}
    & \xthead{ANNs} \\
    \midrule[\heavyrulewidth]
    \textbf{Computational Complexity}
    & NP-hard \cite{ref-satria2020spatial}
    & $O(N^2)$
    & $O(i\times o\times n + n\times o)$ or $O(n \times o \times (i+1))$\newline for training a single epoch. \cite{ref-taylor1995freeway} \\
    \midrule
    \textbf{Performance Evaluation}
    & Provides a posterior probability distribution with confidence interval.
    & Ensure linear unbiased predictors.
    & Epoch with the lowest sum of squared error. \\
    \midrule
    \textbf{Weaknesses}
    & Very computationally intensive due to choosing the proper prior distribution.
    & \begin{compactitem}
        \item Missing value causes error in unmatched dimensions.
        \item Can not handle large datasets.
        \item Require normal distribution.
    \end{compactitem}
    & Require intensive data training, and this might lead to an overfitting problem. \\
    \midrule
    \textbf{Strengths }
    &
    \begin{compactitem}
      \item Handle large and small data.
      \item Handle missing values.
      \item Prior knowledge about uncertain input is not required.
    \end{compactitem}
    &
    \begin{itemize}
      \item Handle small data.
      \item Computational efficiency.
    \end{itemize}
    &
    \begin{compactitem}
      \item Handle big data and small data.
      \item Accommodate missing values without a separate estimation step [108]
      \item Computational efficiency due to the parallelity feature.
      \item Prior knowledge about uncertain input is not required.
    \end{compactitem} \\
    \midrule
    \textbf{Overcoming the Limitation}
    &
    Use uninformative prior to reduce the computational time, however, it can affect the prediction accuracy negatively.
    &
    Remove observations that include missing values.
    &
    \begin{compactitem}
      \item Decrease the number of layers of the network.
      \item  Use iterative methods to stop the training process such as gradient descent.
    \end{compactitem} \\
    \bottomrule
  \end{tabularx}
\end{sidewaystable}
\restoregeometry

\end{document}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM