Which RMarkdown theme/style is used to get the TOC shown below? - r-markdown

The default floating table-of-contents looks like below using theme 'united' I think.
How does one create the TOC theme/style shown below?
Here is the page.
Here is another example:
Link here.
This question is not about how to create the floating TOC or about the general page style/theme, but where does the specific TOC style come from? Is it an argument somewhere? Perhaps some variation to tocify?

html_document output supports TOC, you just need to turn it on.
Try this:
---
title: "example yaml"
author: "you"
date: "8/20/2018"
output:
html_document:
toc: true
toc_float: true
---
More settings of TOC, please refer to Rmarkdown: the definitive guide
Edit:
I checked the gh-page for your link, however I didn't know how the author generated those pages. If you want the same appearance of TOC in that page, maybe ask the author?

Related

Multiple authors in Rmarkdown ioslides_presentation without Hyphen sign

I want to add two authors in my Rmarkdown presentation using ioslides_presentation as the output. This is what I tried:
---
title: "Sample title"
author:
- "Author1"
- "Author2"
output: ioslides_presentation
---
However it gives me an extra Hyphen sign for both authors:
If I change the output to slidy_presentation or revealjs::revealjs_presentation it'll work fine. It's only the problem with ioslides_presentation.
Any help is appreciated.

Text vanishes in Gitbook using Bookdown

Iw as working on a gitbook using bookdown in R several months ago. Today, I resumed my work again, but when I rendered the book the font of the output changed dramatically. It vanishes! I don't remember having changed anything on the TAML of the book. This is how it looks now. Right after the word WELCOME, the text becomes lighter and lighter until it literally disappears. It has a sort of vanishing effect that I have no idea how I got.
Thank you for your help.
Best,
this is my _output.yml
bookdown::gitbook:
config:
toc:
collapse: section
scroll_highlight: yes
before: |
<li>PovcalNet Internal Guidelines</li>
after: |
<li>Published with bookdown</li>
download: ["pdf", "epub"]
toolbar:
position: fixed
edit : null
search: yes
fontsettings:
theme: white
family: sans
size: 2
sharing:
facebook: no
github: no
twitter: no
linkedin: no
weibo: no
instapaper: no
vk: no
info: yes
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
bookdown::epub_book:
stylesheet: style.css
And this is my _bookdown.yml
book_filename: "Povcalnet_internal_guidelines"
repo: https://github.com/xxxxxx/Povcalnet_internal_guidelines/
output_dir: "docs"
delete_merged_file: true
language:
label:
fig: "Figure "
tab: "Table "
ui:
edit: "Edit"
chapter_name: "Chapter "
rmd_files: [
"index.Rmd",
"intro.Rmd",
"Folder_structure.Rmd",
"Collaboration_in_Git.Rmd",
"DM_Group_data.Rmd",
"Handover.Rmd",
"references.Rmd",
]
before_chapter_script: "_common.R"
And, I am rendering the book using the following instruction,
bookdown::render_book("index.Rmd", "bookdown::gitbook")
I found the problem. Basically, in one of my .Rmd files I create a diagram using the DiagrammeR package. When one of my colleagues removed the diagram, the issue was gone, but we had no diagram. However, I created a separate .mmd (mermaid) file and updated both packages glue and DiagrammeR. All of this solved the problem.
thanks.

Issues with different citation packages in bookdown

I am creating a pdf-book using bookdown, with a .bib file that holds my citations. I call the citations with the standard [#citation] used in bookdown. Citing works correctly, but the bibliography doesn't seem to be how I wanted it.
Here are the things that I need to work:
The bibliography should be included in the toc, at the end of \mainmatter, but before the \backmatter, which I use to attach pdf's as an appendix, where the appendix header is listed in the toc
The in-text citations should be in number format, with possible nested citations, like this: [1,2]
Bibliography should be in the order they appear in the text, with the possibility of removing DOI/URLs etc as I see fit
For these things to work so far, I've tried the natbib package, which seem to work fine. However, I do not seem to be able to remove DOI/URLs from specific bibliography entries, such as journal articles. Therefore, I tried using biblatex or the built-in pandoc, but neither seem to work properly (With pandoc the bibliography is gone from the toc, and the bibliography entries are messy. With biblatex, i get multiple errors that the program can't find specific entries in the .bib file, which are there)
This is my YAML with natbib:
site: bookdown::bookdown_site
geometry: "left=4cm,right=3cm,top=3cm,bottom=3cm"
subparagraph: true
output:
bookdown::pdf_book:
latex_engine: xelatex
fig_caption: yes
toc: false
citation_package: natbib
includes:
before_body: frontpage.tex
after_body: after_body.tex
in_header: preamble.tex
fontsize: 11pt
linestretch: 1.2
documentclass: book
bibliography: [packages.bib, libraryzotero.bib]
link-citations: yes
---
And this is in my preamble.tex:
\usepackage{titlesec}
\usepackage{pdfpages}
\titleformat{\chapter}
{\normalfont\LARGE\bfseries}{\thechapter}{1em}{} % set title format
\titlespacing*{\chapter}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\AtBeginDocument{\let\maketitle\relax}
\usepackage{makeidx}
\makeindex
\setcitestyle{numbers,square,comma}
\usepackage{url}
\usepackage[nottoc]{tocbibind}
\usepackage{caption}
\captionsetup[figure]{textfont={small,it}, labelfont={normalsize,bf,it}} % set figure caption font size and style
\usepackage{graphicx}
\usepackage{float}
\let\origfigure\figure
\let\endorigfigure\endfigure
\renewenvironment{figure}[1][2] {
\expandafter\origfigure\expandafter[H]
} {
\endorigfigure
}
\raggedbottom
\usepackage{fancyhdr,blindtext}
\fancyhf{}
\fancyhead[LO]{\slshape \rightmark} %section
\fancyhead[RO]{\thepage}
\fancyhead[RE]{\slshape \leftmark} % chapter
\fancyhead[LE]{\thepage}
\setlength{\headheight}{27.7pt} % as requested by fancyhdr's warning
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\makeatletter
\renewcommand{\chaptermark}[1]{% % change settings for including headers
\if#mainmatter
\markboth{Chapter \thechapter{}: #1}{}%
\else
\markboth{#1}{}%
\fi
}
\makeatother
\usepackage{epigraph}
\setcounter{secnumdepth}{1}
\setcounter{tocdepth}{1}
Where \setcitestyle{numbers, square, comma} is for the in-text references.
Does anyone have any suggestions how to get these things to work with bookdown?
For the natbib based solution you could patch the used bibliography style:
You are not setting any bibliography style. Therefore plainnat.bst is used.
Copy plainnat.bst from your TeX installation (typically TEXMF/bibtex/bst/natbib/) to your working directory with a new name.
Add biblio-style: <new-name> to your YAML header.
Edit your BST file:
Find FUNCTION {article}.
Within that block remove format.doi output and format.url output.
Repeat for other types.

Full local customisation for html template and css theme/hightlighting

I am currently exploring the R Markdown configurations and the possibilities for the HTML output. My goal is to have a local html template as well as a local css theme file which behaves exactly the same as if I would select theme/highlight options in in the yaml configurations.
I used the following configuration:
output:
html_document:
theme: united
highlight: tango
toc: true
toc_depth: 3
toc_float: # set to false if you do no want a floating toc
collapsed: true
smooth_scroll: true
I now want to be able to customize the HTML structure and the CSS by my own. I started with the HTML template as follows:
Downloaded the standard pandoc HTML5 template and copied it into a local template.html file. I changed my configuration to
output:
html_document:
template: template.html
theme: united
highlight: tango
toc: true
toc_depth: 3
toc_float: # set to false if you do no want a floating toc
collapsed: true
smooth_scroll: true
There are several problems arizing:
the TOC is not shown anymore
the rendered HTML design of the output changed, i.e. I have no margin at all - all javascript functionality is gone, so no DT support, no tabs, no scrolling etc.
My question is: How can I achive the exactly same design and functionality I had before with my configuration but having the template/theme/highlight files stored locally? (So a template.html and a styles.css and all the needed JS files)
Let me know if I need to give further details. Thanks!
The Pandoc default you linked to is not the default used in rmarkdown. That one is stored in system.file("rmd/h/default.html", pkg = "rmarkdown"), and a current version is online here: https://github.com/rstudio/rmarkdown/blob/master/inst/rmd/h/default.html.
You should also study the source to rmarkdown::html_document if you decide to modify the default template. You'll also have to make some other changes if template != "default".

Creating a footer for every page using R markdown

I'm writing a document in R Markdown and I'd like it to include a footer on every page when I knit a PDF document. Does anyone have any idea on how to do this?
Yes, this question has been asked and answered here: Adding headers and footers using Pandoc. You just need to sneak a little LaTeX into the YAML header of your markdown document.
This markdown header does the trick:
---
title: "Test"
author: "Author Name"
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyhead[CO,CE]{This is fancy header}
- \fancyfoot[CO,CE]{And this is a fancy footer}
- \fancyfoot[LE,RO]{\thepage}
output: pdf_document
---
Works for me with an Rmd file in RStudio Version 0.98.1030 for Windows.
Another option would be to use the argument includes provided by rmarkdown::pdf_document() (documentation). This allows you to keep the footer in a separate file. If your footer is defined in footer.tex, the header of your R Markdown file would look like this:
---
output:
pdf_document:
includes:
after_body: footer.tex
---
This also assumes that footer.tex is in the same directory as the R Markdown file.
Update: The file footer.tex can contain any valid LaTeX that you want to be inserted at the end of your PDF document. For example, footer.tex could contain the following:
This \textbf{text} will appear at the end of the document.
To manage the height of the footer, you can use the following:
date: '`r paste("Date:",Sys.Date())`'
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \setlength{\footskip}{-50pt} # set the footer size
Keep Coding!