0

I am trying to format a "paragraph" table column using \raggedright. However, it generates an error "\midrule ->\noalign". Thanks for any help:

% Test.tex
%--------------
\documentclass{article}
\usepackage{calc}
\usepackage{array}
\usepackage{booktabs}
%\usepackage[document]{ragged2e} % Has no effect
\begin{document}

% This works: \begin{tabular}{>{\centering}p{\widthof{Symbolic}}lp{3.5in}}

% This yields error "\midrule ->\noalign": %\begin{tabular}{>{\centering}p{\widthof{Symbolic}}l>{\raggedright}p{3.5in}}

\toprule Symbolic algebra & Code variable & Explanation \ \midrule $x_i$ & ifPrj(i) & The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs. \ \bottomrule

\end{tabular}

\end{document}

This page was cited as answering the question, but I find that the information is much more broadly encompassing about how to use alignment commands. My question here is very focused on a specific error. People are likely to search based on a specific error.

1 Answers1

1

I feel like an...extremely unintelligent person. The problem is solved by replacing all \\ with \tabularnewline:

\documentclass{article}
\usepackage{calc}
\usepackage{array}
\usepackage{booktabs}
\begin{document}

\begin{tabular}{>{\centering}p{\widthof{Symbolic}}l>{\raggedright}p{3.5in}}

\toprule Symbolic algebra & Code variable & Explanation \tabularnewline \midrule $x_i$ & ifPrj(i) & The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs. The quick brown fox jumped over the lazy dogs. \tabularnewline \bottomrule

\end{tabular}

\end{document}

Based on egreg's comment, I found a more complete description of the problem and solutions here. One has to search for the phrase "The problem is that \raggedright redefines \\".

  • 2
    It's a lot easier to do what egreg told you to. – daleif Sep 09 '22 at 18:28
  • Both approaches are described in the PDF document cited in this answer. Since I didn't come up with egreg's answer, I don't feel that it would be right for me to post it. – user2153235 Sep 09 '22 at 19:06