I'm hoping this is a question with a simple answer. I am using Rmarkdown/knitr to author a PDF document (in RStudio). Many LaTeX classes (like article) automatically indent the first line of a paragraph of text, but Rmarkdown does not, nor can I figure out a way to do so.
Here's a simple example:
---
title: "minimal"
author: "prison rodeo"
output: pdf_document
---
This is an R Markdown document.
I would like this paragraph to be first-line indented, but it is not.
Using > indents the entire paragraph, which is not what I'm looking for. I've tried spaces/tabs at the beginning of each paragraph, and using \indent; neither seems to work. Any ideas?
The default Pandoc template includes an indent argument. If set to true, paragraphs start with an indentation.
----
title: "Title"
author: "Me"
output: pdf_document
indent: true
----
I believe the following in your YAML header will work the same and has the advantage of still compiling should you decide to knit your document to an HTML file (though, I haven't tested this).
----
title: "Title"
author: "Me"
header-includes:
- \setlength\parindent{24pt}
output:
pdf_document
----
If what you're after happens to be the default settings in other regards as well, you might also be interested in setting the \parskip option to its default setting, since it is otherwise set to {6pt plus 2pt minus 1pt}
header-includes:
- \setlength\parindent{24pt}\setlength{\parskip}{0.0pt plus 1.0pt}
Related
Probably a basic question but I can't see how to knit my RMarkdown document into a Word document. I've checked the various ReadMe's e.g. https://crsh.github.io/papaja_man/ but can't see anywhere where it is spelled out. Any help is appreciated.
If you are looking to produce a Word document in APA style using papaja you can change the default output specified in the YAML front matter to the following:
---
output: apa6_docx
---
This is also mentioned in the package manual.
I believe you have to specify it in your yaml header as such:
---
title: TITLE
author: AUTHOR
output: word_document
---
Also, the manual does note that there functions won't work when converting into word.
When I write # Introducción into my .rmd file, the section title is on the format 1. Introducción by default. I need something like this:
I prefer to use only markdown language. Is it possible to change into my YAML header?
If you're ok with some minimal TeX syntax you could try this:
----
title: "Title"
author: "Me"
header-includes:
- \usepackage[Sonny]{fncychap}
output:
pdf_document
----
\chapter{Introducción}
This is just a proposal to use the fncychap class, see here for some ideas. I couldn't test it here, but you might get an idea.
I recently asked
Changing the font size of figure captions in RMarkdown HTML output
and I got a very nice answer which uses this CSS method. I wanted to try the same, but this time with Word output. If you don't want to read my former question, I summarize the issue here: I'd like to make the font size of all figure captions in my R Markdown document smaller. The final output is Word,this time, and I'm working in R Studio. To load the picture, I use the include_graphics function from knitr, because I've been told it's the best way (see here). My .Rmd file is:
---
title: "ppp"
author: "ppp"
date: "`r Sys.Date()`"
output:
word_document:
fig_caption: yes
html_document:
fig_caption: yes
---
<style>
p.caption {
font-size: 0.8em;
}
</style>
```{r setup, include=FALSE}
library(knitr)
opts_chunk$set(echo = FALSE)
```
```{r foo, fig.cap="$f_{p}$ as a function of $g$ for various values of $r=\\frac{\\rho_{w}}{\\rho_{a}}$"}
# All defaults
include_graphics("download.jpg")
```
This is regular text.
The corresponding output is:
Clearly, this CSS method doesn't work (I guess it's something related to HTML, so it doesn't render in Word). In Word I can manually change the font size for each caption, but I'd rather set some global R Markdown parameter. Is that possible?
Almost as easy as in the HTML case. The following applies to the workflow using LibreOffice. But in Word it should be almost the same:
Produce your docx output file.
Open it in LibreOffice (or Word, or Pages, ...)
In LibreOffice, right-click the caption and choose Edit Style (in Word you can open the styles pane with Ctrl+Shift+Alt+S)
In the menu that popped up you can modify the style for Image Captions
When you are done editing the style, click Apply and just save the file as a docx called template.docx
Finally, add a style reference in the YAML header of your Rmd document like
title: "ppp"
author: "ppp"
date: "July 4, 2017"
output:
word_document:
reference_docx: template.docx
fig_caption: yes
And the captions should be smaller now according to how you changed the style in your reference document.
I have some .Rmd files in which I need to make some changes to the layout in subsections. This example shows what I need to do.
This is an example Rmd code:
---
title: "test"
output:
pdf_document:
latex_engine: xelatex
number_sections: yes
toc: yes
toc_depth: 3
html_document: default
mainfont: Calibri Light
header-includes:
- \usepackage[dutch]{babel}
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyfoot[LE,RO]{test}
- \usepackage{floatrow}
- \floatsetup[table]{capposition=top}
- \usepackage{dcolumn}
- \usepackage{here}
- \usepackage{caption}
- \captionsetup{labelsep=space,justification=justified,singlelinecheck=off}
---
# Article
## title
#### subsubsubtitle {-}
Here is some text
The result if generating pdf is:
But what I really want is:
So I want the text to be starting on the next line instead of right after the section header. (Also I don't want the subsection to be numbered and, that's why I put the {-} right after it.)
Does someone know how to manage this?
This addresses the Latex side of the problem.
The \paragraph, which is what \subsubsubsection is, just has different formatting and presentation. One of the things is that it doesn't start a new line. This is in pure Latex.
Ways around it:
The package titlesec allows you to customize the title appearance a lot. See this post.
Do it in Latex itself -- [re]define how \paragraph works -- see the above post, and/or this post.
Tweak it in the next itself, adding a newline. See below.
There may be a more direct way in .Rmd but I am not familiar with it and this has the Latex tag.
I have to address another aspect of this, without debating poster's purpose. Such deep hierarchy may indicate a need to rethink the structure. Does it help in making the document easier and more intuitive to use, or does it do the opposite?
With that out of the way, here are some direct ways of making it add a line, as requested.
Tweak it in the text itself, so that it takes a newline (\newline alone doesn't work).
\paragraph{title_text}
\mbox{ }\\
paragraph text here
Another way
\paragraph{title_text} \hspace{0pt} \\
paragraph text here
With titlesec package you can redefine the \paragraph, by changing [runin] to [hung]
\usepackage{titlesec}
\titleformat{\paragraph}[hung] % default is [runin]
{\normalfont\normalsize\bfseries}
{\theparagraph}{1em}{}
Or, can explicitly change the spacings
\usepackage{titlesec}
\titleformat{\paragraph}
{\normalfont\normalsize\bfseries}{\theparagraph}{1em}{}
\titlespacing*{\paragraph}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
For a succinct summary of the titlesec package see this post.
All this is straight-up Latex and I am not sure how it works with .Rmd.
I have an issue rendering bibliographies covering more than one page as only the first one is printed using RMarkdown and beamer output.
The same question has been posted at http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html#comment-2398115545 but without any help.
---
title: "Sample Document"
output: beamer_presentation
bibliography: bibliography.bib
---
You can force a slide to be continued on the next one by setting its class to allowframebreaks. Just do this for your last slide. From the pandoc mailing-list:
## References {.allowframebreaks}
Edit: knitr has a setting that prevents this solution from working out of the box with rmarkdown. See this question for a solution.