- Some special characters need to be escaped by a double backslash
\\
,
& % $ # _ { } ~ ^ \
e.g.
\\$
\\%
-
Overleaf has a lot of good documentation that helped me figure stuff out
-
\noindent on line before paragraph to remove auto indent
-
You can load figures as vector graphics (e.g. pdf) or as raster (e.g. png jpeg). I have all my figures as powerpoints and pdfs. Don't git track pptx files though (gitignore *.pptx)
-
Set slide size to be max 17 cm wide and 24 cm tall (or whatever the page size is). Actually I prefer to reduce height to at least 20 cm, so that the figure caption is on the same page as the figure.
-
To use special characters, and citations, use text references described in (2.2.4)[https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#text-references], and alluded to in (2.4)[https://bookdown.org/yihui/bookdown/figures.html]. See figure 1 of chapter 2 for an example.
-
Place text and text reference somewhere (e.g. just above figure code chunk), then under the fig.cap option in the relevant figure chunk, insert the text reference. All figures in my thesis are inserted like this.
-
Figures will be automatically numbered and linked when referenced correctly in the text.
-
Use
here::here()
to call file paths because it works with knitting and R studio projects easier. Read Jenny's post about why you need to stop usingset_wd()
.
Example code:
(ref:textreference) Figure title that appears in text. Figure caption that appears in text.
knitr::include_graphics('path\to\image')
Tables are best generated by using kable
to print the table. That means that tables can be loaded into R as data.frame
objects, for example by reading in a csv/xlsx/txt file, or through manual creation.
I don't recommend using xlsx, use csv instead
- See (2.5)[https://bookdown.org/yihui/bookdown/tables.html] for details. Tables are referenced in the same way as figures, through the code chunk label.
Example code:
\captionsetup{width=7in}
readxl::read_csv(here::('Tables', 'appendix-b', 'Table S1.csv')) %>%
kableExtra::kbl(
booktabs = TRUE,
caption = 'Title. Caption.')
Put this at the top of your script:
options(knitr.kable.NA = '')
-
For citations within tables, create text reference outside of each cell that contains of a reference. Then insert text references as a column in the table. See chapter 2 tables 1 and 2 as examples. See kableExtra github (issues)[haozhu233/kableExtra#214] for discussion.
- another option that I DON'T RECOMMEND, is to use
format = 'markdown'
, and then citations can be written as [@author-1999], but then all tables need to be in this format to keep style consistent across whole thesis. I have also found that this format is not as consistent and robust (e.g. text can overlap in columns with no easy fix). Footnotes also don't work with markdown format, so just avoid this option because it causes more problems.
- another option that I DON'T RECOMMEND, is to use
- Figure caption titles are by default not full-width. To make figure captions full-width, add to the YAML of main_script.Rmd:
header-includes:
- \usepackage{caption}
and then write "\captionsetup{width=6.5in}" on the line before the table code chunk. See table 2.1 as an example
-
In most cases I try to reduce the size of my tables such that they fit into the page. But you can also save a lot of space with the following table formatting options:
-
To automatically wrap columns, use
kableExtra::kable_styling(full_width = TRUE)
This is usually sufficient / reasonable, but alternatively you can try using this option, which makes everything smaller:
kableExtra::kable_styling(latex_options = "scale_down")
-
If your table is long, and needs to be split into multiple pages, set
longtable = TRUE
in thekable(...)
call. See 13_appendix_A.Rmd for examples -
kableExtra::landscape()
works well for wide tables -
kableExtra::column_spec()
look into this for line-wrapping / adjusting specific columns
I suggest using zotero. I
I liked using the built-in rstudio reference manager, which has auto-completion / search. It also adds references directly into the bib file.
Toggle on visual markdown editor before inserting citations, then you can take advantage of the auto-generation of the .bib file, and also auto-completion.
For my dissertation, my data chapters have been published. Therefore including these published articles require some repetitive formatting and editing. Here I made a checklist of all the steps to completely incorporate these into a broader dissertation context:
After each step, I recommend knitting and checking the output for errors, before moving on to the next step.
-[ ] Copy and paste manuscript text -[ ] Replace references -[ ] If references are not all in zotero library, you can download a bib file from the online journal article and import that into zotero first
-[ ] Insert figures -[ ] Copy (and format) figures into their individual figure folders (images/ch#) -[ ] Insert into main text: -[ ] Figure itself / code chunk -[ ] Figure caption (see #Figures above) -[ ] References to figures in main text
-[ ] Insert tables -[ ] Create CSV files of tables -[ ] Insert table code chunk -[ ] References to tables in main text -[ ] Ensure table is not cut off, if it is, see my tips on how to make it fit
-[ ] Insert tables and figures into the appropriate appendix -[ ] Reference appendix tables and figures in main text
Some non- rmarkdown, but required things to also do:
-[ ] Write in preface the contribution and copyright details -[ ] Insert abbreviations into glossary -[ ] Adjust abbreviations (remove repeats, make consistent)
The following code makes it so the number and the caption are further apart, such that they don't overlap when the number reaches the double digits:
\makeatletter
\renewcommand*\l@table{\@dottedtocline{1}{1em}{3.2em}}
\makeatother
Insert after \addcontentsline
- To get the most out of git diff / tracking, write one sentence per line- markdown doesn't "see" line breaks, but having one sentence per line will allow each sentence to be git tracked (as opposed to each paragraph).