Spacing changes when using xaringan with ninjutsu and going from a list with one bullet point to two bullet points - r-markdown

I am trying to create a complex incremental slide in Rmarkdown using the xaringan with ninjutsu for column formatting. I cannot (to my knowledge) use the standard approaches to incremental slides as elements are changing in multiple places (e.g., more text on the left hand column and an image that changes in the right hand column). Instead, I am recreating the entire slide each time. The problem I am having is that bullet lists change formatting as I go from one bullet point to two (even if I do not have multiple columns). Specifically, the spacing from text to bullets increases when I add a bullet point.
A simple document to reproduce the problem is:
---
title: "Test of bullet alignment"
output:
xaringan::moon_reader:
css: ["default", "ninjutsu"]
---
- A test
---
- A test
- B test
After knitting this document, when you go from the 1st to the 2nd slide the spacing from the bullet point to the text changes. This causes a noticeable change in the word wrapping that makes the slide look non-incremental.
Does anyone understand what is going on and have a solution or workaround?

You have such inconsistent space because you are adding extra space between two bullet points, which leads to wrap the texts A test and B test with paragraph html element p and ninjutsu.css contains the following line for styling the paragraph element.
.content > h1, h2, h3, p { padding-left: 2%;padding-right: 2%; }
So when you are writing a single bullet point, that is not getting wrapped with p but in the next slide when you are writing two bullet points with an extra space between them they are getting wrapped with p and therefore, getting 2% left and right padding. And hence the problem.
But in default xaringan (in default.css) there's no such style rule for paragraph elements in slide content class. That's why, in the base case, there's no such space inconsistency.
Solution
Now a possible solution could be to overwrite the css rule for p elements inside the list elements li and write your own rule for the desired padding (vertical and horizontal), which will work for both the below cases,
- A test
- B test
Or
- A test
- B test
Rmarkdown file
---
title: "Test of bullet alignment"
output:
xaringan::moon_reader:
css: ["default", "ninjutsu"]
---
```{css, echo=FALSE}
li p {
display: inline !important;
padding: 0px !important;
}
li {
padding: 6px 3px;
}
```
### This is non tight list (with space between items)
- A test
---
###This is non tight list (with space between items)
- A test
- B test
---
### This is tight list (with no space between items)
- A test
---
### This is tight list (with no space between items)
- A test
- B test

Related

How to remove css-grid gutter from outer edge of a row

I am currently working to replicate a design and I am using css grid for the layout.
I applied the css gap attribute and gutters were created between the rows and columns. However, a gutter was created outside the last row and I have been battling to fix it. from what I know about grid gap and also from css Tricks,the gutters are only created between the columns/rows, not on the outer edges.
Following is a screenshot of how it looks like after my implementation current look You can notice the gutter at the bottom of the last row on the right. I do not want the gutter there, I just want the row to take up the space at the bottom. This is the code for the grid container.
.App {
display: grid;
grid-template-rows: repeat(2, 1fr);
grid-template-columns: repeat(4, 1fr);
gap: 25px;
width: 70%;
height: 55%;
background-color: var(--pry-blue);
}

Rmarkdown suppress image keeping figure numbering

In writing papers for publication it is often required to keep figures in a separate document (or even a separate document for each figure). In doing so you must manually maintain the figure labels in text i.e. you must write "y was greater than 50% (Figure 1)" in the rmd document rather than something like "y was greater than 50% (Figure #ref(fig:Fig1))". This means that if the figures are rearranged, which is common, then you must manually change all the figure labels to suit the new order.
I am trying to find a way to code in rmd (officedown) that keeps the automatic numbering of the figures within the text but doesn't actually compile the word doc with the figure images.
Below is some example code, I have tried various argument such as fig.show='hide' but without success.
Any and all comments and ideas are welcome in getting to the end result. For example, cross referencing such as in book down in this question. Ideally I would also be able to leave a small amount of text where the actual figure would go as well. Something like 'Figure 1, here' as a simple marker for reviewers but this can be done manually with ease.
---
citation_package: natbib
bibliography: './CompileResources/SBLitRev_Bibli.bib'
biblio-style: 'User/Zotero/styles/ecology-letters.csl'
output:
officedown::rdocx_document:
reference_docx: "./CompileResources/template.docx"
page_size:
width: 8.3
height: 11.7
orient: "portrait"
page_margins:
bottom: 1
top: 1
right: 1.25
left: 1.25
header: 0.5
footer: 0.5
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.cap = TRUE)
library(officedown)
library(officer)
library(rvg)
library(knitr)
fp <- fp_par(
text.align = "center",
padding.bottom = 20, padding.top = 120,
border.bottom = fp_border())```
y was greater than 50% (Figure \#ref(fig:Fig1)).
*Figure 1, here*
```{r fig.cap="Bla bla", include=F, fig.id = "Fig1", fig.cap.style = "Image Caption", fig.show='hide'}
knitr::include_graphics("./Figures/Fig1.pdf")```

Creating two table of contents with different depths in R Markdown

I created my lecture notes in pdf format using RMarkdown but it has many subheaders. Because of this, I want to create two different table of contents: first table of contents with 1 depth, then table of contents in 4 depth respectively.
Adding both toc_depth: 1 and toc_depth: 4 did not work.
My YAML header:
---
title: "Lecture Notes"
author: "x"
output:
pdf_document:
highlight: tango
toc: true
toc_depth: 4 #depth table of contents
number_sections: true
documentclass: article
classoption: a4paper
fontsize: 12pt
geometry: "right=1cm, left=1cm, top=1cm, bottom=3cm"
---
As far as I am aware, I don't believe two Table of Contents is possible. One thing you can try is if you don't want a certain heading numbered, you can do
## Including Plots {-}
Which heads it has a header, but doesn't number it in the TOC. Here is the two output differences
without {-}
with {-}
These can be used in places like the Preface, about the authors, etc.
This is not a perfect solution (maybe some with more knowledge could automate this).
The solution works if the intermediate latex file is kept and a short table of contents is manually added using the shorttoc package.
Adding shortdoc:
...
\documentclass[
]{book}
\usepackage{shorttoc}
...
And than adding it between title and TOC:
\shorttableofcontents{〈title 〉}{〈depth 〉}

Coloring a table in apache superset

I want to color the background bars (or the entire cells) of the table as shown in the appended screenshot based on the "Group-By"/dimension value (red for "rot", yellow for "gelb" and green for "grün").
I was able to color the metric-part of other visualizations with label_colors, but I have not yet found a way to color the cells of the table based on a "dimension".
Is there a way to do this?
As of now:
EDIT: I wanted to color it the following way (edited with paint):
This is a tad hacky, but you can add a markdown component and add the following markup:
<style>
th {
color: red; /* or whatever color/hex code you want */
}
</style>
The markdown component will be blank after you add this--i.e. there will just be a blank markdown block-- so you may want to add some copy. Alternatively, if you already have a markdown block, you can add it there, and it won't appear as long as you remember the <style></style> tags.

Change Default Beamer slide size

In R markdown when using Beamer slides if you try to plot you need to specify the plot sizes (unlike in the reports) so that the plots fit on a page. This can often result in the plots appearing to be squashed together, as apposed to just a smaller version of the plot.
Is there some method to change the default slide size to alleviate this problem?
I have tried
header-includes:
- \usepackage[papersize={25.6cm,19.2cm}]{geometry}
in the yaml header, and I get the error
! LaTeX Error: Missing \begin{document}.
Using R Markdown I shouldn't need to use this though.
A reproducible example is shown below
---
title: "Plots look bad"
author: "Beavis"
date: "`r format(Sys.time(), '%d/%m/%Y')`"
output: beamer_presentation
header-includes:
- \usepackage{float}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(results = 'hide')
knitr::opts_chunk$set(warning = FALSE)
knitr::opts_chunk$set(cache=TRUE)
knitr::opts_chunk$set(fig.height=3.5)
```
# Introduction
```{r}
pca <- prcomp(iris[,1:4])
biplot(pca)
```
Here, you if you run this the second slide looks like this As you can see the plot is rubbish. What is the best way to avoid this problem?
The biplot function uses par(pty = "s") to force a square plot, so it's not going to fill a rectangular slide. You can make it look better by asking the fig.height to be bigger, but then it will overflow the bottom of the slide. To prevent this, you can set both fig.height to a large number, and out.height (which will be a LaTeX measurement) to something that will fit on a slide. For example, using this chunk
```{r fig.height=10, out.height="0.8\\textheight"}
pca <- prcomp(iris[,1:4])
biplot(pca)
```
I see this output:
I'd recommend a smaller fig.height, but your preference may be different.
Both fig.height and out.height could be specified using knitr::opts_chunk$set as defaults for all slides if you want.
You could also specify out.width="\\textwidth" for a really ugly stretched plot that fills the slide, but I wouldn't recommend it.