Graphics, Figures & TablesFlush text right in paragraph column of table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
jibberalan
Posts: 9
Joined: Mon Oct 18, 2010 11:52 pm

Flush text right in paragraph column of table

Post by jibberalan »

I am trying to create a table which has specified column widths and the text in these columns is right aligned. I can get this to work for every column except for the last column using '>{\raggedleft}p{3cm}'. However every time I try and use this for the last column I get a 'Misplaced \noalign. \hline ...' error followed by '! Extra alignment tab has been changed to \cr.<recently read> \endtemplate 100 &'

The following code will reproduce the error.

Code: Select all

\documentclass[11pt,letterpaper]{article}
\usepackage{array}
\begin{document}
Test table:

\begin{table}[!ht]
\begin{center}
\begin{tabular}{r >{\raggedleft}p{3cm} >{\raggedleft}p{3cm}}
\hline
test & really really long column title here & another really really long column title here \\
\hline
100 & 10 & 50000 \\
10 & 5 & 500 \\
\hline
\end{tabular}
\end{center}
\end{table}

\end{document}
If the last '>{\raggedleft}p{3cm}' is replaced with 'r' then it will be flushed right but the column label will be very long. Any help is greatly appreciated!
Last edited by jibberalan on Wed Jan 12, 2011 9:50 pm, 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.

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

Flush text right in paragraph column of table

Post by localghost »

You have to restore the functionality of the \\ command for a new tabular line. This requires an additional command only for the last column in your table head. See also the array manual.

Code: Select all

\begin{tabular}{r>{\raggedleft}p{3cm}>{\raggedleft\arraybackslash}p{3cm}}
% table content
\end{tabular}

Thorsten
jibberalan
Posts: 9
Joined: Mon Oct 18, 2010 11:52 pm

Re: Flush text right in paragraph column of table

Post by jibberalan »

Thank you very much! Exactly what I was missing.
Post Reply