/
knitr-twocolumn.Rnw
68 lines (53 loc) · 1.93 KB
/
knitr-twocolumn.Rnw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
%% LyX 2.0.5.1 created this file. For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[twocolumn]{article}
\usepackage[sc]{mathpazo}
\usepackage{geometry}
\geometry{verbose,tmargin=3cm,bmargin=3cm,lmargin=3cm,rmargin=3cm}
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
\setlength{\parskip}{\bigskipamount}
\setlength{\parindent}{0pt}
\usepackage{url}
\usepackage[unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=2,
breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
{hyperref}
\hypersetup{
pdfstartview={XYZ null null 1}}
\usepackage{breakurl}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\renewcommand{\textfraction}{0.05}
\renewcommand{\topfraction}{0.8}
\renewcommand{\bottomfraction}{0.8}
\renewcommand{\floatpagefraction}{0.75}
\makeatother
\begin{document}
<<setup, include=FALSE, cache=FALSE>>=
opts_chunk$set(fig.path='figure/twocolumn-', fig.align='center', fig.show='hold')
render_listings()
@
\title{Using knitr in A Two-column Document}
\author{Yihui Xie}
\maketitle
We can use the \texttt{figure{*}} environment in \LaTeX{} so that
figures can span over two columns. Because the output hooks use the
\textbf{framed} package which does not work well with the \texttt{figure{*}}
environment, we can either modify the output hooks or use other packages
like \textbf{listings}. For example,
<<chunk-hook, echo=2>>=
<<setup>>
@
\begin{figure*}
<<boring-plots, fig.width=5, fig.height=5, out.width='.45\\linewidth'>>=
x=rnorm(100)
par(mar=c(4,4,.1,.1))
boxplot(x)
hist(x,main='')
@
\caption{Two plots spanning over two columns.}
\end{figure*}
The output PDF file will be like: \url{https://bitbucket.org/stat/knitr/downloads/knitr-twocolumn.pdf}.
The Rnw source of this document is at \url{https://github.com/yihui/knitr/blob/master/inst/examples/knitr-twocolumn.Rnw}.
\end{document}