3

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.

Community
  • 1
  • 1
  • what is the difference between `{table*}` and `{table}` ? maybe it is related to table numeration in latex, is it? – SabDeM Jul 11 '15 at 17:16
  • I think {table*} is for full-page width tables –  Jul 11 '15 at 17:18
  • (http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf) Pg. 3 shows the difference between figure and figure* environment. –  Jul 11 '15 at 17:19
  • 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 Jul 11 '15 at 17:24
  • 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. –  Jul 11 '15 at 17:26

2 Answers2

2

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

Johan Larsson
  • 3,496
  • 18
  • 34
-1

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.

Repmat
  • 690
  • 6
  • 19
  • Thanks @Repmat! I have tried some of those suggestions, but it does not seem to do the job either. I am adding an EDIT to my original question, so I can put in more detail what I have tried with your suggestion. If you have any suggestions to try after my EDIT, please let me know! :) And thanks for the information about the * not working in LaTeX. –  Jul 11 '15 at 18:29
  • Do you mind me asking, do you know of a method in which I can simply print the xtable in LaTeX at a specified distance from the left margin? For instance, as default, it prints on the left side of the page. Is there any method to instead have it print, say, 3 inches from the left side of the page? Thank you for any of your thoughts... –  Jul 12 '15 at 18:06
  • That is a question, best left for the TeX stack - i.e. add a new question on their site. You can control the placement of tables, from xtable with: table.placement = getOption("xtable.table.placement", "placement"), with the command in my answer. However, you are looking for sometthing which is not standard LaTeX - you need some package. Either way, I doubt it will fit well with Xtable. – Repmat Jul 12 '15 at 19:09
  • Thanks @Repmat. So, basically, it seems difficult for me to keep the tufte-handout format, while also allowing some tables to be positioned in the center (total center, not just non-margin center) of the page? I will try to think of other get-around solutions... –  Jul 12 '15 at 19:29
  • Usually, what I do, is create a more or less well formatted table from R. Then I tweak in the tex document – Repmat Jul 12 '15 at 22:11
  • 1
    Okay thanks. I would do that, but this supposed to be something that can auto-generate the documents. These things are more difficult than I thought! –  Jul 13 '15 at 01:54