Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed a pdf in a R Markdown file and adapt pagination

I am finishing my PhD, and I need to embed some papers (in pdf format) in somewhere in the middle of my R Markdown text.

When converting the R Markdown into PDF, I would like those PDF papers to be embed in the conversion.

However, I would like those PDF papers to be also numbered according to the rest of the Markdown text.

How can I do it?


UPDATE: New error

By using \includepdf, I get this error:

output file: Tesis_doctoral_-_TEXTO.knit.md

! Undefined control sequence.
l.695 \includepdf
                 [pages=1-10, angle=90, pagecommand={}]{PDF/Paper1.pdf} 
Here is how much of TeX's memory you used:
 12157 strings out of 495028
 174654 string characters out of 6181498
 273892 words of memory out of 5000000
 15100 multiletter control sequences out of 15000+600000
 40930 words of font info for 89 fonts, out of 8000000 for 9000
 14 hyphenation exceptions out of 8191
 31i,4n,35p,247b,342s stack positions out of 5000i,500n,10000p,200000b,80000s

Error: Failed to compile Tesis_doctoral_-_TEXTO.tex. See Tesis_doctoral_-_TEXTO.log for more info.
Execution halted

EXAMPLE of the R Markdown code

---
title: Histología dental de los homininos de la Sierra de Atapuerca (Burgos, España)
  y patrón de estrategia de vida
author: "Mario Modesto-Mata"
date: "20 September 2018"
output:
  pdf_document:
    highlight: pygments
    number_sections: yes
    toc: yes
    toc_depth: 4
  word_document:
    toc: yes
    toc_depth: '4'
  html_document: default
csl: science.csl
bibliography: references.bib
header-includes:
- \usepackage{pdfpages}
---

```{r opciones_base_scripts, message=FALSE, warning=FALSE, include=FALSE, paged.print=FALSE}
library(captioner)
tabla_nums <- captioner(prefix = "Tabla")
figura_nums <- captioner(prefix = "Figura")
anx_tabla_nums <- captioner(prefix = "Anexo Tabla")
```

# Resumen

Los estudios de desarrollo dental en homínidos han sido sesgados involuntariamente en especies pre-Homo y algunos especímenes Homo tempranos, que representan la condición primitiva con tiempos de formación dental más rápidos, respetan a los Neandertales posteriores y a los humanos modernos, que comparativamente tienen tiempos de formación más lentos.

## PDF Article

\includepdf[pages=1-22, pagecommand={}]{PDF/Paper1.pdf}

## Bayes

El desarrollo dental relativo se evaluó empleando un enfoque estadístico bayesiano (31).

This is the link to download the PDF


NEW IMAGE

enter image description here

like image 668
antecessor Avatar asked Dec 22 '25 03:12

antecessor


1 Answers

I had to remove a few things from your example, but after that it worked without problems:

---
title: Histología dental de los homininos de la Sierra de Atapuerca (Burgos, España)
  y patrón de estrategia de vida
author: "Mario Modesto-Mata"
date: "20 September 2018"
output:
  pdf_document:
    highlight: pygments
    number_sections: yes
    toc: yes
    toc_depth: 4
    keep_tex: yes
  word_document:
    toc: yes
    toc_depth: '4'
  html_document: default
header-includes:
- \usepackage{pdfpages}
---


# Resumen

Los estudios de desarrollo dental en homínidos han sido sesgados involuntariamente en especies pre-Homo y algunos especímenes Homo tempranos, que representan la condición primitiva con tiempos de formación dental más rápidos, respetan a los Neandertales posteriores y a los humanos modernos, que comparativamente tienen tiempos de formación más lentos.

## PDF Article

\includepdf[pages=1-22, pagecommand={}, scale = 0.9]{Paper1.pdf}

## Bayes

El desarrollo dental relativo se evaluó empleando un enfoque estadístico bayesiano (31).

Result:

enter image description here

BTW, for something like a thesis I would use bookdown, since this gives you cross-referencing etc.

If that does not work for you, I suggest first looking at plain LaTeX, i.e. does the following LaTeX document work for you:

\documentclass{article}
\usepackage{pdfpages}
\begin{document}
foo

\includepdf[pages=1-22, pagecommand={}, scale = 0.9]{Paper1.pdf}

bar
\end{document}
like image 187
Ralf Stubner Avatar answered Dec 23 '25 22:12

Ralf Stubner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!