Generallatex table problem --about >{\centering}

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
zhengyiqun08
Posts: 2
Joined: Thu Oct 09, 2008 6:28 am

latex table problem --about >{\centering}

Post by zhengyiqun08 »

my code is as follows:
\begin{tabular}{|c |>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|}
[29-32, 34-36] & & \Checkmark & & & & &\Checkmark \\
\hline
\end{tabular}

the error indicated is "! Misplaced \noalign. \hline -> \noalign"

However, if I change this code to:
\begin{tabular}{|c |>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|}
[29-32, 34-36] & & \Checkmark & & & & &\\
\hline
\end{tabular}

or

\begin{tabular}{|c |>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|>{\centering}m{1.2 cm}|m{1.2 cm}|} %the last column without centering horizontally
[29-32, 34-36] & & \Checkmark & & & & &\Checkmark \\
\hline
\end{tabular}

No error occurs.

Can you help me fix it? Besides, why is there a ">" in this command ">{\centering}" ?
Last edited by zhengyiqun08 on Fri Oct 10, 2008 3:55 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

latex table problem --about >{\centering}

Post by gmedina »

Hi zhengyiqun08,

The array package redefines \\ (the command to change line). To avoid the error that you are getting there are two options:
1) Instead of \\ you can use \tabularnewline, as the following example suggests:

Code: Select all

\documentclass{article}
\usepackage{bbding}
\usepackage{array}

\begin{document}

\begin{tabular}{|c*{7}{|>{\centering}m{1.2 cm}}|}
  [29-32, 34-36] & & \Checkmark & & & & & \Checkmark \tabularnewline
  \hline
\end{tabular}

\end{document}
2) Use \arraybackslash just after \centering:

Code: Select all

\documentclass{article}
\usepackage{bbding}
\usepackage{array}

\begin{document}

\begin{tabular}{|c*{7}{|>{\centering\arraybackslash}m{1.2 cm}}|}
  [29-32, 34-36] & & \Checkmark & & & & & \Checkmark \\
  \hline
\end{tabular}

\end{document}
You can find the answer to the question about > in the array package documentation (page 2). There you will also find information about the shortcut that I used in the declaration of the table format.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
zhengyiqun08
Posts: 2
Joined: Thu Oct 09, 2008 6:28 am

Re: latex table problem --about >{\centering}

Post by zhengyiqun08 »

Thanks a lot, gmedina. Problem solved.
Post Reply