Permalink
3350056 Aug 11, 2016
72 lines (57 sloc) 2.15 KB
%% LyX 2.2.1 created this file. For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{url}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\providecommand{\LyX}{L\kern-.1667em\lower.25em\hbox{Y}\kern-.125emX\@}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\renewcommand{\textfraction}{0.05}
\renewcommand{\topfraction}{0.8}
\renewcommand{\bottomfraction}{0.8}
\renewcommand{\floatpagefraction}{0.75}
\@ifundefined{showcaptionsetup}{}{%
\PassOptionsToPackage{caption=false}{subfig}}
\usepackage{subfig}
\makeatother
\begin{document}
<<setup, include=FALSE>>=
library(knitr)
opts_chunk$set(fig.path='figure/subfloats-')
@
\title{Using subfloats in \LyX{} with knitr}
\author{Yihui Xie}
\maketitle
If you insert a float figure inside a float figure in \LyX{}, you
will get subfloats. To make sure the two subfloats can stand side
by side, you have to:
\begin{enumerate}
\item remove new lines between the two subfloat environments in \LyX{}
(if you are not sure if there are blank lines between them, check
the \LaTeX{} source);
\item use the chunk option \texttt{echo=FALSE} to hide the R source code
in the output;
\item set \texttt{out.width} to be less than half of the linewidth if you
do not want the sub figures to exceed the page margin;
\item most importantly, leave a blank line in the beginning of the subfloat
environment, so that \texttt{<\textcompwordmark{}<>\textcompwordmark{}>=}
starts in a new line and \textbf{knitr} can recognize it;
\end{enumerate}
Figure \ref{fig:knitr-subfloat} is an example.
This document was compiled with \textbf{knitr} \Sexpr{packageVersion('knitr')}.
Rnw source at \url{https://github.com/yihui/knitr/blob/master/inst/examples/knitr-subfloats.Rnw}.
\begin{figure}
\subfloat[this is a subfloat]{
<<test-subfloat, echo=FALSE, out.width='.45\\linewidth'>>=
plot(1)
@
}\subfloat[another float]{
<<test-another, echo=FALSE, out.width='.45\\linewidth'>>=
plot(rnorm(100))
@
}
\caption{one figure with 2 sub figures\label{fig:knitr-subfloat}}
\end{figure}
\end{document}