我想让文本环绕由 knitr 代码块生成的表格。我找到了一个常规表格的解决方案这里,但我没能为代码块生成的表格重新实现它。对于代码块生成的图形,我只是将块封闭在wrapfigure
控制序列中,但当我尝试对表格执行相同操作时,wraptable
我失败了。
整个最小代码:
\documentclass[a4paper,12pt, english]{article}
\usepackage{graphicx}
\usepackage{wrapfig}
\begin{document}
sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1
\begin{wraptable}{r}{0.5\textwidth}
<<chunk_table, results="asis", echo=FALSE>>=
library(xtable)
print(xtable(head(iris[,c(1,2)])))
@
\caption [Iris]{Table iris caption, Table iris caption, Table iris caption, Table iris caption, Table iris caption, Table iris caption}
\end{wraptable}
sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2, sample text 2
\begin{wrapfigure}{r}{0.5\textwidth}
<<image,echo=FALSE, results='asis', echo=FALSE>>=
boxplot(na.omit(iris))
@
\caption [Iris]{Figure iris caption, Figure iris caption,Figure iris caption, Figure iris caption, Figure iris caption, Figure iris caption}
\end{wrapfigure}
sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3, sample text 3
\end{document}
答案1
我认为您可以通过添加floating = FALSE
对 的调用来实现您的目标print.xtable()
。
\documentclass[a4paper,12pt, english]{article}
\usepackage{graphicx}
\usepackage{wrapfig}
\begin{document}
sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1
\begin{wraptable}{r}{0.5\textwidth}
<<chunk_table, results="asis", echo=FALSE>>=
library(xtable)
print(xtable(head(iris[,c(1,2)])), floating = FALSE)
@
\caption [Iris]{Table iris caption, Table iris caption, Table iris caption, Table iris caption, Table iris caption, Table iris caption}
\end{wraptable}
sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1, sample text 1
\end{document}