Search code examples
pdflatexknitrsuffix

The fig file was inculded in function include_graphics(), could lost file extension when rmd to pdf/tex


I get a problem when I use knit to convert rmd to pdf, as follow:

rcode in my .rmd like this:


knitr::include_graphics('image/xyzAnovaFig.svg')

The result of rmd->tex/pdf is:

\begin{figure}

{\centering \includegraphics[width=0.7\linewidth]{image/xyzAnovaFig} 

}

\caption{MSb,MSw Example}\label{fig:xyzanova1}
\end{figure}

As you can see, the suffix of the picture will be lost, causing the picture not to be displayed in the pdf and compilation errors.

How can i fix it? Please.


Solution

  • The lost suffix will NOT cause errors and is NOT responsible for the image not being displayed in the pdf. You shouldn't use a suffix in \includegraphics{...}. Latex will automatically find the file type best suited for the engine you use.

    However svg is not supported. If you want to include an svg image, you need special packages like the svg package and then use

    \includesvg{⟨filename⟩}
    

    (note that this needs to be compiled with shell escape enabled and inkscape has to be installed)


    Personally I would use inkscape to convert svg files to pdf and then include the pdf files in the document.