Skip to content
Prev 284728 / 398502 Next

width and alignment of Latex table columns

Hi

Here is an example with something at hand if you use Sweave.
Using Sweave you can embed the R in a chunk and properly format the 
headers and sometimes the table.

the D{.}{.}{4.0} requires the use of \usepackage{dcolumn}

\begin{table}[h]
\caption[DNO and \rdate]%
{DNO and \rdate with row totals}%
\label{tab:CW2}%
\centering
\begin{tabular}{p{1.0in} *{7}{D{.}{.}{4.0}}  }
\toprule
\addlinespace[3pt]
% Header
\multicolumn{1}{Measurement} \\
\addlinespace[3pt]
\midrule
\addlinespace[5pt]
%Table2
<<Table2, keep.source=FALSE, results=tex, echo=FALSE>>=

   xx <- addmargins(xx,2)

   print(
   xtable(xx,
          digits = rep(0,8)
          ),
          type    = "latex",
          floating = FALSE,
          tabular.environment = "tabular",
          include.rownames = TRUE,
          include.colnames = FALSE,
          only.contents = TRUE,
          hline.after = NULL
   ) ## xtable

@ % Table2 end
\addlinespace[5pt]
\bottomrule
\end{tabular}
\end{table}

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
ARMIDALE NSW 2351
Email: home mackay at northnet.com.au
At 22:07 9/02/2012, you wrote: