How to reference sections in rmarkdown with pdf output - r

How do I use \label and \ref to link sections in rmarkdown when outputting to pdf please. I have tried various permutations from https://bookdown.org/yihui/bookdown/cross-references.html and https://bookdown.org/yihui/rmarkdown-cookbook/cross-ref.html with no success.
One attempt
---
title: "Untitled"
output: pdf_document
---
See Section \#ref(sec:label).
# Section One (\#sec:label)
which gives

You can modify your document as follows:
---
title: "Untitled 1"
date: "28 de junio de 2020"
link-citations: yes
output:
pdf_document:
includes:
keep_tex: yes
number_sections: yes
toc_depth: 2
---
\section{This is the first section} \label{section1}
You will be some in \ref{section1}
Then you can see how numbers appear, just add \label{} to your sections and use \ref{} to call. Also, I suggest using \section{}, and modify YAML as I included. Hoping this can help.

Related

Bookdown: Produce only PDF, no HTML

I have a large bookdown project. My YAML header below.
My only desired output is a PDF. However, bookdown by default produces a HTML as well. This makes compilation take more time, and also uses more caching space on my disk. Any chance I can disable producing HTML output? I have tried to play around with the site parameter in the YAML heading, but no luck.
title: "Title"
subtitle: "Subtitle"
author:
- "Name"
- "Institution"
date: "September 2020"
output:
bookdown::pdf_book:
toc: false
includes:
in_header: preamble.tex
keep_tex: yes
latex_engine: xelatex
citation_package: natbib
fontsize: 12pt
linestretch: 1.5
site: bookdown::bookdown_site
documentclass: book
bibliography: [references.bib]
biblio-style: "apalike"
geometry: "left=2.5cm, right=2.5cm, top=2.5cm, bottom=2.5cm"
bookdown doesn't really have a "default" output format. If it produces HTML, the output format must have been provided somewhere. Check if you have a _output.yml under the root directory of your book project. If you do, you may delete it. Then bookdown will use the output field that you specified in the YAML frontmatter of your Rmd document.

Rmarkdown and Latex format citations with round paranthesis

I feel like this is a straight forward thing, but everything I find doesn't quite get me what I want. I'm using rmarkdown and knitting to a latex .pdf. I'd like to have my in-text citations have round () parenthesis instead of the block ones. The yaml below uses a references.bib file to correctly import the references. Is there anything I can do to easily change my parenthesis to round?
---
title: "Title"
author: "Author"
date: "16/03/2020"
output:
pdf_document:
fig_caption: yes
citation_package: natbib
bibliography: references.bib
editor_options:
chunk_output_type: console
---
I've used an approach here, but it returns an error:
Error in yaml::yaml.load(..., eval.expr = TRUE) :
Parser error: while parsing a block mapping at line 6, column 5 did not
find expected key at line 7, column 30`
---
title: "Title"
author: "Author"
date: "16/03/2020"
output:
pdf_document:
fig_caption: yes
bibliography: references.bib
editor_options:
chunk_output_type: console
\usepackage[round]{natbib}
---
Any ideas? Thanks for your suggestions / ideas...
The problem with your attempt to include \usepackage[round]{natbib} in the rmarkdown header is that rmarkdown seems not clever enough to parse commands with optional arguments. One can trick it by hiding the command in a .tex file
---
title: "Title"
author: "Author"
date: "16/03/2020"
output:
pdf_document:
fig_caption: yes
includes:
in_header: preamble.tex
bibliography: references.bib
---
test [#knuth]
with preamble.tex
\usepackage[round]{natbib}
https://rstudio.cloud/project/1061588
Using the header-includes: option should fix the issue.
---
title: "Title"
author: "Author"
date: "16/03/2020"
output:
pdf_document:
fig_caption: yes
citation_package: natbib
bibliography: references.bib
editor_options:
chunk_output_type: console
header-includes:
- \usepackage[round]{natbib}
---

changing rmarkdown "table of contents" default title

I am using RMarkdown to write my MSc thesis, in a language different than English. The thesis shall be rendered in .docx format. Reading around SO, I found that it is possible to provide some pandoc arguments among which toc-title could address my issue. Nevertheless I was not able to do it. My current YAML header is:
output:
word_document:
reference_docx: stile_tesi.docx
toc: yes
fig_caption: true
#pandoc_args: [
# "--toc-title", "INDICE"
#]
Thanks in advance
---
title: "Untitled"
output:
word_document:
toc: yes
toc-title: "INDICE"
---
Important: Watch out the correct indention!

R: Removing the "Chapter" part from the title in bookdown::pdf_book with documentclass: report

consider my header and first section
---
title: "asdf"
author: "asdf"
date: "13 Januar 2018"
documentclass: report
output:
bookdown::pdf_book:
citation_package: biblatex
latex_engine: pdflatex
number_sections: yes
fig_caption: yes
---
# Introduction
Here begins my introduction
I want to remove the automatic "Chapter 1" part, thats sits in front of the actual chapter title (in this case Introduction)
This does not work
header-includes:
\renewcommand{\chaptername}{}
Also using another documentclass does not work, because I need the number of my sections/chapters be represented in the figure captions (e.g Figure 3.1)
What I would like is to end up with a Title 1 Introduction , than 2 Methods and so on.
Should not be to hard, but I can't figure it out.
Thanks
Greg
You can use
subparagraph: true
output:
bookdown::pdf_book:
includes:
in_header: preamble.tex
together with
\usepackage{titlesec}
\titleformat{\chapter}
{\normalfont\LARGE\bfseries}{\thechapter}{1em}{}
\titlespacing*{\chapter}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
in preamble.tex (c.f. https://tex.stackexchange.com/questions/10326/how-to-set-the-chapter-style-in-report-class). You have to make sure that the LaTeX package titlesec is installed in your TeX system.
At the time of writing subparagraph: true was needed since the used pandoc LaTeX template redefined \paragraph and \subparagraph in a way interfering with titlesec. This has changed since then. at least with rmarkdown version 2.1 one no longer needs subparagraph: true. thanks #MarkNeal for noticing this!

How to change table of content header in knitr?

I am using the following options to produce a pdf document with knitr:
---
title: "Test"
author: "Paulo Miramor"
date: "13-07-2015"
output: pdf_document
toc: yes
---
I would like to change the header of the table of contents (which is "Contents"), since I am producing a document in Portuguese. Is there any way to customize it?
Thanks to #Molx and #Chris in the comments I could find a solution.
Solution 1
Add \renewcommand{\contentsname}{Índice} to the document so that the .Rmd header is:
---
title: "Test"
author: "Paulo Miramor"
date: "13-07-2015"
output: pdf_document
header-includes:
- \renewcommand{\contentsname}{Whatever}
toc: yes
---
With this solution the header is Whatever you put inside \contentsname argument.
Solution 2
Add lang: portuguese to the document so that the .Rmd header is:
---
title: "Test"
author: "Paulo Miramor"
date: "13-07-2015"
output: pdf_document
lang: portuguese
toc: yes
---
Using this solution the header was a translation of "Contents" to Portuguese. This should work if your TeX installation supports the language.

Resources