表格未位於頁面中間,因為它太長

表格未位於頁面中間,因為它太長

如標題,我希望我的表格位於紙張的中間。

也要注意: 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 列的儲存格中自動換行。

我建議您替換tabulartabularx,將目標寬度設為,並為第 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

結果 :

在此輸入影像描述

相關內容