Skip to content

Commit

Permalink
Improvements to OUP format (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmkaplan2000 committed Aug 3, 2020
1 parent 8757713 commit 25de7c1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions R/article.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...
)
}
Expand Down
15 changes: 14 additions & 1 deletion inst/rmarkdown/templates/oup_article/resources/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -54,7 +58,6 @@
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}


% Part for setting citation format package: natbib
$if(natbib)$
\usepackage{natbib}
Expand All @@ -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$
Expand Down
27 changes: 22 additions & 5 deletions inst/rmarkdown/templates/oup_article/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)")
Expand All @@ -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}.
Expand Down
1 change: 0 additions & 1 deletion man/article.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 25de7c1

Please sign in to comment.