Text FormattingPrinting xTable in margin with page breaks

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
SuzuBell
Posts: 14
Joined: Sat Dec 13, 2014 7:08 am

Printing xTable in margin with page breaks

Post by SuzuBell »

I recently posted about trying to print text in margin that was justified and would page-break (http://latex-community.org/forum/viewto ... 44&t=26434).

I have posted on other sites as well, and it did not seem doable for me to accomplish the page-break in the margin notes (instead the text simply falls off the bottom of the page).

Now, I am trying a different approach. I have an xtable (of 26 rows). I am trying to print this xtable in the margins. It will start on the first page, and end on the second page. Hence, I am trying to now page-break this xtable in the margins.

My approach is shown below. If you remove the third (last) chunk, you can see the page format works so far. There is main text, and then there are two figures in the margin.

The third chunk is intended to add the xtable below the two figures in the margin (it should start on the first page and continue to the second page). However, I am receiving an error that values.pdf does not exist (whereas mtcars1.pdf and mtcars2.pdf were successfully created).

Any advice to achieve this (even if another approach is needed) is greatly appreciated!

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}

\makeatletter
\makeatother
\newcounter{marginresume}

\begin{document}

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

<<echo=FALSE,results='asis'>>=
  
fname1="mtcars1.pdf"
pdf(fname1,width=4,height=4)
print(qplot(mpg,cyl,data=mtcars))
{dev.off();invisible()}
cat(sprintf('\\begin{marginfigure}
            \\includegraphics[width=0.98\\linewidth]{%s}
            \\caption{\\label{mar:myQplot}Plot of MPG and CYL.}
            \\end{marginfigure}',sub('\\.pdf','',fname1)))

cat("\\marginnote{\n\n \\bigskip{} \n\n} ")

fname2="mtcars2.pdf"
pdf(fname2,width=4,height=4)
print(qplot(hp, qsec, data=mtcars))
{dev.off();invisible()}
cat(sprintf('\\begin{marginfigure}
            \\includegraphics[width=0.98\\linewidth]{%s}
            \\caption{\\label{mar:myQplot2}Plot of HP and QSEC.}
            \\end{marginfigure}',sub('\\.pdf','',fname2)))

cat("\\marginnote{\n\n \\bigskip{} \n\n} ")
@
  
This is the main body of text. This is the main body of text. This is the main body of text. This is the main body of text. This is the main body of text. This is the main body of text. This is the main body of text. This is the main body of text. This is the main body of text. This is the main body of text. This is the main body of text. This is the main body of text. This is the main body of text. This is the main body of text. 
        
<<echo=FALSE,results='asis'>>=
myDF = data.frame(vals=runif(26, 1, 10))
row.names(myDF) = letters

fname3="values.pdf"
pdf(fname3,width=4,height=4)
print(xtable(myDF,caption='List of letters and values.',label='tab:lettersVal',align='lr'),floating=FALSE, tabular.environment = "longtable")
{dev.off();invisible()}
cat(sprintf('\\begin{marginfigure}
            \\includegraphics[width=0.98\\linewidth]{%s}
            \\caption{\\label{mar:myDFPlot}Plot of Letters and Values.}
            \\end{marginfigure}',sub('\\.pdf','',fname3)))
@

\end{document}

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

Re: Printing xTable in margin with page breaks

Post by Johannes_B »

You have mentioned that you posted the problem on other sites as well. Please crosslink all topics against each other. This is like brain storming and gets new ideas.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
SuzuBell
Posts: 14
Joined: Sat Dec 13, 2014 7:08 am

Re: Printing xTable in margin with page breaks

Post by SuzuBell »

Okay, great idea. Here are the other two sites that I have posted this question:

1) https://stackoverflow.com/questions/311 ... age-breaks

2) http://tex.stackexchange.com/questions/ ... age-breaks
Post Reply