1

I'm using longtable to create a my table. I am getting the table I want but I'm getting this error:

Misplaced \noalign. You have used a \hline command in the wrong place, probably outside a table. If the \hline command is written inside a table, try including \ before it.

Here is the code of my table:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage[hmargin=2cm]{geometry}

\usepackage{array}
\usepackage{booktabs}
\usepackage{longtable}

\begin{document}
\begin{center}
\begin{longtable}{|l|l|l|l|l|}
\caption{Tableau récapitulatif des modèles de prédiction de l’évolution de communautés dans la littérature} \label{tab:long} \\

\hline \multicolumn{1}{|c|}{\textbf{Méthode}} & \multicolumn{1}{c|}{\textbf{Entrée}} & \multicolumn{1}{c|}{\textbf{Algorithme}}  & \multicolumn{1}{c|}{\textbf{Validation} } & \multicolumn{1}{c|}{\textbf{Résultats}} \\ \hline 
\endfirsthead
\hline \multicolumn{5}{|r|}{{(Voir la page suivante)}} \\ \hline
\endfoot

\hline \hline
\endlastfoot
\parbox{62pt}{\raggedright 
\cite{Goldberg2011}
} & \parbox{88pt}{\raggedright 
\addlinespace
\textbullet{} Métriques significatives : la densité, l’intersection et la taille du noyau d’une communauté.
\addlinespace
} & \parbox{79pt}{\raggedright 
\textbullet{ }Prédicteur de durée de vie d’une communauté.
} & \parbox{71pt}{\raggedright 
\textbullet{} Leave-one-out cross validation.
} & \parbox{78pt}{\raggedright 
\addlinespace
\textbullet{} Les communautés intenses, petites et stables ont les plus longues durées de vie.
\addlinespace
} \\
\hline
\end{longtable}
\end{center}
\end{document}

How can I escape those errors?

  • what you like to achieve with \addlinespace? more vertical space around cells? – Zarko Jan 15 '17 at 20:45
  • Yes. I want to get margins. – Joker 00 Jan 15 '17 at 20:52
  • This can be obtain with makecell package. See my answer. – Zarko Jan 15 '17 at 21:03
  • Please always cite the full error message from the log. – Martin Schröder Jan 16 '17 at 8:39
4

It is not clear to me, what you like to achieve with \addlinespace (erors done with your use is explained in David Carlisle answer). More vertical space around cells? For more items in one cell, I would use (adopted for use in table) \itemize environment:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage[hmargin=2cm]{geometry}

\usepackage[labelfont=bf,skip=3pt]{caption}
\usepackage{ragged2e}
\usepackage{array, booktabs, longtable, makecell}
\renewcommand\theadfont{\bfseries\normalsize}
    \usepackage{enumitem}       % for nice list
\newlist{tabitemize}{itemize}{1}% <-- defined new list
\setlist[tabitemize]{nosep,     % <-- new list setup
                     topsep     = 0pt       ,
                     partopsep  = 0pt       ,
                     leftmargin = *         ,
                     label      = $\bullet$ ,
                     before     = \vspace{-\baselineskip},
                     after      = \vspace{-\baselineskip}
                     }

\begin{document}
{   \setcellgapes{3pt}
    \makegapedcells
\begin{longtable}{|l|
                *{3}{>{\RaggedRight}p{98pt}|}
                     >{\RaggedRight\arraybackslash}p{98pt}|}
    \caption{Tableau réapitulatif des modèles de prédiction de l’évolution de communautés dans la littérature}
\label{tab:long} \\
    \hline 
\thead{Méthode} &   \thead{Entrée}  &   \thead{Algorithme}    
    &   \thead{Validation}  &   \thead{Résultats}       \\ 
    \hline
\endfirsthead
    \hline 
\multicolumn{5}{|r|}{{(Voir la page suivante)}}         \\ 
    \hline
\endfoot
    \hline \hline
\endlastfoot
\cite{Goldberg2011}
    &   \begin{tabitemize}
        \item   Métriques significatives : la densité, l’intersection et la taille du noyau d’une communauté.
        \end{tabitemize}
    &   \begin{tabitemize}
        \item   Prédicteur de durée de vie d’une communauté.
        \item   Prédicteur de durée de vie d’une communauté.
        \end{tabitemize}
    &   \begin{tabitemize}
        \item   Leave-one-out cross validation.
        \item   Leave-one-out cross validation.
        \item   Leave-one-out cross validation.
        \end{tabitemize}
    &   \begin{tabitemize}
        \item   Les communautés intenses, petites et stables ont les plus longues durées de vie.
        \end{tabitemize}                                                            \\
    \hline
\end{longtable}
}
\end{document}

enter image description here

4

the full error message is

! Misplaced \noalign.
\addlinespace ->\noalign 
                         {\ifnum 0=`}\fi \@ifnextchar [{\@addspace }{\@addsp...
l.30 }
       & \parbox{79pt}{\raggedright

which shows the problem is the \addlinespace

\addlinespace has to be at the start of a table row, you can not use it inside a \parbox.

Also do not surround longtable by a center environment (it has no effect on its horizontal position, just adds spurious vertical space)

I guess the intended layout is something like

enter image description here

although I would use p columns not m so the parboxes are top aligned and the bullets line up.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage[hmargin=2cm]{geometry}

\usepackage{array}
\usepackage{booktabs}
\usepackage{longtable,array}

\begin{document}
\renewcommand\arraystretch{2}
\begin{longtable}{|l|
>{\raggedright}m{75pt}|
>{\raggedright}m{75pt}|
>{\raggedright}m{75pt}|
>{\raggedright\arraybackslash}m{75pt}|}
\caption{Tableau réapitulatif des modèles de prédiction de l’évolution de communautés dans la littérature} \label{tab:long} \\

\hline \multicolumn{1}{|c|}{\textbf{Méthode}} & \multicolumn{1}{c|}{\textbf{Entrée}} & \multicolumn{1}{c|}{\textbf{Algorithme}}  & \multicolumn{1}{c|}{\textbf{Validation} } & \multicolumn{1}{c|}{\textbf{Résultats}} \\ \hline 
\endfirsthead
\hline \multicolumn{5}{|r|}{{(Voir la page suivante)}} \\ \hline
\endfoot

\hline \hline
\endlastfoot
\cite{Goldberg2011}
&\textbullet{} Métriques significatives : la densité, l’intersection et la taille du noyau d’une communauté.
 & 
\textbullet{ }Prédicteur de durée de vie d’une communauté.
& 
\textbullet{} Leave-one-out cross validation.
& 
\textbullet{} Les communautés intenses, petites et stables ont les plus longues durées de vie.
\\
\hline
\end{longtable}

\end{document}
  • So where to put \addlinespace ? – Joker 00 Jan 15 '17 at 19:54
  • well start by deleting it as it is in error, I could not guess the intended layout (or why you have parboxes at all rather than a p column.) so I did not suggest any fix other than deleting the commands that are in error – David Carlisle Jan 15 '17 at 19:56
  • After deleting it the margins disappear. I would appreciate it if you could suggest a fix, even if that changes the table style. – Joker 00 Jan 15 '17 at 20:00
  • @Joker00 Try \strut\newline before and \newline after. – Andrew Swann Jan 15 '17 at 20:23
  • @AndrewSwann Sorry, before and after what? – Joker 00 Jan 15 '17 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.