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.
Related
I was trying to write create some beamer slides in Rmarkdown. Since the beamer slides would need to include some Chinese characters, I have to specify xelatex as the latex engine.
However, recently I found that the xelatex engine has a problem (the problem was not here a month ago): When using xelatex as the latex engine, the itemise bullets in beamer slides disappeared.
Does anyone know how to resolve this issue?
Below is a minimum working example:
---
title: trial doc
institute: |
| Department trial
| trial Education
Date: "17 October 2020"
output:
beamer_presentation:
theme: "CambridgeUS"
colortheme: "dolphin"
slide_level: 3
latex_engine: xelatex
df_print: kable
classoption: "aspectratio=169"
fontsize: 10pt
mainfont: Times New Roman
header-includes:
- \setbeamercolor{frametitle}{bg=white}
- \usepackage{ctex}
- \AtBeginSubsection{}
- \AtBeginSection{}
- \setbeamerfont{frametitle}{series=\bfseries}
- \AtBeginDocument{\title[xxx]{xxxxx}}
- \AtBeginDocument{\institute[xxxxx]{\\Department of xxx\\xxx}}
- \AtBeginDocument{\author[xxxxxx]{XXX}}
---
\frametitle{Outline}
\tableofcontents
# 欢迎
\frametitle{\textbf{Welcome}}
some text
some Chinese text 你好
trying to itemize:
- Hello
- subitem
trying some numbered list:
1. hello
2. hello
And the output I get is as below:
Output from the code above
When I try using pdflatex as the latex engine (in which case I cannot use the ctex package and cannot include Chinese characters in my beamer slides), the itemize and numbered list works perfectly.
Really appreciate if someone can help me with this!
As provided by #samcarter_is_at_topanswers.xyz above, I solved this problem by following the steps in github.com/pgf-tikz/pgf/issues/928#issuecomment-700690532.
The example below (i.e. saved as a file index.rmd ) has the same code chunk to display an image above and below the top level heading, but the image doesn't appear above the top level heading. This occurs if there is a file _output.yml with only this entry bookdown::gitbook: in the same directory.
That line seems to enforce a table of contents (which I want) and that appears to strip out anything (image or text) before the first top level heading by default (which I don't want) - so can this behaviour be modified?
---
site: bookdown::bookdown_site
---
```{r echo=FALSE, message=FALSE, warning=FALSE}
library(imager)
im <- load.image(system.file('extdata/Leonardo_Birds.jpg',package='imager'))
plot(im, axes=FALSE)
```
# R Markdown
```{r echo=FALSE, message=FALSE, warning=FALSE}
library(imager)
im <- load.image(system.file('extdata/Leonardo_Birds.jpg',package='imager'))
plot(im, axes=FALSE)
```
What follows is workaround to your Options 2 and 3, using Markdown and CSS to style images and HTML+CSS to style text; also, using base64 image (transparent gif) generator as an space separator between elements.
Beware of whitespaces! (at the end of each line - place two white spaces and hit ENTER)
Does one of these approaches/hacks work for you? If not, it would be better to delete the answer, it may be misleading to others.
---
title: |
![](www/image.png){width=300px}|
|:-:|
![](www/image.png){width=300px style="display: block; margin:0 auto"}
![](www/image.png){width=300px height=90px align=left}
![](www/image.png){width=300px height=90px align=center}
![](www/image.png){width=300px height=90px align=right}
![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==){width=150px}
R Markdown Title
<center>R Markdown Title</center>
<p style="text-align: right;">R Markdown Title</p>
![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==){width=150px}
author: "Author Name"
date: "08/03/2020"
---
Using Markdown table to "style" images |-| (left-aligned), |:-:| (centered) and |-:| (right-aligned) will work well with simple RMarkdown outputs.
I realised that you have an image under # top level heading positioned at the very top of the page - with top:0px. causing image duplication and, possibly, hover problem:
<img src="https://i.imgur.com/GiViTbA.png" style="position:absolute;top:0px;height:100px;" />
replace with:
![](http://stackoverflow.com/favicon.ico){width=50px style="display: block; margin:0 auto;"}
and see what will happen.
---
title: |
![](https://i.imgur.com/GiViTbA.png){width=300px style="display: block; margin:0 auto;"}
![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==){width=50px}
R Markdown Title
![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==){width=50px}
output:
html_document: default
---
# I'm a top level heading {-}
![](http://stackoverflow.com/favicon.ico){width=50px style="display: block; margin:0 auto;"}
Note, you need to replace the image with a local image if you want to show the image in the rstudio viewer.
The image will be visible in the html file created when you knit, if you open in a browser connected to the internet.
```{r echo=FALSE, message=FALSE, warning=FALSE}
plot(cars)
```
EDIT:
Let's try to find a common ground, A Minimal Book Example, github here.
Adjustments made in index.Rmd:
---
title: |
![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==){height=300px}
author: "Author Name"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output: bookdown::gitbook
---
# Prerequisites
<img src="https://i.imgur.com/GiViTbA.png" style="position:absolute;top:50px;height:300px;align:center;" />
This is a _sample_ book written in **Markdown**. You can use anything that Pandoc's Markdown supports, e.g., a math equation $a^2 + b^2 = c^2$.
index.Rmd output:
Adjustments made in Chapter: Introduction (01-intro.Rmd):
# Introduction {#intro}
![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==){height=240px}
<img src="https://i.imgur.com/GiViTbA.png" style="position:absolute;top:50px;height:300px;align:center;" />
You can label chapter and section titles using `{#label}` after them, e.g., we can reference Chapter \#ref(intro). If you do not manually label them, there will be automatic labels anyway, e.g., Chapter \#ref(methods).
01-intro.Rmd output:
With this solution we are "masking" a top level heading (# Introduction) with .png image, which will appear in the Table of Content as text.
Disadvantage: besides the obvious hack, image width must be at least equal or wider than top level heading title.
Note: 3 options are provided here, and none of them are perfect. The perfect solution may rely on modifications to the bookdown package?
Option 1:
Use includes with before_body like this in your _output.yml file (suggested here):
bookdown::gitbook:
css: assets/style.css
includes:
before_body: assets/big-image.html
after_body: assets/footer.html
Disadvantages:
i) Requires making a html file just to insert an image.
ii) If using a web-based image, won't show in Rstudio viewer.
iii) If using a local image, path can get mixed up and won't show in online web html rendering
iv) Includes image at the top of each chapter of bookdown if using before_body: my_image.html. Alternative option in_header: my_image.html does not seem compatible with the sidebar index.
Option 2
Insert image via yaml in index.rmd, using the solution under Tip 3 Add a Logo in your title/header/footer at this blog post
---
title: |
![](my_image.png)
My title
Disadvantages:
i) When you hover over the image, it displays a copy of the image in a slightly different location (Can this "Hover" behaviour be disabled?)
ii) If using a web-based image, won't show in Rstudio viewer.
iii) If using a local image, path can get mixed up and won't show in online web html rendering
Option 3
The code below borrowed from here (which you can place below the top level heading) presumably goes direct through the knitting process and inserts itself in the final html. The issue is that the image doesn't make room for itself and ends up over the first text. Is there some simple html/css to sort this out?
<img src="https://i.imgur.com/GiViTbA.png" style="position:absolute;top:0px;height:100px;" />
Disadvantages:
i) Image doesn't make room for itself and ends up over the first text. You can get around this with a hack by coding extra space (trial and error) through the yaml title like this:
title: |
.
.
.
.
site: bookdown::bookdown_site
EDIT
This is superseded by Radovan's accepted answer.
This was the best answer, taking option 3 from my previous answer, and combining a code approach to making the relevant space from Radovan's answer.
You will still have problems if you want to include a title in the YAML (I don't need this, as my title is in the image).
Also, on first loading the page, it presents nicely, but image is not seen if you go to the top of the document using the table of contents (the inheader approach used by this bookdown shows a better behaviour, but appears at the top of every chapter, which is not desired).
---
title: |
![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==){height=300px}
output:
html_document: default
---
# I'm a top level heading {-}
<img src="https://i.imgur.com/GiViTbA.png" style="position:absolute;top:50px;height:300px;align:center;" />
Note, you need to replace the image with a local image if you want to show the image in the rstudio viewer.
The image will be visible in the html file created when you knit, if you open in a browser connected to the internet.
```{r echo=FALSE, message=FALSE, warning=FALSE}
plot(cars)
```
The problem of hovering the image duplicating the image can be fixed by removing the line below from the css file that is generated at \libs\gitbook-2.6.7\css\style.css
.book .book-header h1 a:hover{color:inherit;text-decoration:none}#media (max-width:1000px){.book .book-header h1{display:none}}
as a result, this code below places the image right above the title:
---
title: |
![class='btn noHover'](images/Stats.png){width=400px style="display: block; margin:0 auto; align:center;" }
<center>GEOG380 Basic Stats with R</center>
---
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.
I am trying to build a book, with 9 chapters. I am using the bookdown::bookdown_site package for that, which I have included in the YAML header in index.Rmd. But when I knit the book, using bookdown::tufte_book2, the pdf file generate the text inside the chunks with different font colors.
When I try to run each chapter individually, using "tufte_handout", the outcome is as expected. Main text and inside chunk text is monochrome and TimesNewRoman.
In rStudio, before build the book, I have tried in Sweave/Program defaults to use both Latex Engines, "xeLaTex" and "pdfLaTex"
YAML header in index.Rmd
---
title: "Operations Research Using R<br />"
author: "Timothy R. Anderson"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
monofont: Times New Roman
highlight: monochrome
documentclass: book
bibliography: ["Master4Bookdowns.bib"]
---
YAML header in each individual ChapterX.Rmd file:
---
title: 'Chapter 3: More LP Models'
header-includes:
- \usepackage{longtable}
- \usepackage{caption}
monofont: Times New Roman
output:
tufte::tufte_handout:
citation_package: natbib
latex_engine: xelatex
toc: TRUE
number_sections: true
highlight: monochrome
tufte::tufte_html: default
tufte::tufte_book:
citation_package: natbib
latex_engine: xelatex
highlight: monochrome
---
I expect all document with the same font type and monochrome.
Since bookdown::tufte_book2 is not specified in your main YAML header, I assume you have an _output.yml file that defines the output format. In that case, you have to add highlicht: monochrome there, i.e.:
bookdown::tufte_book2:
highlight: monochrome
[other options]
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?