1

I read many TEX questions/answers on fitting a table to your page width, but cannot figure out how to do apply it in my context (using xtable/sweave). Everything that I tried (using adjustbox, tabu) have not worked yet. I have a pretty bad overfull \hbox (262.58336pt too wide) in alignment at lines 18--41.

Here's my code and Rdata:

\documentclass{article}
\usepackage[hmargin=2.5cm,vmargin=3.5cm]{geometry}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{lscape}
\usepackage{float}
\usepackage{adjustbox}
\begin{document}
\SweaveOpts{concordance=TRUE}

<<echo=F>>=
load("Table_wratio_scaled_elasmo_nospatialtemporal.Rdata")
require(xtable)
finalx <- xtable(final2,label="bigtable",caption="List of ...")
@


\begin{landscape}
<<Final table, echo=F,results=tex>>=
print(finalx,tabular.environment="longtable", caption.placement="top",
        size="\\small", table.placement="", floating=FALSE)
@
\end{landscape}
\end{document}

Here's how the xtable output looks like:

% latex table generated in R 3.0.2 by xtable 1.7-1 package
% Thu Oct 17 08:53:16 2013
{\small
\begin{longtable}{rlrrrrrrrrrrr}
\caption{List of all fishery and mean weight (mt) of elasmobranch category captured in observed Canadian fisheries} \\ 
  \hline
 & fishery & Obs\_tspp & Obs\_Selachii & Obs\_Batoid & wratio\_Selachii & wratio\_Batoid & Obs\_Sets & log\_tspp & scaled\_Selachii & scaled\_Batoid & Obs\_proxie & scaled\_Elasmo \\ 
  \hline
1 & Total & 118025.04 & 390.78 & 493.10 &  &  & 37270.00 & 670446.67 & 3425.09 & 3273.37 &  & 6698.46 \\ 
  2 & SWORDFISH-Line & 84.85 & 81.00 & 0.07 & 0.96 & 0.97 & 62.00 & 919.91 & 892.72 & 0.62 & 9.22 & 893.34 \\ 
  3 & HALIBUT(ATL)-Line & 261.41 & 17.80 & 66.86 & 0.07 & 0.07 & 953.00 & 1793.35 & 126.37 & 498.40 & 14.58 & 624.77 \\ 
  4 & COD(ATL)-Line & 398.41 & 8.51 & 24.58 & 0.02 & 0.01 & 616.00 & 6360.91 & 130.13 & 394.79 & 6.26 & 524.92 \\ 

....

58 & CUSK-Line & 2.11 & 0.04 & 0.17 & 0.02 & 0.02 & 16.00 &  &  &  &  &  \\ 
   \hline
\hline
\label{bigtable}
\end{longtable}
1
  • is it possible to show the effective latex document for those of us without sweave set up. In particular what is the longtable argument \begin{longtable}{cccccccc} ? Commented Oct 16, 2013 at 23:35

2 Answers 2

1

Your data fits easily on the page, but your headings don't so you need to re-word them or rotate them or shorten them.

This fits for example, but may not be what you want:

 & \rotatebox{90}{fishery} & \rotatebox{90}{Obs\_tspp} & \rotatebox{90}{Obs\_Selachii} & \rotatebox{90}{Obs\_Batoid} & \rotatebox{90}{wratio\_Selachii} & \rotatebox{90}{wratio\_Batoid} & \rotatebox{90}{Obs\_Sets} & \rotatebox{90}{log\_tspp} & \rotatebox{90}{scaled\_Selachii} & \rotatebox{90}{scaled\_Batoid} & \rotatebox{90}{Obs\_proxie} & \rotatebox{90}{scaled\_Elasmo} \\ 

enter image description here

3
  • Thank you @DavidCarlisle, the problem with this command is that I cannot use with xtable/sweave. I guess I have to manipulate somehow the display of my column within xtable or as you suggested change my headings for something shorter. Should I post this question on stackoverflow since now it seems more of a xtable/R coding rather than a LaTex issue? Thank you!
    – GodinA
    Commented Oct 17, 2013 at 15:08
  • @GodinA can you not put the \rotatebox{}{long title} into sweave where you previously just put long title ? As you say if that's hard, it isn't really a TeX question anymore Commented Oct 17, 2013 at 15:29
  • @Godina actually you can do this sort of things with xtables, see the gallery/vignette, section 4.7. cran.r-project.org/web/packages/xtable/vignettes/…
    – asac
    Commented Sep 25, 2015 at 16:43
-1

Could have also done

\usepackage{rotating}
\usepackage{pdflscape}

\begin{landscape}
\begin{sidewaystable}
INSERT TABLE
\end{sidewaystable}
\end{landscape}
2
  • 4
    This answer could be improved by extending it to show a complete minimal working example (MWE) that the OP and future visitors can compile for testing purposes. For example, for this code to be successful, both the pdflscape and rotating packages are required. This is critical information for anyone hoping to use this solution. Commented Aug 19, 2014 at 19:41
  • -1. Answers on this site are usually self-contained, such that people can simply copy-paste the document and compile. This is not the case in this answer and it is therefore not useful. Commented Jul 20, 2017 at 23:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .