[Tex/LaTex] Last tabularx column raggedright with memoir

memoirtablestabularx

In the 3-column tabularx output produced with the following source that uses the memoir documentclass, how do I get the 3rd (last) column to be typeset ragged right rather than justified?

\documentclass{memoir}

\begin{document}

\begin{center}
\begin{tabularx}{3in}{l|>{\raggedright}X|p{0.725in}}
\toprule
\textbf{Source} & \textbf{Targets}          &\textbf{Locations}
\\\midrule[\heavyrulewidth]
09  & 99, 199, 299, 399, 499, 599, 699, 799 & boxes 5, 119, 135--136
\\\hline
200 & 399   & box 23
\\\bottomrule
\end{tabularx}
\end{center}

\end{document}

tabularx table wants ragged right last column

I tried modifying the tabularx so as to begin…

\begin{tabularx}{3in}{l|>{\raggedright}X|>{\raggedright}p{0.725in}}

… but that causes an error:

./tabularx.tex:14: Misplaced \noalign.
\hline ->\noalign 
                  {\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
l.14     \end{tabularx}

Best Answer

enter image description here

In the final column you need to use \arraybackslash to reset \\ back to ending a table row, or use \tabularnewline rather than \\

\documentclass{memoir}

\begin{document}

\begin{center}
\begin{tabularx}{3in}{l|>{\raggedright\arraybackslash}X|>{\raggedright\arraybackslash}p{0.725in}}
\toprule
\textbf{Source} & \textbf{Targets}          &\textbf{Locations}
\\\midrule[\heavyrulewidth]
09  & 99, 199, 299, 399, 499, 599, 699, 799 & boxes 5, 119, 135--136
\\\hline
200 & 399   & box 23
\\\bottomrule
\end{tabularx}
\end{center}

\end{document}