[Tex/LaTex] Using tabularx package with xtable package in R

marginsrtablesxtable

I am trying to solve the problem of having a latex table (produced using the xtable from R, then combined into a tex file using Sweave), exceeding the margins of my LaTeX document.

I found that one such solution can be based on the tabularx package, and I am wondering what would be the best way to implement it (or if there is a better solution I am overlooking).

Right now the only way I am thinking of is to edit print.xtable so it would work with the tabularx LaTeX package. Any other suggestions will be most welcomed.

Thanks.

update: Here is an example code for such a table:

\begin{table}
\begin{center}
\begin{tabular}{rlrrrrrr}
  \hline
 & SOSo letter's locations & resubstitution (full tree) & K-CV  (full tree) & resubstitution (prune min) & K-CV  (prune min) & resubstitution (prune min+1SE) & K-CV  (prune min+1SE) \\ 
  \hline
1 & bar\_SOSo\_top & 0.88869 & 0.86281 & 0.88794 & 0.86281 & 0.88266 & 0.85779 \\ 
  2 & bar\_SOSo\_left & 0.88618 & 0.81281 & 0.88593 & 0.81307 & 0.87362 & 0.80704 \\ 
  3 & bar\_SOSo\_right & 0.89799 & 0.79070 & 0.89774 & 0.79121 & 0.88191 & 0.78543 \\ 
  4 & bar\_SOSo\_top\_left & 0.99573 & 0.96985 & 0.99548 & 0.96985 & 0.99070 & 0.96759 \\ 
  5 & bar\_SOSo\_top\_right & 0.99221 & 0.95603 & 0.99196 & 0.95653 & 0.98995 & 0.95402 \\ 
  6 & bar\_SOSo\_left\_right & 0.99221 & 0.88920 & 0.98442 & 0.89095 & 0.97814 & 0.88995 \\ 
  7 & bar\_SOSo\_top\_left\_right & 0.99925 & 0.97111 & 0.99673 & 0.97337 & 0.98492 & 0.97261 \\ 
   \hline
\end{tabular}
\caption{Some table}
\end{center}
\end{table}

Best Answer

some combination of these might work....

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\def\tst{
  \hline
1 & bar\_SOSo\_top & 0.88869 & 0.86281 & 0.88794 & 0.86281 & 0.88266 & 0.85779 \\ 
  2 & bar\_SOSo\_left & 0.88618 & 0.81281 & 0.88593 & 0.81307 & 0.87362 & 0.80704 \\ 
  3 & bar\_SOSo\_right & 0.89799 & 0.79070 & 0.89774 & 0.79121 & 0.88191 & 0.78543 \\ 
  4 & bar\_SOSo\_top\_left & 0.99573 & 0.96985 & 0.99548 & 0.96985 & 0.99070 & 0.96759 \\ 
  5 & bar\_SOSo\_top\_right & 0.99221 & 0.95603 & 0.99196 & 0.95653 & 0.98995 & 0.95402 \\ 
  6 & bar\_SOSo\_left\_right & 0.99221 & 0.88920 & 0.98442 & 0.89095 & 0.97814 & 0.88995 \\ 
  7 & bar\_SOSo\_top\_left\_right & 0.99925 & 0.97111 & 0.99673 & 0.97337 & 0.98492 & 0.97261 \\ 
   \hline}

\begin{table}
\def\h#1{\multicolumn{1}{p{3em}}{\mbox{}\hskip0pt #1}}
\begin{center}
\begin{tabular}{rlrrrrrr}
  \hline
  & { SOSo letter's locations } & \h{ resubstitution (full tree) } & \h{ K-CV  (full tree) } & \h{ resubstitution (prune min) } & \h{ K-CV  (prune min) } & \h{ resubstitution (prune min+1SE) } & \h{ K-CV  (prune min+1SE)} \\ 
\tst
\end{tabular}
\caption{Some table}
\end{center}
\end{table}

\begin{table}
\def\h#1{\multicolumn{1}{c}{\rotatebox{90}{#1}}}
\begin{center}
\begin{tabular}{rlrrrrrr}
  \hline
  & \h{ SOSo letter's locations } & \h{ resubstitution (full tree) } & \h{ K-CV  (full tree) } & \h{ resubstitution (prune min) } & \h{ K-CV  (prune min) } & \h{ resubstitution (prune min+1SE) } & \h{ K-CV  (prune min+1SE)} \\ 
\tst
\end{tabular}
\caption{Some table}
\end{center}
\end{table}


\end{document}
Related Question