-
Notifications
You must be signed in to change notification settings - Fork 17
Home
- How do I make my table and figure captions in french automatically?
You must create two separate caption references and use an if statement to select which one is to be used. It is best to set this up for every figure and table when first writing the document, so that when you get your french translations back it is just a cut/paste exercise.
(ref:my-caption) A figure caption in English.
(ref:my-caption-french) A figure caption in French.
```{r figure-chunk-name, fig.cap = ifelse(french, "(ref:my-caption-french)", "(ref:my-caption)")
```
Note that the french
variable is declared in the first knitr code chunk in index.Rmd and is extracted from the YAML header at the top of index.Rmd. You only have to change the value in the YAML header to french: true
to change all the figure and table captions.
- How do I include a citation or figure reference or r object value in a figure or table caption?
```{r chunk1}
x <- 7
```
(ref:my-caption) A figure caption. See Appendix \@ref(app:my-appendix)). x has
the value `r x`. See @viridis2018.
```{r my-figure, fig.cap="(ref:my-caption)"}
plot(1)
```
- How do I include extra packages for latex-rendered documents?
In the index.Rmd
file, add the following to the YAML part (the section between the ---
and ---
) for whatever package you want to include. For this example it is the threeparttablex
package:
header-includes:
- \usepackage{threeparttablex}
Note that if you need to include more than one package you will have to have them on the same line like this:
header-includes:
- \usepackage{threeparttablex} \usepackage{caption}
This will NOT work, only the first one is added:
header-includes:
- \usepackage{threeparttablex}
- \usepackage{caption}
- I have added appendices after the bibliography, but they are appearing in the document before the bibliography. How do I make the bibliography appear before the appendices?
Add the following line where you want the bibliography to be placed:
<div id="refs"></div>
- When I click on links in the PDF (e.g. figures or citations) they don't take me to the appropriate figure or reference. How do I fix that? Try running
tinytex::tlmgr_install("hyperref")
.
- To see the variables declared in
_bookdown.yml
, you can do the following from any R chunk within the project:
config <- bookdown:::load_config()
- To access the YAML metadata located at the beginning of
index.Rmd
, you can look at the following list from any R chunk within the project:
rmarkdown::metadata
For example if creating a CSAS SR document, the following YAML metadata will be in index.Rmd:
output:
csasdown::sr_pdf:
french: true
In the setup R chunk, the following line of code would set up the language for R:
french <- rmarkdown::metadata$output$`csasdown::sr_pdf`$french
- If writing the document in French, you can change the decimal point to a comma for all numeric values in the project using the following in the setup chunk:
if(french){
options(OutDec = ",")
}
- Knitr chunk names can only have numbers, letters, and dashes. Underscores are not permitted and will cause major problems in rendering with
bookdown
. Here is an example of a bad chunk:
```{r bad_chunkname, results = "asis"}
d <- data.frame(x = c(1,2,3,4),
y = c(5,6,7,8),
z = c(9,10,11,12))
csasdown::csas_table(d,
format = "latex",
font_size = 8,
caption = "XX - This table is broken")
```
The error for this was:
! Misplaced \noalign.
\toprule ->\noalign
{\ifnum 0=`}\fi \@aboverulesep =\abovetopsep \global \@b...
l.125 ...able is broken\}\textbackslash{} \toprule
x \& y \& z\textbackslash...
Error: Failed to compile resdoc.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See resdoc.log for more info.
Execution halted
And the resulting TeX
file had broken code for the table with many \textbackslash{}
commands peppered through it:
\textbackslash{}begin\{longtable\}\{rrr\} \textbackslash{}caption\{(\#tab:broken\_table)XX - This table is broken\}\textbackslash{} \toprule x \& y \& z\textbackslash{} \midrule 1 \& 5 \& 9\textbackslash{} 2 \& 6 \& 10\textbackslash{} 3 \& 7 \& 11\textbackslash{} 4 \& 8 \& 12\textbackslash{} \bottomrule \textbackslash{}end\{longtable\}
-
Do not include spaces or
~
in any folders in the path to your document. LaTeX doesn't play nicely with them. -
In order for proper formatting of headers according to CSAS layout requirements, the headers must be typed in the appropriate case in .Rmd files. For example:
Heading 1-beginning of a section or chapter; all caps. Prints as e.g. 1. INTRODUCTION
# THIS IS A MAIN HEADER
Heading 2-subsection; all caps. Prints as e.g. 1.1 FIRST SUBSECTION
## THIS IS A SUBSECTION
Heading 3; sentence case. Prints as e.g. 1.2.1 This is the next layer
### This is the next layer
Heading 4-sentence case. Prints as e.g. 1.2.4.1 Yet another
#### Yet another