2

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.

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149

1 Answers1

7

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}

enter image description here

Moriambar
  • 11,466