Debian Codegraph @

inst/examples/knitr-subfloats.Rnw

raw
1 %% LyX 2.2.1 created this file. For more info, see http://www.lyx.org/.
2 %% Do not edit unless you really know what you are doing.
3 \documentclass{article}
4 \usepackage[T1]{fontenc}
5 \usepackage[latin9]{inputenc}
6 \usepackage{url}
7
8 \makeatletter
9
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
11 \providecommand{\LyX}{L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@}
12
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
14 \renewcommand{\textfraction}{0.05}
15 \renewcommand{\topfraction}{0.8}
16 \renewcommand{\bottomfraction}{0.8}
17 \renewcommand{\floatpagefraction}{0.75}
18
19 \@ifundefined{showcaptionsetup}{}{%
20 \PassOptionsToPackage{caption=false}{subfig}}
21 \usepackage{subfig}
22 \makeatother
23
24 \begin{document}
25 <<setup, include=FALSE>>=
26 library(knitr)
27 opts_chunk$set(fig.path='figure/subfloats-')
28 @
29
30 \title{Using subfloats in \LyX{} with knitr}
31
32 \author{Yihui Xie}
33
34 \maketitle
35 If you insert a float figure inside a float figure in \LyX{}, you
36 will get subfloats. To make sure the two subfloats can stand side
37 by side, you have to:
38 \begin{enumerate}
39 \item remove new lines between the two subfloat environments in \LyX{}
40 (if you are not sure if there are blank lines between them, check
41 the \LaTeX{} source);
42 \item use the chunk option \texttt{echo=FALSE} to hide the R source code
43 in the output;
44 \item set \texttt{out.width} to be less than half of the linewidth if you
45 do not want the sub figures to exceed the page margin;
46 \item most importantly, leave a blank line in the beginning of the subfloat
47 environment, so that \texttt{<\textcompwordmark{}<>\textcompwordmark{}>=}
48 starts in a new line and \textbf{knitr} can recognize it;
49 \end{enumerate}
50 Figure \ref{fig:knitr-subfloat} is an example.
51
52 This document was compiled with \textbf{knitr} \Sexpr{packageVersion('knitr')}.
53 Rnw source at \url{https://github.com/yihui/knitr/blob/master/inst/examples/knitr-subfloats.Rnw}.
54
55 \begin{figure}
56 \subfloat[this is a subfloat]{
57 <<test-subfloat, echo=FALSE, out.width='.45\\linewidth'>>=
58 plot(1)
59 @
60
61 }\subfloat[another float]{
62 <<test-another, echo=FALSE, out.width='.45\\linewidth'>>=
63 plot(rnorm(100))
64 @
65
66 }
67
68 \caption{one figure with 2 sub figures\label{fig:knitr-subfloat}}
69 \end{figure}
70
71 \end{document}