Reputation: 2783
I am trying to create custom background colors for blocks of text in a book chapter. If I add this code:
```{block, type="FOO"}
blah
```
to my Rmd file and this:
div.FOO {
font-weight: bold;
background-color: LightGray;
}
to my style.css file the html page looks great but the PDF output no longer includes the chapter and the table of contents is missing.
Can someone please tell me what to tweak to get a PDF to use a custom block? Unfortunately I don't speak TeX so clues for the clueless would be greatly appreciated.
Upvotes: 2
Views: 528
Reputation: 497
You should review Section 9.6 in the R Markdown Cookbook (Xie, Dervieux, and Riederer 2020) for instructions.
In short, you need a preamble.tex
file containing the LaTeX commands for making your custom block (with which you will try and mimic the CSS which defines how it looks in HTML)
You will also need to markup custom blocks in your .Rmd
file differently, like this
:::: {FOO}
blah
::::
Upvotes: 1
Reputation: 366
To give your some context for my answer, here is a "Learn LaTeX in 30 Minutes" talk. It's probably worth your time to take a look at it, just so that you understand more of the basic environment syntax.
To answer your question, bookdown
projects have a file called preamble.tex
. I believe you should add the following lines to that file:
\newenvironment{Foo}{
\begin{center}
\begin{tabular}{|p{0.9\textwidth}|}
\hline \\
}
{
\\\\\hline
\end{tabular}
\end{center}
}
I'm not sure if that answers all of your question, but that's what I have so far.
Upvotes: 3