Reputation: 356
I am trying to format a references section for an html printout created in Rmarkdown, and generate a hanging indent for the references to make them easier to read. The text is in just generic text format and is not in bibtex
or any special reference manager format for Rmarkdown.
I tried the answer given in this question (https://stackoverflow.com/questions/33691391/rmarkdown-hanging-indent-citation\), however it did not work. I tried several different methods of formatting the text in Latex but they did not work. Below is .Rmd code that shows some of my attempts in a replicable format.
---
title: "Untitled"
output:
html_document: default
---
\begin
\setlength{\parindent}{-0.2in}
\setlength{\leftskip}{0.2in}
\setlength{\parskip}{8pt}
Author1a, Author2a. Year. A very long title of a journal article that wraps around 1. Journal1. Volume:Pages.\\
Author1b, Author2b. Year. Title2. Journal2. Volume:Pages.\\
Author1c, Author2c. Year. Title3. Journal3. Volume:Pages.\\
\end
$\setlength{\parindent}{-0.2in}
\setlength{\leftskip}{0.2in}
\setlength{\parskip}{8pt}
Author1a, Author2a. Year. A very long title of a journal article that wraps around 1. Journal1. Volume:Pages.\\
Author1b, Author2b. Year. Title2. Journal2. Volume:Pages.\\
Author1c, Author2c. Year. Title3. Journal3. Volume:Pages.\\$
$$
\setlength{\parindent}{-0.2in}
\setlength{\leftskip}{0.2in}
\setlength{\parskip}{8pt}\\
Author1a, Author2a. Year. A very long title of a journal article that wraps around 1. Journal1. Volume:Pages.\\
Author1b, Author2b. Year. Title2. Journal2. Volume:Pages.\\
Author1c, Author2c. Year. Title3. Journal3. Volume:Pages.\\
$$
```{=Latex}
\setlength{\parindent}{-0.2in}
\setlength{\leftskip}{0.2in}
\setlength{\parskip}{8pt}
Author1a, Author2a. Year. A very long title of a journal article that wraps around 1. Journal1. Volume:Pages.\\
Author1b, Author2b. Year. Title2. Journal2. Volume:Pages.\\
Author1c, Author2c. Year. Title3. Journal3. Volume:Pages.\\
```
The last chunk is supposed to be a code block defined as a LaTeX environment following https://bookdown.org/yihui/rmarkdown-cookbook/raw-latex.html but if I try to include two sets of code blocks to represent the chunk as displayed in Rmarkdown the formatting gets messed up.
I did some more research and it looks like many of the functions of Latex may not be available when knitting to an .html document, only a .pdf or a word document (https://github.com/rstudio/rmarkdown/issues/1829), and only Latex Math is compatible with html. Thus, the previous question might only be applicable when knitting to a PDF. I don't need to write the references using LaTeX, though it seemed before this to be the easiest way to do so.
Is there a way to format a hanging indent in non-coding text in Rmarkdown when the document to be created is an .html file, rather than a .pdf report?
Upvotes: 0
Views: 457
Reputation: 18714
For an html_document
output:
You could set this within script tags within the RMD (not in a chunk or in a chunk-- your choice). You can just write it when you use it, as well.
None of this is within a code chunk; this is a text section between chunks.
<div style="text-indent: -40px; padding-left: 40px;">
Names. (dates). Titles titles titles titles. *Sources sources sources, number*(number), pages-pages. And of course the DOI with no period
Names. (dates). Titles titles titles titles. *Sources sources sources, number*(number), pages-pages. And of course the DOI with no period
Names. (dates). Titles titles titles titles. *Sources sources sources, number*(number), pages-pages. And of course the DOI with no period
</div>
This is what this output looks like:
I don't know what your knowledge level is, so if this is something you're familiar with, just ignore it. The div
tags and inline styles work with regular text when rendering as HTML
.
For every opening tag, you need a closing tag. <div> and </div>
The asterisks cause the text to be italicized.
This could be useful: 96 px is about 1 inch. (Should the amount of indent be critical.)
Upvotes: 1