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:
When what I am trying to do is generate output more like:
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.
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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.