表格太长,不在页面中间

表格太长,不在页面中间

正如标题所示,我希望我的桌子位于纸张的中间。

还要注意: LaTeX Error: \begin{document} ended by \end{longtable}. 我该如何修复它?

这是我的代码:

\begin{longtable}

\centering

    \begin{tabular}{|c|c|c|c|c|c|}

        \hline

         Authors \& Contribution & Topic & Assumption & Scalability & Comparison  & Application\\

         \hline

         Alzahrani et al. 2018 & DDoS attack & No & No & No & Cloud computing\\

        \hline

         Biggio, et al. 2011 & Adversarial attack  & No & No & No & Cloud computing\\

         \hline

    \end{tabular}

    \label{tab:my_label}

\end{longtable}

答案1

您的桌子(至少在示例中)不是长,而是宽。

该环境与长度超过一页的表格longtable类似。tabular

我建议您tabularx在以下table环境中使用:

\documentclass{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{tabularx}
\usepackage{array}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\renewcommand{\arraystretch}{1.3}
\begin{document}
For Table \ref{tab:my_label} \verb|\centering| is not necessary because the table is as wide as the text line.
\begin{table}
  \caption{My Table}\label{tab:my_label}
  \begin{tabularx}{\linewidth}{|C|C|c|c|c|C|}
    \hline
    Authors \& Contribution & Topic & Assumption & Scalability & Comparison  & Application\\
    \hline
    Alzahrani et al. 2018 & DDoS attack & No & No & No & Cloud computing\\
    \hline
    Biggio, et al. 2011 & Adversarial attack  & No & No & No & Cloud computing\\
    \hline
  \end{tabularx}
\end{table}

For Table \ref{tab:little}, if you would like it to be centered, you should use \verb|\centering| within the \texttt{table} environment, because the table is shorter than the text line.
\begin{table}\centering
  \caption{A less wide table}\label{tab:little}
  \begin{tabular}{|c|c|c|}
    \hline
    In case & your table & is not wide\\
    \hline
    and you & would like & to center it\\
    \hline
    use \verb|\centering| & within the  & \texttt{table} environment\\
    \hline
  \end{tabular}
\end{table}
\end{document}

在此处输入图片描述

答案2

首先,我看不出使用longtable环境有什么好的理由;table应该使用环境。其次,您需要允许在第 1 列和第 2 列的单元格中自动换行。(根据文本块的宽度,您可能还希望允许在第 6 列中自动换行。)

我建议您tabular用替换tabularx,将目标宽度设置为,并对第 1 列和第 2 列\textwidth采用居中版本的列类型。X

在此处输入图片描述

\documentclass{article} % or some other suitable document class
\usepackage[a4paper,margin=2.5cm]{geometry} % set page parameters suitably
\usepackage{tabularx} % for 'tabularx' environment and 'X' column type
\usepackage{ragged2e} % for '\RaggedRight' macro
\newcolumntype{C}{>{\Centering\hspace{0pt}}X}

\begin{document}

\begin{table}
\setlength\extrarowheight{2pt} % for a less-cramped "look"
\begin{tabularx}{\textwidth}{| C | C | c | c | c | c |}
\hline
Authors \& Contribution & Topic & Assumption & Scalability & Comparison  & Application\\
\hline
Alzahrani et~al.\ 2018 & DDoS attack & No & No & No & Cloud computing\\
\hline
Biggio et~al.\ 2011   & Adversarial attack  & No & No & No & Cloud computing\\
\hline
\end{tabularx}

\caption{A table with six columns}
\label{tab:my_label}

\end{table}

\end{document}

答案3

尝试table这样的环境:

\documentclass[a4paper]{article}
\usepackage[margin=2cm]{geometry}
\usepackage{tabularx,float,multirow}
\begin{document}

\begin{table}[htb]
\centering
\begin{tabular}{|c|c|c|c|c|c|}
    \hline
     Authors \& Contribution & Topic & Assumption & Scalability & Comparison  & Application\\
     \hline
     Alzahrani et al. 2018 & DDoS attack & No & No & No & Cloud computing\\
    \hline
     Biggio, et al. 2011 & Adversarial attack  & No & No & No & Cloud computing\\
     \hline
\end{tabular}
\label{tab:my_label}
\end{table}
\end{document}

确保您加载了所需的包,例如序言中的tabularx和。float

结果 :

在此处输入图片描述

相关内容