Skip to content

Instantly share code, notes, and snippets.

@ericpgreen
Last active December 22, 2015 16:29
Show Gist options
  • Save ericpgreen/6500054 to your computer and use it in GitHub Desktop.
Save ericpgreen/6500054 to your computer and use it in GitHub Desktop.
template for writing an article in RStudio that combines text + R code and compiles into .tex and .pdf via LaTeX
%-------------------------------------------------------------------------------
% Title
% Code written by AUTHOR, email
% Date
% Other notes
%-------------------------------------------------------------------------------
\documentclass[authoryear,11pt]{elsarticle} % requires elsarticle package
\usepackage[T1]{fontenc}
\usepackage{enumerate}
\usepackage{graphics}
\usepackage{graphicx}
\usepackage[shortlabels]{enumitem}
\setlist[itemize]{noitemsep, topsep=0pt}
\usepackage{lmodern}
\usepackage{threeparttable}
\usepackage{booktabs}
\usepackage{dcolumn}
\usepackage[group-separator={,}]{siunitx}
\usepackage{float}
\usepackage{url}
\usepackage[english]{babel}
\usepackage{multirow}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e}
\usepackage[dark,bottom,none]{draftcopy}
\usepackage[colorlinks=true,
urlcolor=blue, % external links
citecolor=blue, % citations
filecolor=blue, % local files
linkcolor=blue,
]{hyperref}
%\usepackage{endfloat}
%\usepackage[super, sort, numbers]{natbib}
%\usepackage[round]{natbib}
\def\citeapos#1{\citeauthor{#1}'s (\citeyear{#1})}
\usepackage{rotating}
\usepackage{parskip}
\usepackage[margin=1in]{geometry}
\usepackage{caption}
\newcommand*{\h}{\hspace{5pt}}% for indentation
\newcommand*{\hh}{\h\h}% double indentation
\usepackage[toc,page]{appendix}
\usepackage{array}
\usepackage{parskip}
\usepackage{fancyhdr}
\pagestyle{fancy}
\lhead{}
\chead{}
\fancyfoot[C]{}
\rhead{Header \thepage} % change
\renewcommand{\headrulewidth}{0pt}
% \usepackage{Sweavel} % only helpful for including code chunks
\usepackage{inconsolata}
\usepackage{listings}
\lstset{breaklines=true} % break long lines
% get rid of footer included in elsarticle
\makeatletter
\def\ps@pprintTitle{%
\let\@oddhead\@empty
\let\@evenhead\@empty
\def\@oddfoot{}%
\let\@evenfoot\@oddfoot}
\makeatother
\begin{document}
\bibliographystyle{apalike}
\begin{frontmatter}
\title{This is my title}
\author[add1]{Author1\corref{cor1}}
\ead{mail@email.com}
\author[add2]{Author2\corref}
\ead{mail@email.com}
\author[add3]{Author3\corref}
\ead{mail@email.com}
\cortext[cor1]{Note about correspondence}
\address[add1]{Affilition, address}
\address[add2]{Affilition, address}
\address[add3]{Affilition, address}
\begin{abstract}
This is my abstract
\end{abstract}
\begin{keyword}
my, key, words
\end{keyword}
\end{frontmatter}
\newpage
\section*{Acknowledgements} % include * removes from numbering
Say something nice.
\newpage
% \newpage % uncomment to add a table of contents
% \tableofcontents
% \newpage
\section{Introduction}
Main text and R code chunks go here
<<setup, include=FALSE>>==
# set chunk options
# if the .rnw file is in a folder 1-level inside the root folder
# R thinks the working directory is inside
# so set root.dir up one level
opts_knit$set(root.dir = '../')
# same issue for figures
opts_chunk$set(echo=FALSE, fig.path='../output/figures/',
cache=TRUE, tidy=FALSE, dev='pdf', echo=FALSE, message=FALSE,
include=FALSE)
@
\newpage
\section{References}
\bibliography{refs} % refs.bib needs to go in same directory as .swf file
% \begin{appendices} % uncomment to add appendices
% \end{appendices}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment