3
votes

If I do the following command:

xtable(diamonds[1:5,1:4], label = 'tab:myTab', caption='This is my caption',align = c("rr|lr|r"))

I get the following output:

\begin{table}[ht]
\centering
\begin{tabular}{rr|lr|r}
  \hline
 & carat & cut & color & clarity \\ 
  \hline
1 & 0.23 & Ideal & E & SI2 \\ 
  2 & 0.21 & Premium & E & SI1 \\ 
  3 & 0.23 & Good & E & VS1 \\ 
  4 & 0.29 & Premium & I & VS2 \\ 
  5 & 0.31 & Good & J & SI2 \\ 
   \hline
\end{tabular}
\caption{This is my caption} 
\label{tab:myTab}
\end{table}

My question is: Is it possible to have the xtable output not {table}, but rather {table*}?

========================= EDIT =========================

I am taking into account Repmat's input. I am using the code found here (How to center LaTeX xtable output in full text width).

1) I added one package to their preamble

\usepackage{tabularx}

2) Then, I changed their command:

print(x.big, tabular.environment ='longtable', floating = FALSE, include.rownames=FALSE)

To four commands:

print(x.big, tabular.environment ='tabular*', include.rownames=FALSE, width= "\\linewidth")
print(x.big, tabular.environment ='tabular*', include.rownames=FALSE, width= "\\textwidth")
print(x.big, tabular.environment ='tabularx', include.rownames=FALSE, width = "\\linewidth")
print(x.big, tabular.environment ='tabularx', include.rownames=FALSE, width= "\\textwidth")

Each time, this generated an output as follows:

This is the new output

When what I am trying to do is generate output more like:

My goal

I would not mind having to just move the xtable over by a hard-coded specified amount too (like by 3 inches to the right) - but I have been able to figure that out as well.

2
what is the difference between {table*} and {table} ? maybe it is related to table numeration in latex, is it?SabDeM
I think {table*} is for full-page width tablesuser2808302
(mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/…) Pg. 3 shows the difference between figure and figure* environment.user2808302
Usually the starred environments in LaTeX are applied in two- or multi-column layouts, where the version with a star spans over the entire page width while the usual version is as wide as the column width.RHertel
Thanks @RHertel! I think that is right too, as per the reference I provided. Do you think it is possible to achieve this with the xtable command? I am using the xtable command in the same Tufte-Handout format given in that reference.user2808302

2 Answers

2
votes

What you need to do is specify floating.environment = "table*" in your call to print.xtable. I don't know if you used Sweave for your document, but here is an example using it. Unfortunately, latex insists on moving table* to the second page irrespective of whether there is space for it on the first or not, but here goes:

\documentclass[twocolumn]{article}
\usepackage{lipsum}

\begin{document}

<<libraries, include = FALSE>>=
library(xtable)
library(ggplot2) # for diamonds dataset
@

<<table, echo = FALSE, results = 'asis'>>=
print(xtable(diamonds[1:5,1:4], label = 'tab:myTab',
             caption='This is my caption',
             align = c("rr|lr|r")),
      floating.environment = "table*")
@

\lipsum[1-13]

\end{document}

Second page:

Imgur

-1
votes

The print.xtable command has a width argument, see page 2 in this refence manuel. I have not tried it, but you would call something like:

require(xtable)
print(xtable(object, width = "some latex command you would like"))

You can see some of examples of this in the xtable gallery - page 20.

Also note that, from a LaTeX point of view, the * does not work with tabular or longtable environments.