From 25de7c1c25e0bd6b137f91c02c2b2b603fd6b0b6 Mon Sep 17 00:00:00 2001 From: dmkaplan2000 Date: Mon, 3 Aug 2020 22:57:47 +0200 Subject: [PATCH] Improvements to OUP format (#284) --- NEWS.md | 4 +++ R/article.R | 4 +-- .../oup_article/resources/template.tex | 15 ++++++++++- .../oup_article/skeleton/skeleton.Rmd | 27 +++++++++++++++---- man/article.Rd | 1 - 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index a3423331d..82aa499c0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,10 @@ rticles 0.15 - Added support for George Kour's arXiv preprint format (thanks, @alexpghayes, #236). +- Update to OUP format for `knitr::kable` table generation and optionally placing floats at end of document (thanks, @dmkaplan2000, #279). + +- Update to OUP format to use `pandoc-citeproc` by default for citations (thanks, @dmkaplan2000, #289). + rticles 0.14 --------------------------------------------------------------------- diff --git a/R/article.R b/R/article.R index 03db85b43..793a4fd5f 100644 --- a/R/article.R +++ b/R/article.R @@ -186,11 +186,11 @@ mnras_article <- function(..., keep_tex = TRUE, fig_caption = TRUE) { #' @export #' @rdname article oup_article <- function( - ..., citation_package = 'natbib', keep_tex = TRUE, + ..., keep_tex = TRUE, md_extensions = c("-autolink_bare_uris") ) { pdf_document_format( - "oup_article", citation_package = citation_package, + "oup_article", keep_tex = keep_tex, md_extensions = md_extensions, ... ) } diff --git a/inst/rmarkdown/templates/oup_article/resources/template.tex b/inst/rmarkdown/templates/oup_article/resources/template.tex index 7f840d567..529a15731 100644 --- a/inst/rmarkdown/templates/oup_article/resources/template.tex +++ b/inst/rmarkdown/templates/oup_article/resources/template.tex @@ -8,6 +8,10 @@ \usepackage{fancyvrb} \usepackage{framed} +% For knitr::kable functionality +\usepackage{booktabs} +\usepackage{longtable} + %% To allow better options for figure placement %\usepackage{float} @@ -54,7 +58,6 @@ \providecommand{\tightlist}{% \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} - % Part for setting citation format package: natbib $if(natbib)$ \usepackage{natbib} @@ -71,6 +74,16 @@ $endif$ $endif$ +% Part for indenting CSL refs +$if(csl-refs)$ +\newlength{\cslhangindent} +\setlength{\cslhangindent}{1.5em} +\newenvironment{cslreferences}% + {$if(csl-hanging-indent)$\setlength{\parindent}{0pt}% + \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces$endif$}% + {\par} +$endif$ + % Pandoc header $for(header-includes)$ $header-includes$ diff --git a/inst/rmarkdown/templates/oup_article/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/oup_article/skeleton/skeleton.Rmd index 1c88405e4..7385a7ca7 100644 --- a/inst/rmarkdown/templates/oup_article/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/oup_article/skeleton/skeleton.Rmd @@ -33,15 +33,17 @@ keywords: # - endnotes bibliography: mybibfile.bib output: rticles::oup_article +#header-includes: +# - \usepackage[nomarkers,tablesfirst]{endfloat} # For figures and tables at end +# - \usepackage{lineno} # For line numbering +# - \linenumbers # For line numbering --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = FALSE) # By default, hide code; set to TRUE to see code -knitr::opts_chunk$set(fig.pos = 'p') # Places figures on their own pages +knitr::opts_chunk$set(fig.pos = 'p') # Places figures on pages separate from text knitr::opts_chunk$set(out.width = '100%', dpi=300) # Figure resolution and size knitr::opts_chunk$set(fig.env="figure") # Latex figure environment - -library(xtable) # Creates tables that follow OUP guidelines; other options, such as kable, may also be workable ``` # Introduction @@ -77,7 +79,7 @@ A bullet list: # Results -Generate a figure. +## Generate a figure. ```{r fig1, fig.cap="This is the first figure.",echo=TRUE} plot(1:10,main="Some data",xlab="Distance (cm)",ylab="Time (hours)") @@ -91,16 +93,31 @@ plot(1:5,pch=19,main="Some data",xlab="Distance (cm)",ylab="Time (hours)") Reference to second figure: Fig. \ref{fig:fig2} -Generate a table. +## Generate a table using `xtable` ```{r tab1, results="asis", echo=TRUE} df = data.frame(ID=1:3,code=letters[1:3]) + +# Creates tables that follow OUP guidelines using xtable +library(xtable) print(xtable(df,caption="This is the table caption",label="tab:tab1"), comment=FALSE) ``` You can reference this table as follows: Table \ref{tab:tab1}. +## Generate a table using `kable` + +```{r anothertable, echo=TRUE} +df = data.frame(ID=1:3,code=letters[1:3]) + +# kable can alse be used for creating tables +knitr::kable(df,caption="This is the table caption",format="latex", + booktabs=TRUE,label="tab2") +``` + +You can reference this table as follows: Table \ref{tab:tab2}. + # Discussion You can cross-reference sections and subsections as follows: Section \ref{materials-and-methods} and Section \ref{a-subsection}. diff --git a/man/article.Rd b/man/article.Rd index 63cee91e0..1fb9fea66 100644 --- a/man/article.Rd +++ b/man/article.Rd @@ -76,7 +76,6 @@ mnras_article(..., keep_tex = TRUE, fig_caption = TRUE) oup_article( ..., - citation_package = "natbib", keep_tex = TRUE, md_extensions = c("-autolink_bare_uris") )