4

I'm trying to create a table and I've got the error you can see in the title.

The (minimal) code is :

\begin{table}
\begin{center}
\begin{tabular}{%
|>{\centering}p{0.20\columnwidth}%
|>{\centering}p{0.19\columnwidth}%
|>{\centering}p{0.11\columnwidth}%
|>{\centering}p{0.17\columnwidth}%
|>{\centering}p{0.11\columnwidth}|}
\hline
a & b & c & d & e \\
a & b & c & d & e \\
\end{tabular}
\end{center}
\end{table} 

The number of column is okay, the end of line also ... I also get an if I insert an \hline between the two lines

The error in this case is Misplaced \noalign \hline

So far, I could correct it by having the last column without >{\centering}.

Any help greatly appreciated :-)

4

You have to use \arraybackslash for the last column:

 |>{\centering\arraybackslash}p{0.11\columnwidth}|}

to restore the \\ after \centering.

Code:

\documentclass{article}
\usepackage{array}
\begin{document}
  \begin{table}
\begin{center}
\begin{tabular}{%
|>{\centering}p{0.20\columnwidth}%
|>{\centering}p{0.19\columnwidth}%
|>{\centering}p{0.11\columnwidth}%
|>{\centering}p{0.17\columnwidth}%
|>{\centering\arraybackslash}p{0.11\columnwidth}|}
\hline
a & b & c & d & e \\
a & b & c & d & e
\end{tabular}
\end{center}
\end{table}
\end{document}
2

I would like to suggest that you use the \newcolumntype macro (provided by the array package) to define a new column type called, say, P. That way, the code needed to set up the tabular environment can be greatly simplified.

\documentclass{article}
\usepackage{array} % for "\newcolumntype" macro
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1\columnwidth}}
\begin{document}
\begin{table}
\centering  % better than "\begin{center}" and "\end{center}"
\begin{tabular}{|P{0.20}|P{0.19}|P{0.11}|P{0.17}|P{0.11}|}
\hline
a & b & c & d & e \\
a & b & c & d & e \\
\hline
\end{tabular}
\end{table} 
\end{document}

enter image description here

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.