How to put a subscript in the slidify title? - r

I am making slides with slidify. In my title that is to be specified in the index.Rmd YAML header, I need to use a subscript, e.g. H20.
in Rmarkdown, I would do H~2~0. That does not work.
in Markdown, I would do H<sub>2</sub>O. That does not work
in mathjax that can be loaded as widget, I would use H\(_2\)O. That works but the mathjax font and fontsize writting is much bigger than the normal title font and fontsize
Is there a clean way to write a subscript in the slidify title, like in latex?

Related

How to customize font type/size for Rmarkdown table output to PPT?

I am kniting my Rmd to PPT using a custom PPT template with different types of slides. I have all headers/text set to Alright Sans Font, mostly size 11.
When I knit to PPT, that all works except the table ouput is calibri and way too large of font. How can i customize?
How do I reduce vertical spacing between numbered/bulleted lists?
I think this might need to happen in the PPT template but not sure.

Change Background color of RMarkdown PDF Code Chunk

I am trying to change the code chunk formatting options in a rmarkdown document that is generated as a pdf. I want the formatting for these code chunks to be different. I want similar to
class.source="bg-info", class.output="bg-warning"
for HTML documents.
Not sure if I understood your question correctly. Please always include an minimum working example (MWE) with your question for greater clarity. Since it is not outline exactly what is required, a general outline is provided.
To change the code chunk formatting options in a Rmarkdown document (PDF or HTML) you can use the built-in Pandoc Syntax Highlighting styles. You can change both the background of code chunks, and the font color. All you have to do is to add the highlight in YAML.
highlight specifies the syntax highlighting style. Some alternatives are default, tango, pygments, kate, monochrome, espresso, zenburn, haddock, breezedark, and textmate. You can also use null to prevent any highlighting. For example:
title: "A nice document"
output:
html_document:
highlight: haddock
You can change the the appearance of your code and output with some predefined CSS classes for backgrounds in HTML: "bg-primary", "bg-success", "bg-info", "bg-warning", and "bg-danger". Arbitrary class names and user-define custom CSS rules are also allowed. A detailed discussion can be found in Yihui Xie's R Markdown Cookbook.

Use Times New Roman 12 pt in r markdown docx

I want to use Times New Roman font in a .docx file using R markdown. I have tried adding the following in the YAML section:
mainfont: "Times New Roman", sansfont: Calibri Light - both with and without quotes. I also specified a template:
output:
word_document:
reference_docx: template1.docx
I had generated template1.docx using R markdown and changed some of the formattings like margin, line number, font size, font face, etc. and everything, but the font face gets copied to the main .docx file. Please help.
The mainfont argument only works for pdf output.
To make your Word document have a specific font, open your template document in Word. Go to the "Design" tab. The Fonts button allows you to select the default fonts for your headings and body text.
You can create your own font pairings if one of the available options is not to your liking. For example, you can create an option with Times New Roman for both headings and body text

Inline code in R markdown PDF file is not displayed correctly

My R markdown PDF file does not show inline code as it should. This only works correct when choosing HTML as output file.
Generally inline code should look like this. So when highlighting some words within my text, I want it to look like this.
E.g. I want to have this sentence in my PDF output:
A good way to pronounce %>%when reading code is then.
Instead I get what you see here:
The image shows how the inline code is displayed in my output. Only changed font and style, instead of grey background.
I use exactly the same code as I am using here at stack overflow: `` these signs before and after the text I want to highlight.
Any tip how to fix this? I need PDF output, and not HTML.
Thanks a lot!
Text like `this` is translated into the LaTeX command \texttt{this}. LaTeX commands can be changed, so we can modify the \texttt command to create a color box:
```{=latex}
\definecolor{codegray}{HTML}{cccccc}
\let\textttOrig\texttt
\renewcommand{\texttt}[1]{\textttOrig{\colorbox{codegray}{#1}}}
```
Add the above at the beginning of your Rmd document (right after the YAML header) to get a gray background for you inline code snippets.

R: how to center output in R markdown

I know I can set fig.align = 'center' if I want to center my figure. But what if I want to center my output in a pdf document?
The following code worked for me.
\center Centered Text \center
And, if you need to put it in bold, as my case, you can use the underline (two at the beggining, two at the end):
\center __Centered Text__ \center
Hopefully it is not too late to add my answer.
You can use html tags in Rstudio Markdown documents.
To center a text you just need to:
<center> TEXT TO CENTER </center>
This works for me when knitting Rstudio Markdowns.
The option for centering a plot you generated by R code in Rmd file and that for an existing figure from a file elsewhere is different.
For the figures you generated in R, I think fig.align="center" is sufficient, even if you want a PDF output.
For <center> <\center> to work, you can only use an HTML output. If you still want PDF output, I think you can use include_graphics(your_img.png) from knitr package, and then you can use chunk options like fig.align="center". If you also want to change the size of this figure, please use something like out.width="50%", but not fig.width.
For more details, I found this article really useful tips and tricks for working with images and figures in r markdown documents.

Resources