zueridown makes it easy to generate customized R Markdown PDF documents that follow the corporate design of the city of Zurich. It is based on the CRAN package indiedown, which lays down the framework for customization.
To create a PDF document using zueridown you need some LaTeX packages. To install those packages you can install tinytex using the following lines of code in R:
install.packages('tinytex')
tinytex::install_tinytex()
# to uninstall TinyTeX, run tinytex::uninstall_tinytex() tinytex automatically will install all packages needed for zueridown. However, if you get an error due to some missing package, you can use the following helper functions:
library(tinytex)
tlmgr_install('psnfss') # install the psnfss package
tlmgr_update() But if you still have some trouble, it is better to use:
tinytex::reinstall_tinytex()You can find more information on tinytex here: https://yihui.org/tinytex/
To install from a local source file, store zueridown_main.tar.gz at an arbitrary location on your computer.
In R Studio, in the Packages pane, click Install and select the option Install from Package Archive File. Browse to the location of the file and install it. Alternatively, you can download the package from https://github.com/StatistikStadtZuerich/zueridown, by clicking Clone or download, extract it to any location, e.g., to your Desktop.
Then, run:
remotes::install_local("<path_to_location>/zueridown-main", dependencies = FALSE)The package can also be directly installed from here with the appropriate git credentials. If you are already cloning repositories from GitLab, you can simply run:
remotes::install_git("https://cmp-sdlc.stzh.ch/OE-7035/ssz-da/libraries/zueriverse/zueridown.git")Otherwise you need to create a personal access token in your settings, and use this as a password, together with your GitLab username.
zueridown uses Helvetica Neue LT Pro, the font of the corporate design, if it is installed on your computer:
65 Medium as regular and 85 Heavy as bold.
The font is licensed and does not ship with the package.
It is enough to install it for the current user, for example in Settings > Personalization > Fonts on Windows.
If you cannot install fonts, copy the font files, named like HelveticaNeueLTPro-Md.otf or .ttf, to a folder and set options(zueridown.font_path = "<folder>"), for example in .Rprofile.
The path of that folder, and on Windows of the folder of the fonts installed for the current user, must not contain , = % # { } [ ] " or :, except for the : of a Windows drive letter. A folder such as OneDrive - Acme, Inc (with ,) stops the render with an error when the font is loaded from it. The same applies to the folder where R installs zueridown, which holds TeX Gyre Heros; its path must also never contain # or : , which stops every render.
Without the font, zueridown uses TeX Gyre Heros, a free Helvetica clone that ships with the package, and a message says how to install fonts.
The message is shown at the start and at the end of the render, and again in the same R session only if its advice changes.
A document can set another font in its mainfont field, and a user in the option zueridown.mainfont, see ?zueridown.
A font file named in mainfont or the option zueridown.mainfont is not looked up in the zueridown.font_path folder:
it must be in the folder of the document or in the TeX installation, or have its folder in Path= in mainfontoptions.
After installation, a new R Markdown template is available in R Studio. To open, use File, New File, R Markdown.
Click From Template and select one of the templates:
zueridown document with glossary and without Bibliography.zueridown document with bibliography and glossary.zueridown document with bibliography and without glossaryzueridown document without glossary and bibliographyzueridown two-column document with graphics
After saving the file on your computer, you can use the Knit button to produce a basic PDF document based on this template.
To check your version of zueridwon, run:
packageVersion("zueridown")More zueri-specific packages are available on github: zueritheme provides a ggplot-theme that is styled according to the city's CI/CD, zuericolors provides the CI/CD colors, and zuericssstyle has css for styling other types of documents such as html.
zueritheme and zuericolors are automatically installed with zueridown.
You can use parameters in R Markdown reports using the zueridown template. However, two relevant conditions take place.
First, it is not possible to include in the YAML r calls like r params$country. Therefore, if your document has a title or a subtitle using a parameter, you should use the title and/or subtitle parameters in the function cd_page_title_box or cd_page_title_box accordingly, for instance:
cd_page_title_box(
title = paste0("Stadt Zürich: Auswertung", params$country, "verkehrszählstelle", params$Name),
title_size = "40pt",
color_palette = cd_color_palette("palette1"),
)
Second, you should use the zueridown output format to render the parameterized report. Consequently, after creating a zueridown template (for instance: "report.Rmd") use the option output_format as in the following example:
rmarkdown::render(
input = "report.Rmd",
output_format = zueridown::zueridown(),
output_file = "Country_1_report.pdf",
params = list(country = "Switzerland", Name = "name_1"))
The option full_width = T in kableExtra uses the tabu LaTeX package, but this package has some problems with colors and other functionalities. To solve this zueridown has the function full_width_tabular . The function changes the LaTeX package tabu for tabularx. To use it properly follow next steps:
- specify the chunk options:
```{r, out.width = "\\textwidth", results='asis', warning=FALSE}. - Set in the code of the table
full_width = T - Add the function
full_width_tabularat the end of the code table.
Example
```{r tab1, out.width = "\\textwidth", results='asis', warning=FALSE}
kableExtra::kable(head(iris),
col.names = gsub("[.]", " ", names(iris)),
table.env='table',
caption = "\\textbf{Titel der Tabelle} \\newline Untertitel der Tabelle",
booktabs = T) %>%
kable_styling(font_size = 9, full_width = T, latex_options = "HOLD_position") %>%
row_spec(0,bold=TRUE) %>%
row_spec(2,background="red") %>%
full_width_tabular()
```
If the document does not have proper hyphenation in any line, or there are some texts which extend beyond the margin of the page, i.e. if the document looks like:
Use the commands from the tinytex package to install or update the babel-german and hypehn-german LaTeX packages:
tinytex::tlmgr_install ("babel-german")tinytex::tlmgr_install ("hyphen-german").
Afterwards your text should contain proper hyphenation, for instance:
If you encounter a bug, please open an issue or contact statistik@zuerich.ch{.email}.





