I have a results section that includes code chunks and text. When I knit my Rmd to a pdf, two of my figures have LaTeX code surrounding them. The captions are not properly rendered. Looking at my Results.tex file, I can see that I have several \textbackslash{} inserted in the figure LaTeX code. I'm assuming this is what is causing the figure captions to not work properly as the working figures do not have these mystery \textbackslash{}. I can not figure out why only 2 out of my 8 figures have this issue, or how to stop \textbackslash{} from being inserted into the code.
Here is the YAML and example of a problem code chunk that contains the broken graph:
---
bibliography: library.bib
csl: journal-format.csl
header-includes:
- \usepackage{setspace}
- \doublespacing
- \usepackage{rotating}
- \usepackage{booktabs}
- \usepackage{makecell}
- \usepackage{gensymb}
output:
pdf_document:
fig_caption: yes
latex_engine: xelatex
keep_tex: yes
indent: true
---
# Results
```{r graph, echo=FALSE, fig.keep = 'all', dev = 'pdf', fig.show = "hold", fig.align= 'center', out.width="70%", fig.asp=0.618, fig.width=6, message=FALSE, warning=FALSE, fig.cap= "The relationship (caption has parenthesis) and % symbols. \\label{graph}"}
## This is the Rmd chunk that has \textbackslash{} inserted into the .tex file and will not
# display figure captions correctly in the final .pdf
Part of my .tex file that shows \textbackslash{}
\textbackslash{}begin\{figure\}
\{\centering \includegraphics[width=0.7\linewidth]{Thesis_Results_files/figure-latex/graph-1}
\}
\textbackslash{}caption\{The relationship (caption has parenthesis) and % symbols.
\label{Corr_to_signal_95CI_graph}\}\label{fig:graph}
\textbackslash{}end\{figure\}