[Tex/LaTex] Create linewidth spaced three columned table with column alignment

tablestabularx

I'm writing a two columned article:

\documentclass[10pt, aps, prb, twocolumn]{revtex4-1}

I would like to include a table which is as long as 1.\linewidth. The table should consist of three columns, the first two are aligned to the left and the last column should be aligned to the right. The last column should also be at the end of 1.\linewidth.

I have the following code but it is very unsatisfying. This is because I have to manually tune the size of the first two columns in order to have the final column aligned to the end of 1.\linewidth.

\noindent
\begin{tabularx}{1.\linewidth}{p{.3\linewidth} p{.3\linewidth} r}
  \hline
  Animal    & Description & Price (\$) \\
  \hline
  Gnat      & per gram    & 13.65      \\
            & each        & 0.01       \\
  Gnu       & stuffed     & 92.50      \\
  Emu       & stuffed     & 33.33      \\
  Armadillo & frozen      & 8.99       \\
  \hline
\end{tabularx}

What would be the correct approach to this problem? Am I correct in using tabularx or would you advise something else?

Best Answer

You can simply use tabular*; I present two implementations, one with \hline and the other one with the very useful package booktabs and its features. With revtex4-1, this package needs some kick.

\documentclass[10pt, aps, prb, twocolumn]{revtex4-1}
\usepackage{tabularx,array,booktabs}

\usepackage{lipsum} % just for the example

% the following code is for making the booktabs example work
\AtBeginDocument{
  \heavyrulewidth=.08em
  \lightrulewidth=.05em
  \cmidrulewidth=.03em
  \belowrulesep=.65ex
  \belowbottomsep=0pt
  \aboverulesep=.4ex
  \abovetopsep=0pt
  \cmidrulesep=\doublerulesep
  \cmidrulekern=.5em
  \defaultaddspace=.5em
}

\begin{document}
\lipsum[1]

\noindent
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}llr}
\hline
  Animal    & Description & Price (\$) \\
\hline
  Gnat      & per gram    & 13.65      \\
            & each        & 0.01       \\
  Gnu       & stuffed     & 92.50      \\
  Emu       & stuffed     & 33.33      \\
  Armadillo & frozen      & 8.99       \\
\hline
\end{tabular*}

\lipsum[2]

\noindent
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}llr}
\toprule
  Animal    & Description & Price (\$) \\
\midrule
  Gnat      & per gram    & 13.65      \\
            & each        & 0.01       \\
  Gnu       & stuffed     & 92.50      \\
  Emu       & stuffed     & 33.33      \\
  Armadillo & frozen      & 8.99       \\
\bottomrule
\end{tabular*}

\lipsum
\end{document}

enter image description here

However, I would simply typeset the table at its natural width:

\begin{center}
\begin{tabular}{llr}
\toprule
  Animal    & Description & Price (\$) \\
\midrule
  Gnat      & per gram    & 13.65      \\
            & each        & 0.01       \\
  Gnu       & stuffed     & 92.50      \\
  Emu       & stuffed     & 33.33      \\
  Armadillo & frozen      & 8.99       \\
\bottomrule
\end{tabular}
\end{center}