Short header for a very long Section's title in beamer presentation R Markdown (Pandoc) - header

I am working on a beamer_presentation which consists of several sections. The section titles are too long to fit into the CambridgeUS headline. I have already tried several options from related latex sources to use some short title for the section (say just "Chapter 1" instead of "Chapter 1 with a very-very-very-very-very long title" by \AtBeginSection{\title[Short title]{Long title}}) but yet can't figure out how to manage this in header-includes of R Markdown YAML. I set the section title through # in Markdown
---
title: Title for the whole presentation
subtitle: 'Presentation'
author:
- Author
institute: "Institution"
date: " `r format(Sys.Date(), '%B %d, %Y')`"
output:
beamer_presentation:
latex_engine: xelatex
toc: true
highlight: tango
theme: "CambridgeUS"
colortheme: "lily"
fonttheme: "serif"
slide_level: 3
keep_tex: true
header-includes:
- \setbeamertemplate{navigation symbols}{}
- \AtBeginDocument{\title[Presentation]{Title for whole presentation}}
- \renewcommand{\raggedright}{\leftskip=0pt \rightskip=0pt plus 0cm}
- \def\sectionname{Chapter}
- \AtBeginSubsection{}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```
# Chapter 1 with a very-very-very-very-very long title
## Intro
### The first page

In beamer, this is trivial, you can use \section[short version]{long version}. But Markdown makes such an easy job excruciatingly difficult.
However you can trick markdown like this:
---
title: Title for the whole presentation
subtitle: 'Presentation'
author:
- Author
institute: "Institution"
date: " `r format(Sys.Date(), '%B %d, %Y')`"
output:
beamer_presentation:
latex_engine: xelatex
toc: false
highlight: tango
theme: "CambridgeUS"
colortheme: "lily"
fonttheme: "serif"
slide_level: 3
keep_tex: true
header-includes:
- \setbeamertemplate{navigation symbols}{}
- \AtBeginDocument{\title[Presentation]{Title for whole presentation}}
- \renewcommand{\raggedright}{\leftskip=0pt \rightskip=0pt plus 0cm}
- \def\sectionname{Chapter}
- \AtBeginSubsection{}
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```
```{=latex}
\tableofcontents[hideallsubsections]
\end{frame}
\section[short version for headline]{Chapter 1 with a very-very-very-very-very long title}
\subsection[short subsection for headline]{Intro}
\begin{frame}
\frametitle{The first page}
```
some text
(be careful where you place this command, otherwise you might end up with empty extra frames - that's why I had to switch off the automatic toc and insert it manually...)

Related

Change title size with quarto titlepages extension when rendering to pdf

I am creating a short report with quarto in rstudio, rendering it to pdf. I use the quarto titlepages extension to create a title page with a logo and a background image. I can get everything to work except for the size of the title font.
I've been searching in the web for hours, and trying all approaches I could think off, but the font size of the title never changes...can someone give me a hint on what I am doing wrong?
This is my YAML:
---
title: "Effect of treatment on the species 1"
author: "Author 1 and Author 2"
date: ' `r paste("Date:",Sys.Date())`'
lang: gl
format:
titlepage-pdf:
documentclass: scrbook
titlepage: plain
titlepage-geometry:
- top=70mm
- bottom=30mm
- right=30mm
- left=30mm
titlepage-logo: "images/circularNegro.png"
titlepage-bg-image: "images/OsTres.png"
titlepage-theme:
elements: ["\\titleblock", "\\logoblock", "\\authorblock", "(biólogos colexiados)" ]
page-fontfamily: "Helvetica Neue"
page-align: center
title-fontsize: 30
title-align: center
title-space-after: 3cm
author-fontsize: 16
author-style: plain
logo-align: center
logo-size: 4cm
logo-space-after: 1cm
bg-image-location: "ULCorner"
bg-image-size: 21cm
pdf:
# Fonts
mainfont: Helvetica Neue
fontsize: 12pt
papersize: A4
margin-top: 25mm
margin-bottom: 25mm
margin-left: 25mm
margin-right: 25mm
toc: true
toc-depth: 2
toc-title: Táboa de contidos
editor: visual
---
I tried with title-fontsize: 30 and with title-style: "large" but none of them would change the font size.
I also tried changing the document class from article, to scrartcl and scrbook.
I did also simplify all the YAML and even remove completely the format: pdf: section of it, but title font size did never change.
I finally tried to define title font size with CSS (which I do not know) by including the following chunk after the YAML (based on this question Change title size and color in Quarto (html output)):
```{css, echo=FALSE}
.title {
font-size: 24px;
font-family: "Helvetica Neue";
}
```
When I do that I get the following error:
Unable to locate an installed version of Python 3.
To my understanding, title-fontsize option is not having any effect on the title font size. Because if we run the following,
---
title: "Effect of treatment on the species 1"
author: "Author 1 and Author 2"
date: last-modified
lang: gl
format:
titlepage-pdf:
documentclass: scrbook
titlepage: plain
titlepage-geometry:
- top=70mm
- bottom=30mm
- right=30mm
- left=30mm
titlepage-theme:
elements: ["\\titleblock", "\\logoblock", "\\authorblock", "(biólogos colexiados)" ]
page-align: center
title-fontsize: 50
title-align: center
title-space-after: 3cm
author-fontsize: 16
author-style: plain
keep-tex: true
---
And then checking the underlying intermediate tex file, we can see,
\newcommand{\titleandsubtitle}{
% Title and subtitle
{\fontsize{50}{60.0}\selectfont
{\Large{\nohyphens{Effect of treatment on the species 1}}}\par
}%
}
\newcommand{\titlepagetitleblock}{
\titleandsubtitle
}
Therefore, title font size is actually \Large and our specified font size 50 is having no effect at all.
Therefore, one approach to this issue, could be using title-fontstyle which takes tiny, small, large, Large, LARGE, huge, Huge` as font sizes.
---
title: "Effect of treatment on the species 1"
author: "Author 1 and Author 2"
date: last-modified
lang: gl
format:
titlepage-pdf:
documentclass: scrbook
titlepage: plain
titlepage-geometry:
- top=70mm
- bottom=30mm
- right=30mm
- left=30mm
titlepage-theme:
elements: ["\\titleblock", "\\logoblock", "\\authorblock", "(biólogos colexiados)" ]
page-align: center
title-fontstyle: Huge
title-align: center
title-space-after: 3cm
author-fontsize: 16
author-style: plain
---
Now the aforementioned Huge, LARGE, Large etc. font sizes are LaTeX predefined font sizes. If you want to use custom font sizes other than those, you can define a new fontsize command and then pass it to title-fontstyle option.
So we define a new font size command gigantic with a font size 70 and use this in title-fontstyle: gigantic.
---
title: "Effect of treatment on the species 1"
author: "Author 1 and Author 2"
date: last-modified
lang: gl
format:
titlepage-pdf:
documentclass: scrbook
include-in-header:
text: |
\newcommand{\gigantic}{\fontsize{70}{73}\selectfont}
titlepage: plain
titlepage-geometry:
- top=70mm
- bottom=30mm
- right=30mm
- left=30mm
titlepage-theme:
elements: ["\\titleblock", "\\logoblock", "\\authorblock", "(biólogos colexiados)" ]
page-align: center
title-fontstyle: gigantic
title-align: center
title-space-after: 3cm
author-fontsize: 16
author-style: plain
---
And lastly some remarks about your attempt of using CSS,
You can not use CSS to modify anything that will be rendered as pdf. You have to use either latex commands or pandoc options.
And you are facing that error, because you are using css chunk which quarto finds as the very first code chunk in the qmd file while rendering the document and as a consequence, Quarto will try to render this document using jupyter which requires python installation. To avoid this problem, one need to use engine: knitr. But again, you do not need a css chunk while rendering to pdf format at the first place.
Yes, it is a rather confusing problem that I wasn't sure how to solve. The title-fontsize is being overridden by title-fontstyle. You need to set title-fontstyle: [] This will work:
---
title: "Test page title font size"
date: last-modified
format:
titlepage-pdf:
documentclass: scrbook
titlepage: plain
titlepage-theme:
title-fontsize: 50
title-align: center
title-fontstyle: []
keep-tex: true
---
I considered doing a check if title-fontsize is spec-ed and then check if any fontsize is being set in title-fontstyle and disallow that. But I haven't coded that. I am thinking perhaps to just 'outlaw' any fontsize in title-fontstyle and require title-fontsize for that. The only problem is that you also need to set title-fontspacing; there is a default, but it doesn't always look good. Maybe I should just issue a warning if title-fontsize is set and title-fontstyle has a fontsize specified.

How do I move a table to the seconde page in r markdown?

I have some problems, I would like my table of contents to be on the second page. Unfortunately, when I generate it with the "toc: true" code, it appears on the first page (i.e. just before the front page, which is not the best). Any help for me?
title: ' '
output:
pdf_document:
number_sections: yes
toc: true
toc_depth: 2
html_document:
df_print: paged
geometry: left = 2.5cm, right = 2cm, top = 2cm, bottom = 2cm
fontsize: 11pt
header-includes:
- \usepackage{float}
- \usepackage{sectsty}
- \usepackage{paralist}
- \usepackage{setspace}\spacing{1.5}
- \usepackage{fancyhdr}
- \usepackage{lastpage}
- \usepackage{dcolumn}
- \usepackage{natbib}\bibliographystyle{agsm}
- \usepackage[nottoc, numbib]{tocbibind}
- \usepackage{ragged2e}
bibliography: bibliography.bib

Rmarkdown knit pdf - getting underlined text instead of italic using *italic* (huxtable issue?)

Rmarkdown text (between chunks) when formated italic using * * knits to pdf underlined and not italic format when I print huxtable.
Here is my example:
```
---
title: "<center><center>"
author: "<center> jd <center><br>"
date: "<center> `r Sys.Date()` <center>"
output:
pdf_document:
fig_caption: yes
toc: yes
toc_depth: 3
number_sections: true
latex_engine: xelatex
html_document:
code_folding: show
df_print: paged
theme: yeti
highlight: tango
toc: yes
toc_float:
collapsed: false
smooth_scroll: false
number_sections: true
fontsize: 10pt
---
This * * makes text *italic*.
```{r lib, message = FALSE}
library(huxtable)
library(tidyverse)
data(iris)
dt_hux <- iris[1:5,1:5] %>% as_hux() %>%
set_font_size(8) %>% set_font("Arial") %>%
set_bold(1, everywhere) %>%
set_top_border(1, everywhere) %>%
set_bottom_border(c(1, 6), everywhere)```
Until this point using * * will give italic format in knit pdf (if next chunck is not run).
But after the next chunk is run * * will underline text (in whole Rmarkdown). Commenting out **dt_hux** returns formatting to italic. Also knit to html will print italic formatting even with dt_hux.
```{r table}
options(huxtable.latex_use_fontspec = TRUE)
options(huxtable.print=print_latex)
dt_hux```
```
Is there a solution to this issues as I need to print huxtable in pdf?
From the TeXnical perspective the problem is that the ulem package is loaded without the normalem option. A couple of workarounds:
use classoption: normalem (based on Knitr hook to add code before \documentclass line in tex file to avoid options clash with xcolor). Caveat: this will pass the option to all packages and might be undesired in case the same option name is also used by other packages (I'm not aware of any other package that uses this option, but just in case ...)
add \normalem either as header-include or at the start of your document
This problem was fixed in huxtable 5.2.0, so you just need to update your package.

R markdown: simplify creating tables of figures and text

For R markdown Rmd web pages I want to generate tables containing in the first column thumbnail images (that link to a larger image or a web site) and
descriptive text in the 2nd column. One example is the following image:
I know I can create this manually in raw HTML, but that is very fiddly and time-consuming. There must be some easier way.
On a different page, I tried a markdown / pandoc table, but that didn't work, and I reverted to manual coding of HTML
icon | title
--------------------------------------------------+--------------------------
<img src="images/books/R-Graphics.jpg" height=50> |Paul Murrell, *R Graphics*, 2nd Ed.
<img src="images/books/R-graphics-cookbook.jpg" height=50> | Winston Chang, R Graphics Cookbook
<img src="images/books/lattice.png" height=50> | Deepayan Sarkar, *lattice*
<img src="images/books/ggplot2.jpg" height=50> | Hadley Wickham, *ggplot2*
Perhaps the htmltools package would be useful here, but I can't quite see how to use it in my Rmd files for this application.
Probably forgot escaping quotes? This works fine for me:
---
title: "The Mighty Doge"
output: html_document
---
```{r}
library(knitr)
create_thumbnail <- function(file) {
paste0("<img src=\"", file, "\" style=\"width: 50px;\"/>")
}
df <- data.frame(Image = rep("unnamed.png", 5),
Description = rep("Doge", 5))
df$Image <- create_thumbnail(df$Image)
kable(df)
```
Here is an approach that uses htmltools and seems much more flexible, in that I can control the details somewhat more easily.
I'm not familiar with bootstrap <div> constructs, so I used HTML table constructs. I had to define functions for tr(), td() etc.
```{r html-setup, echo=FALSE}
library(htmltools)
# table tags
tab <- function (...)
tags$table(...)
td <- function (...)
tags$td(...)
tr <- function (...)
tags$tr(...)
# an <a> tag with href as the text to be displayed
aself <- function (href, ...)
a(href, href=href, ...)
```
Then functions to construct my table entries the way I wanted:
```{r table-functions, echo=FALSE}
# thumnail figure with href in a table column
tabfig <- function(name, img, href, width) {
td(
a(class = "thumbnail", title = name, href = href,
img(src = img, width=width)
)
)
}
tabtxt <- function(text, ...) {
td(text, ...)
}
```
Finally, use them to input the entries:
## Blogs
```{r do-blogs, echo=FALSE}
width="160px"
tab(
tr(
tabfig("FlowingData", "images/blogs/flowingdata.png", "http://flowingdata.com/", width=width),
tabtxt("Nathan Yau,", aself("flowingdata.com/"),
"A large number of blog posts illustrating data visualization methods with tutorials on how do do these with R and other software.")
),
tr(
tabfig("Junk Charts", "images/blogs/junkcharts.png", "http://junkcharts.typepad.com/", width=width),
tabtxt("Kaiser Fung,", aself("http://junkcharts.typepad.com/"),
"Fung discusses a variety of data displays and how they can be improved.")
),
tr(
tabfig("Data Stories", "images/blogs/datastories.png", "http://datastori.es/", width=width),
tabtxt("A podcast on data visualization with Enrico Bertini and Moritz Stefaner,",
aself("http://datastori.es/"),
"Interviews with over 100 graphic designers & developers.")
)
)
```
I still need to tweak the padding, but this gives me more or less what I was after:

shiny ioslides selectInput scrollbar failure

I need to have two consecutive slides use similar selectInputs. When I do this, the scrollbar on the first slide fails. I use "selectize=FALSE" so that the user can deselect options. The scrollbar works fine when it's just one slide.
Am I doing something wrong, or is this a bug? Any help would be greatly appreciated!
---
title: "Scrollbar Failure Demo"
author: "KM"
date: "May 20, 2016"
runtime: shiny
output: ioslides_presentation
---
## Slide1
```{r Slide1, echo=FALSE}
fulllist <- c(1,2,3,4,5,6,7,8,9,10)
inputPanel(
selectInput("Option1", label="Pick Many", multiple=TRUE, selectize=FALSE,
choices=fulllist, selected=fulllist))
renderPlot({plot(input$Option1)
title(main="Scrollbar Fails on Slide 1")})
```
## Slide2
```{r Slide2, echo=FALSE}
inputPanel(
selectInput("Option2", label="Pick Many", multiple=TRUE, selectize=FALSE,
choices=fulllist, selected=fulllist))
renderPlot({plot(input$Option2)
title(main="Scrollbar Works on Slide 2")})
```