2

As the title, I want my table place in the middle of paper.

It is also to notice: LaTeX Error: \begin{document} ended by \end{longtable}. how can I fix it ?

This is my code:

\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}

3 Answers 3

4

Your table (at least, in the example) is not long, is wide.

The longtable enviroment is similar to tabular for tables that are longer than one page.

I suggest you use tabularx within a table environment:

\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}

enter image description here

2
  • +1. :-) A little nit: Since you're setting the target width of the tabularx environment to \linewidth, the \centering instruction isn't needed.
    – Mico
    Apr 25 at 9:53
  • 1
    @Mico Thank you, I updated my answer.
    – CarLaTeX
    Apr 25 at 18:08
2

First, I can't see a good reason for employing a longtable environment; use a table environment instead. Second, you need to allow for automatic line-breaking in the cells of columns 1 and 2. (Depending on how narrow the text block is, you may also want to allow automatic line-breaking in column 6.)

I suggest you replace tabular with tabularx, set the target width to \textwidth, and employ a centered version of the X column type for columns 1 and 2.

enter image description here

\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}
0

Try with table environnement, like this :

\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}

Insure you load needed packages, like tabularx and float in the preamble.

Result :

enter image description here

2
  • I also try this but the table still not in the middle Apr 25 at 3:41
  • 1
    I think the problem is the content inside the column is too long but I dont know how to make it auto split it. Apr 25 at 3:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .