Open sondalex opened 2 years ago
I don't get an error when I run your code, but I also don't get the histogram in the output. If you're still interested in this, could you check whether things are fixed, or broken in a different way?
Hi sure, I will try again. I will keep you updated.
The temporary tex file is saved at book/example.tex
. The line which stops pdflatex conversion is the following:
book/example.tex
141:4 & & \includegraphics[width=0.67in, height=0.17in]{example_files/figure-latex//hist_102501edb50b6.pdf} & & & & & \\
It would work if the generated tex was equal to:
book/example.tex
141:4 & & \includegraphics[width=0.67in, height=0.17in]{../example_files/figure-latex//hist_102501edb50b6.pdf} & & & & \\
Unfortunately, knitr
calls pdflatex
from the book
directory and not from the project root. Therefore, first example fails.
Describe the bug kableExtra plots do not work when knitting from different directory than the main
.Rmd
file and usingroot.dir
option inknitr::opts_knit$set
To Reproduce
Assume the following project structure:
An error will occur when converting the created tex document to to pdf:
Current implementation
Currently, the default directory is set with respect to the
<working directory>/figure-latex
:https://github.com/haozhu233/kableExtra/blob/292f60715959ea952ff25a8aedfd782793b15f7b/R/mini_plots.R#L295-L302
Beginning of Solution
One not optimal solution would be to use absolute paths
fig_dir_name
change:has the advantage of inheriting knitr defaults.
A better solution, would be to use relative paths, however the function(s) writing the tex
\includegraphics
paths statement would have to take care of trimming the base directory (book/
in this example) because pandoc path resolving is relative to the base directory and notroot.dir
.Notes
In order to simplify reproduction, I made the example available in a GitHub repo.
To clone it: