Hi,

I am trying to use bookdown to write a report with the final output being a pdf
I have read several sites where there are lots of work arounds using Latex (not my greatest skill to be honest)

I have three things i am trying to accomplish but i think once i get one of them the rest will fall into place. I want to add the abstract above the table of contents. Below is my YAML

---
title: " "
author: " "
date: " "
output: pdf_document
classoption: twoside
fontsize: 12pt
linestretch: 1.5
geometry: "left=4cm, right=3cm, top=2.5cm, bottom=2.5cm"
---


When i add the abstract to the YAML in the hope it will go above the contents i get the error

Error in yaml::yaml.load(..., eval.expr = TRUE) :
Scanner error: while scanning a simple key at line 3, column 1 could not find expected ':' at line 4, column 1
Calls: ... parse_yaml_front_matter -> yaml_load ->
Execution halted

This happens when i add other things such as keywords
I have seen the blog post which describes how to get the abstract and thanks in above the contents but i keep getting the same error.

I also looked at a blog post by Ed Berry but was unsure where to actually put the section below in respect to the rest of the markdown document

\documentclass{article}
\usepackage{pdfpages}

\begin{document}

\includepdf[pages=1]{../_book/_main.pdf}
\includepdf[pages=2-]{../rmarkdown/before_body.pdf}
\includepdf[pages=2-]{../_book/_main.pdf}

\end{document}


Any help would be greatly appreciated s i have been staring at it a bit too long now
Thanks

1 Like

I believe the problem might be in the YAML header and whether you're indenting properly or adding the options in a way that follow the documentation.

The following YAML header seems to work for me:

---
title: " "
author: " "
date: " "
classoption: twoside
fontsize: 12pt
output:
bookdown::pdf_document2:
toc: true
toc_depth: 2
abstract: |
The text of your abstract.  150 -- 250 words.
keywords:
- key
- dictionary
- word
linestretch: 1.5
geometry: "left=4cm, right=3cm, top=2.5cm, bottom=2.5cm"
---


Session Info
> sessioninfo::package_info()
package     * version date       lib source
assertthat    0.2.1   2019-03-21 [1] RSPM (R 3.5.2)
bookdown      0.9     2018-12-21 [1] RSPM (R 3.5.2)
cli           1.1.0   2019-03-19 [1] RSPM (R 3.5.2)
crayon        1.3.4   2017-09-16 [1] RSPM (R 3.5.0)
digest        0.6.23  2019-11-23 [1] CRAN (R 3.5.3)
evaluate      0.14    2019-05-28 [1] RSPM (R 3.5.2)
htmltools     0.4.0   2019-10-04 [1] CRAN (R 3.5.3)
knitr         1.23    2019-05-18 [1] RSPM (R 3.5.2)
Rcpp          1.0.3   2019-11-08 [1] RSPM (R 3.5.3)
rlang         0.4.2   2019-11-23 [1] CRAN (R 3.5.3)
rmarkdown     1.14    2019-07-12 [1] RSPM (R 3.5.2)
rstudioapi    0.10    2019-03-19 [1] RSPM (R 3.5.3)
sessioninfo   1.1.1   2018-11-05 [1] RSPM (R 3.5.2)
withr         2.1.2   2018-03-15 [1] RSPM (R 3.5.0)
xfun          0.8     2019-06-25 [1] RSPM (R 3.5.2)
yaml          2.2.0   2018-07-25 [1] RSPM (R 3.5.0)

[1] /home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.5
[2] /opt/R/3.5.3/lib/R/library

1 Like

Hi @jdb

Thank you very much for taking the time out to answer my question
It seems when i try to run the code above I get the error below

! LaTeX Error: Environment abstract undefined.

When i take out the abstract portion it seems to run fine with no issues

Do you have any ideas?

Thanks

I think this is related to this question too

You may need to check template used... Which format are you using exactly ? pdf_book ?
Is this possible to share a book example ?

If you want to add an abstract in a bookdown using pdf_book format, the best think is to add it as its own chapter, unumbered

# Abstract {-}

Text of the asbract


Then I guess you can disable the toc by default and create it using latex command in your document where you want it to be like this

# Abstract {-}

An abstract

\tableofcontents


It would be created after the abstract chapter.
You'll need

output:
bookdown::pdf_book:
toc: false


I let you try, it works in my example with bookdown demo repo

Thanks for the question by the way, it made me look into this to clarify this ! Thanks.
At the end, with pdf it is all latex and you can use any latex tricks to achieve your customisation.

Hope it helps.

2 Likes

Thanks very much @cderv. After re-installing tinytex and using the code bookdown::render_book("index.Rmd", pdf_book()), I get to where i almost want to be

I would need to put a page break after the title and before the contents to get it spot on but you have shown me where i need to tinker with it. Thanks again for your help and I hope you have a lovely weekend

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.