Graphics, Figures & Tablesarray | New Column Types for a Table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Third Joker
Posts: 6
Joined: Wed Oct 24, 2012 10:19 am

array | New Column Types for a Table

Post by Third Joker »

Hello everyone !

Does anyone knows why the following code isn't working ?

Code: Select all

\newcolumntype{M}[1]{>{\raggedleft}p{#1}}
\newcolumntype{N}[1]{>{\raggedright}p{#1}}

\begin{tabular}{|M{5cm}|N{4cm}|N{4cm}|}
\hline
  3  &  & \\ \hline
  3  & 4 & \\ \hline
  3& 4 & 5\\ \hline %error
\end{tabular}
The first two lines of the table works well, but once I write a value in the third cell, I get this error.

Code: Select all

! Misplaced \noalign.
Does anyone know how to fix that ?

Thanks!
TJ

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

array | New Column Types for a Table

Post by localghost »

The manual of the array package points out that you have to restore the meaning of \\ in the last column or use \tabularnewline. The declaration of the new column type has to read like this.

Code: Select all

\newcolumntype{M}[1]{>{\raggedleft\arraybackslash}p{#1}}
\newcolumntype{N}[1]{>{\raggedright\arraybackslash}p{#1}}
If that doesn't help, kindly provide a minimal example to avoid random shots and guesswork.


Thorsten
hpesoj626
Posts: 7
Joined: Thu Nov 01, 2012 4:27 pm

array | New Column Types for a Table

Post by hpesoj626 »

Include \arraybackslash after \raggedleft and \raggedright. Below is a full minimal working example incorporating your code snippet. Please include something like this in future posts.

Code: Select all

\documentclass{article}

\usepackage{array}
   \newcolumntype{M}[1]{>{\raggedleft\arraybackslash}p{#1}}
    \newcolumntype{N}[1]{>{\raggedright\arraybackslash}p{#1}}
\begin{document}
    \begin{tabular}{|M{5cm}|N{4cm}|N{4cm}|}
    \hline
             3  &  & \\ \hline
             3  & 4 & \\ \hline
             3  & 4 & 5\\ \hline %error
    \end{tabular}
\end{document}
I hope this helps.
hpesoj626
Third Joker
Posts: 6
Joined: Wed Oct 24, 2012 10:19 am

array | New Column Types for a Table

Post by Third Joker »

It works perfectly fine with the addition of \arraybackslash. Thank's a lot !!
Post Reply