After cloning the bookdown-demo. I want to use the toggle function of sections.
For this, I modified the file _output.yml adding the collapse line:
bookdown::gitbook:
config:
toc:
collapse: section
As shown in: bookdown manual
And added some sections in index.Rmd
# Prerequisites
## second
### third
After building the book in Rstudio, with:
bookdown::render_book("index.Rmd", "bookdown::gitbook")
It works with a little defect. When I click some chapter without sections, (and also sometimes the chapter with sections), there is a rapid movement of the menu as if it opens and immediately closes the sections of the (other) chapter with sections.
Does someone have a solution?
Possibly related issue: https://github.com/rstudio/bookdown/issues/556
Related
I'm using the bs4_book format to set up the framework for a new book project using bookdown. Is there a way to change "On this page" at the top of the right sidebar to "In this chapter"? So far, I haven't been able to find where that text snippet lives.
Here is a solution:
I placed a short JavaScript function in the file local_js.html in the folder with the Rmd chapter files. The contents are:
<script>
$(function() {
$("#toc h2").html("In this chapter");
});
</script>
(Using JQuery 3.5.1)
#toc is the id for the right sidebar contents list, and the heading text is inside the h2 tags.
Then I added the following to the YAML header for the b4_book output:
output:
bookdown::bs4_book:
theme:
primary: "#637238"
includes:
in_header: local_js.html
This seems to work well enough, at least for a book framework that still hasn't got much text or image content in the chapters. I still haven't figured out where the default heading "On this page" is coming from. If anyone knows and can explain how to change it directly, I'd be grateful.
We - bookdown noobs - are making a bookdown with a lot of text per paragraph (using the minimal bookdown as a template, we only added new Rmd files from here). At the moment, one has to scroll a long time before reaching the end of a chapter, because we have many paragraphs per chapter and all paragraphs are pasted on 1 page. In the bookdown example however, each paragraph appears on a separate page. I have looked in the code of the example and tried to copy some index code to ours, but that still pastes everything to one page when knitting to html.
How can we make sure each paragraph (e.g, 3.1, 3.2) appears on a separate page, instead of all paragraphs appearing on the same page (chapter 3 in its entirety)?
This is our index.Rmd code (don't know whether of any use):
site: bookdown::bookdown_site
documentclass: book
output:
bookdown::gitbook: default
R version 3.6.2 (2019-12-12); Bookdown version 0.18
Thanks very much in advance. I am a Latex/Pandoc noob so this may be a very stupid question.
Loved bookdown. However, I'm porting my book from LaTeX into bookdown, and would like some help with headers/footers.
I have a custom code that generates headers and footers in my LaTeX:
% HEADER AND FOOTER MANIPULATION
% for normal pages
\nouppercaseheads
\headsep = 0.16in
\makepagestyle{mystyle}
\setlength{\headwidth}{\dimexpr\textwidth+\marginparsep+\marginparwidth\relax}
\makerunningwidth{mystyle}{\headwidth}
\makeevenhead{mystyle}{}{\textls[100]{\textsf{\small\scshape\thetitle}}}{}
\makeoddhead{mystyle}{}{\textls[100]{\textsf{\small\scshape\leftmark}}}{}
\makeevenfoot{mystyle}{}{\textls[100]{\textsf{\small\thepage}}}{}
\makeoddfoot{mystyle}{}{\textls[100]{\textsf{\small\thepage}}}{}
\clearmark{section} % removing section in the headers
\makeatletter
\makepsmarks{mystyle}{%
\createmark{chapter}{left}{nonumber}{\#chapapp\ }{.\ }}
\makeatother
% for pages where chapters begin
\makepagestyle{plain}
\makerunningwidth{plain}{\headwidth}
\makeevenfoot{plain}{}{}{}
\makeoddfoot{plain}{}{}{}
\pagestyle{mystyle}
% END HEADER AND FOOTER MANIPULATION
I placed my entire LaTeX preamble in preamble.tex (and I've not added content to the book just yet). It renders the following:
The render should actually look like this:
Also, here's what's in the YAML in index.Rmd.
documentclass: memoir
papersize: smalldemyvo
indent: yes
microtypeoptions:
- protrusion
- tracking
fontfamily: Alegreya
fontfamilyoptions:
- osf
fontsize: 11pt
output:
bookdown::pdf_book:
template: null
I'm new to bookdown, but I did read the documentation. I feel I need help with two things.
How do I remove the auto-generated headers and footers?
How do I make "Contents" disappear from the ToC table?
Thank you!
By default, bookdown uses some built-in template(s). If you need more adjustments, you could make your own .tex files (preamble.tex, before_body.tex, after_body.tex, template.tex) and specify them in the yaml part of index.Rmd like this:
bookdown::pdf_book:
includes:
in_header: preamble.tex
before_body: before_body.tex
after_body: after_body.tex
template: template.tex
bookdown merges preamble.tex, before_body.tex, and after_body.tex with the main body (marked as $body$ in template.tex) of your book into one .tex file in the structure under the control of template.tex, and compile it into a pdf book with pandoc and LaTex.
In your case, you have to insert your custom code into template.tex in the right way. #yihui's demo shows a good example.
For more examples to customize these .tex files, I would suggest that you could either look into the 'bookdownplus' package I developed, which gives you 19 examples showing how to tailor a LaTeX template into bookdown's frame, or read Chapter 8.3 Create Your Own Templates in the bookdownplus textbook.
Edited answer
bookdown has built-in templates (decided mostly by documentclass and/or Pandoc). Refer the Theming and Templates sections of bookdown documentation.
An example to learn from, as #pzhao suggested, is the template in the bookdown-chinese repo. Observe the variables that bring in data from the Rmd files. They're enclosed between $$, such as $body$. _output.yml has a reference to this template. This way, you override the default template, thereby eliminating duplicate headers/footers. Your LaTeX template decides what forms part of your headers/footers. An example is the LaTeX code in my question.
The appearance of Contents in the ToC table can also be controlled by tweaking your custom LaTeX template. I use the memoir class, and help to remove self-reference can be found here. My custom LaTeX template already took care of it, so it fixed itself as soon as I figured out how to use my custom template.
I was checking out how to include a nice table of contents / document outline in my rmarkdown document (with html output).
Well, the "standard" approach:
html_document:
toc: true
It works, but I do not like it (not even tweaking options and themes).
But actually, in several pages of the documentation (e.g. http://rmarkdown.rstudio.com/html_document_format.html), they use a very nice layout that includes a table of contents / document outline to the left of the page and the contents of the right (and the outline syncs with the contents part, Highlighting where on the contents you currenly are).
This is EXACTLY what I want. And I guess they did it using rmarkdown. But I cannot find how to do it.
I've check that documentation page, as well as rmarkdown gallery, flex dashboard, web sites among others. But I can't seem to figure it out how to do it.
Well, using web sites I would be able to do it, but it seems overly complicated for what I want (you need to have several pages, and at least index.Rmd file and the _site.yml file).
Instead, I guess there should be an option to simply tell rmarkdown to take my single document and put the section headers in a nice frame to the left, as in the example page from RStudio.
Have you tried this approach? It works for me and it's also on the homepage, you provided:
---
title: "Untitled"
output:
html_document:
toc: true
toc_float: true
---
# header 1
# header 2
# header 3
With a little bit of text, it looks like that:
I am using R Studio and R Markdown to create an ioslides presentation. I would like to eliminate the title slide, and begin the presentation with a normal slide. So far, I have tried removing the title from the YAML options, but this just results in a blank title page.
How can I remove the title page altogether?
my YAML options
---
output:
ioslides_presentation:
widescreen: true
---
You can try to customise the template file. You can find the path of the default one in your system by typing rmarkdown:::rmarkdown_system_file("rmd/ioslides/default.html") in the console.
The easiest way to play with it would be to copy it to the directory of your project, rename it and put additional YAML option like template: custom_template.html. Even though this might not be enough to remove the title slide completely, you can always customise it so it looks like the first slide of your presentation.