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".
Related
I am trying to update my portfolio website with new Quarto-generated HTML files rather than my older RMarkdown-generated HTML files. I have rendered these updated files and they look great!
However, when I have uploaded this HTML to my GitHub Pages website, using htmlpreview, I get a very different picture...
Keep in mind that htmlpreview works perfectly well for my RMarkdown-renderd documents:
Here is my YAML for the Quarto document if it is of help:
author: "Brian Lookabaugh"
toc: true
number-sections: true
format:
html:
code-background: true
I think using self-contained: true would solve your case, since you would need a standalone HTML file.
author: "Brian Lookabaugh"
toc: true
number-sections: true
format:
html:
self-contained: true
code-background: true
For reference, see this page from Quarto Docs.
I am using R Markdown to create a long html document with multiple images inserted throughout. I need automatically numbered figure captions, but cannot figure out how to generate them.
I insert figures this way:
![An informative figure caption](path.png)
The YAML metadata looks like this:
title: "My Title"
author: "me"
bibliography: References.bibtex
output:
bookdown::html_document2:
number_sections: TRUE
fig_caption: TRUE
I am using the bookdown package to produce a large document with tables using the knitr::kable function. I can get the document to produce tables in HTML perfectly, but in PDF, the table contents just appear as a list of numbers. This is also true for the output to Word. The compiled LaTeX just appears to be a list of numbers as well.
This is also true of output from other packages like sjplot.
The same problem also appears when the sample code from the bookdown book.
knitr::kable(
list(
head(iris[, 1:2], 3),
head(mtcars[, 1:3], 5)
),
caption = 'A Tale of Two Tables.', booktabs = TRUE
)
Produces the expected output in HTML:
But, produces the following in PDF:
The YAML header in index.rmd are:
#output ~~~~~~~~~~~ [see _output.yml]
site: bookdown::bookdown_site
output: [bookdown::gitbook, bookdown::pdf_book, bookdown::word_document2, bookdown::html_document2]
documentclass: book
The output settings in the _output.yml are:
bookdown::pdf_book:
keep_tex: true
latex_engine: xelatex
includes:
in_header: tex/biblio.tex
number_sections: yes
pandoc_args: ["--top-level-division=chapter"]
It turns out the problem arises from some interaction with the kableExtra package
So, even if you specify (as I did in my sample code) the knitr namespace (knitr::kable), there is still some downstream interference if kableExtra is loaded. So, this will not work when rendering to PDF:
library(kableExtra, warn.conflicts = TRUE)
knitr::kable(head(iris, 20), caption = 'Here is a nice table!', booktabs = TRUE)
While everything works for the HTML output, the rendering to PDF does not work for the tables and you just end up with a list of the table cell values (for both PDF and Word) - as shown in the image above.
To solve, remove any library statements
Then, ensure you unload the package:
detach("package:kableExtra", unload = TRUE)
And, finally, for me, I found that I needed to "Restart R and Clear All Outputs" or "Terminate R" from the R-Studio "Session" menu.
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.
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?