\documentclass[12pt, a4paper]{article} \usepackage[margin=3cm]{geometry} \usepackage{graphicx} \usepackage[utf8]{inputenc} \usepackage[natbibapa]{apacite} \linespread{1.3} \renewcommand{\doiprefix}{https://doi.org/\kern0pt} \begin{document} <>= rm(list = ls()) library(xtable) @ \begin{titlepage} \begin{center} {\LARGE Title} \vspace{2cm} {\large Author} \end{center} \vspace{2cm} \begin{abstract} Put abstract here. \end{abstract} \end{titlepage} \setcounter{page}{2} \section*{Introduction} \citet{Loetscher08} found that ... Other studies, however, reported different results \citep{Fischer10, ChenSpence11, Loetscher08}. \section*{Methods} ... \section*{Results} <>= PlantGrowth <- PlantGrowth[sample(nrow(PlantGrowth), 24), ] dat <- aggregate(weight ~ group, PlantGrowth, mean) dat$n <- aggregate(weight ~ group, PlantGrowth, length)$weight dat$sd <- aggregate(weight ~ group, PlantGrowth, sd)$weight dat$se <- dat$sd/sqrt(dat$n) m <- anova(lm(weight ~ group, PlantGrowth)) @ Figure~\ref{fig:plant} displays the yields (as measured by dried weight of plants) obtained under a control and two different treatment conditions. In total, the yields ranged from \Sexpr{min(PlantGrowth[["weight"]])} to \Sexpr{max(PlantGrowth[["weight"]])} units ($M = \Sexpr{round(mean(PlantGrowth[["weight"]]), 2)}$, $SD = \Sexpr{round( sd(PlantGrowth[["weight"]]), 2)}$). Table~\ref{tab:plant} shows the average weight per condition, $F(\Sexpr{m$Df[1]}, \Sexpr{m$Df[2]}) = \Sexpr{round(m$"F value"[1], 2)}$, $p = \Sexpr{round(m$"Pr(>F)"[1], 3)}$. \begin{figure}[b!] \centering \caption{Weight per condition\label{fig:plant}} \setkeys{Gin}{width=0.6\textwidth} <>= par(mai = c(.7, .7, .1, .1), mgp = c(2, .7, 0)) boxplot(weight ~ group, PlantGrowth) @ \end{figure} \begin{table}[ht] \centering \caption{Average weight per condition\label{tab:plant}} \begin{tabular}{lrrrr} \hline Group & $M$ & $n$ & $SD$ & $SE$ \\ <>= print(xtable(dat), only.contents=TRUE, include.rownames=FALSE, include.colnames=FALSE) @ \end{tabular} \end{table} \section*{Discussion} ... \bibliographystyle{apacite} \bibliography{bibtex-sample} \end{document}