# \raggedright has unusual behaviour in tables

I'm trying to make one column in a table appear ragged right. I've had some success, depending (inexplicably, to me) on the number of columns. The following works for me:

Attempt 1

\documentclass{article}

\usepackage{graphicx}
\usepackage{dcolumn}

\begin{document}

\begin{tabular}{l>{\everypar{\raggedright}}p{7cm}l}
a & This is a test to see how paragraphs behave in this table & x \\
b & Here's another line of the table, just for the fun of it & y
\end{tabular}

\end{document}


Similarly, if I remove the first and third columns (leaving only the \raggedright column), then it still works.

However, I get errors and alignment problems when I remove the last column. In short, the following does not work:

Attempt 2

\documentclass{article}

\usepackage{graphicx}
\usepackage{dcolumn}

\begin{document}

\begin{tabular}{l>{\everypar{\raggedright}}p{7cm}}
a & This is a test to see how paragraphs behave in this table \\
b & Here's another line of the table, just for the fun of it
\end{tabular}

\end{document}


Can anyone explain why one works but the other doesn't? Also, I couldn't get either to work without the dcolumn package, which seems strange to me because that should be unrelated. Thanks for your help.

• – Werner Oct 30 '13 at 2:02
• Be very careful in using \everypar; in this case is not needed, as \raggedright is a declaration that keeps its effect in the whole current group. – egreg Oct 30 '13 at 7:42

This is how you should be doing it.

\documentclass{article}

\usepackage{graphicx}
\usepackage{array}

\begin{document}

\begin{tabular}{l>{\raggedright\arraybackslash}p{7cm}}
a & This is a test to see how paragraphs behave in this table \\
b & Here's another line of the table, just for the fun of it
\end{tabular}

\end{document}


• However, graphicx is not needed. – Dan Oct 30 '13 at 15:33
• @Dan Oh, yes. I missed it. Copy paste error. :-) – user11232 Oct 30 '13 at 21:51