Graphics, Figures & TablesConvert xtable into multiple columns

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
greenStone
Posts: 2
Joined: Sat Jun 06, 2015 8:29 pm

Convert xtable into multiple columns

Post by greenStone »

I have an .Rnw file in RStudio (which I am pasting below). I am displaying a data frame using the xtable() function. In the example below, the data frame contains 26 rows. I convert the .Rnw file to .tex to .pdf, using the following commands:

Code: Select all

library(knitr)
knit("code.Rnw","code.tex")
pdflatex code.tex
Here is the .Rnw file:

Code: Select all

\documentclass[12pt,english,nohyper]{tufte-handout}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage[space]{grffile}
\usepackage{geometry}
\usepackage{pgffor}
\usepackage{caption}
\usepackage{calc}
\usepackage{enumitem}
\usepackage{microtype}
\usepackage{tabularx} % specify width of xtable

\makeatletter
\makeatother
\newcounter{marginresume}

\begin{document}

<<include=FALSE>>=
library(ggplot2)
library(reshape2)
library(xtable)
library(dplyr)
library(stringr)
@

<<echo=FALSE,results='asis'>>=
set.seed(1)
myDF = data.frame(vals=runif(26, 1, 10))
row.names(myDF) = letters

print(xtable(myDF,caption='This is the caption to my data frame',align='lr'),floating=FALSE, tabular.environment = "longtable")

#align(x.width) <- "|X|X|X|" #Not working
@

\end{document}

This does generate a nice xtable() output, with 26 rows:
This is the current output.
This is the current output.
tableOrig.png (36.06 KiB) Viewed 4516 times
However, as the column width is very small, I have a very long and narrow xtable() output.

Instead, I would like to automate the display of the xtable() output such that there are three tables produced, side-by-side. In this case, there would be 9 rows in the left-most table, 9 rows in the middle table, and 8 rows in the right-most table. It would look something like this:
This is the ideal output.
This is the ideal output.
tableCol.png (28.33 KiB) Viewed 4516 times
Is it possible to accomplish this? This is an automated process, and so the input data frame will not always be 26 rows. Instead, the row number will vary.

Thank you for any advice!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Convert xtable into multiple columns

Post by Johannes_B »

Never used knitr and don't know anything about its capabilities concerning LaTeX output, but maybe the following helps you: Automatic way to break narow tables into two columns
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply