Skip to content

Instantly share code, notes, and snippets.

@paulrougieux paulrougieux/knitrchunk

Last active Nov 19, 2015
Embed
What would you like to do?
Add a footnote in a table generated by xtable inside a Lyx document (answer from http://stackoverflow.com/a/13676007/2641825)
<<1stgenerationxtunitroot, results='asis'>>=
library(xtable)
x <- matrix(rnorm(60), ncol = 10)
x.big <- xtable(x,label='tabbig', caption='Example of longtable')
names(x.big) <- LETTERS[1:10]
names(x.big)[9] <- paste('I','footnote') # I put the tag on I letter
print(x.big,tabular.environment='longtable',floating=FALSE,
sanitize.text.function=function(str)gsub("footnote","\\footnote{my tricky footnote !!}",str,fixed=TRUE))
@
#LyX 2.1 created this file. For more info see http://www.lyx.org/
\lyxformat 474
\begin_document
\begin_header
\textclass scrartcl
\begin_preamble
\usepackage{longtable}
\end_preamble
\use_default_options true
\begin_modules
knitr
\end_modules
\maintain_unincluded_children false
\language british
\language_package default
\inputencoding utf8
\fontencoding global
\font_roman default
\font_sans default
\font_typewriter default
\font_math auto
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100
\graphics default
\default_output_format default
\output_sync 1
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref true
\pdf_bookmarks true
\pdf_bookmarksnumbered false
\pdf_bookmarksopen false
\pdf_bookmarksopenlevel 1
\pdf_breaklinks false
\pdf_pdfborder true
\pdf_colorlinks false
\pdf_backref false
\pdf_pdfusetitle true
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine natbib
\cite_engine_type authoryear
\biblio_style plainnat
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\branch NoChildDocument
\selected 0
\filename_suffix 0
\color #faf0e6
\end_branch
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header
\begin_body
\begin_layout Standard
Based on
\begin_inset CommandInset href
LatexCommand href
name "this answer"
target "http://stackoverflow.com/a/13676007/2641825"
\end_inset
which uses sanitise to insert a foot note in a table.
\end_layout
\begin_layout Standard
\begin_inset ERT
status open
\begin_layout Plain Layout
<<1stgenerationxtunitroot, results='asis'>>=
\end_layout
\begin_layout Plain Layout
library(xtable)
\end_layout
\begin_layout Plain Layout
x <- matrix(rnorm(60), ncol = 10)
\end_layout
\begin_layout Plain Layout
x.big <- xtable(x,label='tabbig', caption='Example of longtable')
\end_layout
\begin_layout Plain Layout
names(x.big) <- LETTERS[1:10]
\end_layout
\begin_layout Plain Layout
names(x.big)[9] <- paste('I','footnote') # I put the tag on I letter
\end_layout
\begin_layout Plain Layout
print(x.big,tabular.environment='longtable',floating=FALSE,
\end_layout
\begin_layout Plain Layout
sanitize.text.function=function(str)gsub("footnote","
\backslash
\backslash
footnote{my tricky footnote !!}",str,fixed=TRUE))
\end_layout
\begin_layout Plain Layout
@
\end_layout
\end_inset
\end_layout
\end_body
\end_document
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.