image - 在knitr中插入外部图像
问题描述
问题描述
我在 Overleaf 环境中使用 knitr 并希望包含外部保存的图像。
以前的尝试
编辑:目前所有尝试都给出编译错误和紧急停止:'<*> main.tex ***(作业中止,文件处于不间断模式)'。所以我怀疑代码中存在一般问题,但我无法发现它。
这是我已经尝试过的:
- 将图像上传到 Overleaf 并使用默认值在 knitr 块之外调用它:
\begin{figure}[htbp]
\includegraphics{image.png}
\end{figure}
- 受这篇文章的启发,将图像保存在 knitr 块内的变量中,并包括块外的图形:
<<fig1,fig=TRUE>>=
f='path/to/image.png'
@
\includegraphics{\Sexpr{f}}
- 我还尝试了基于this和this post 的语法,但没有成功。
下载到图片:RPBU 2011 6 最高峰 1 和 2
最小工作示例(MWE):
请注意,除第一次之外的其他尝试需要先取消注释。
\documentclass{article}
\begin{document}
<<standardsettings,echo=FALSE,results='hide'>>=
%%begin novalidate
library(knitr)
opts_chunk$set(echo=FALSE,fig.width=10,fig.height=5,fig.align='center')
@
%%end novalidate
%First try: Uploading to overleaf and calling outside knitr chunk:
\begin{figure}[htbp]
\includegraphics[width=\linewidth]{RPBU11hp12.png}
\end{figure}
%Second try: Saving image in variable inside knitr chunk and including graphic outside chunk
%<<fig:6highpeaks2018, fig = TRUE>>=
%RPBU11hp1&2 = 'C:/Documents/Uni/5.Jaar 5 (Bachelor)/Kwartiel 3/BEP/Plots/RPBU11hp12.png'
%@
%\begin{figure}[htbp]
%\includegraphics[width=\linewidth]{\Sexpr{RPBU11hp1&2}}
%\end{figure}
%Third try: Directly including the image inside the chunk
% %%begin novalidate
%<<fig:highpeaks2018, fig = TRUE>>=
%knitr::include_graphics(path = %"C:/Documents/Uni/5.Jaar 5 (Bachelor)/Kwartiel 3/BEP/Plots/RPBU11hp12.png")
%@
% %%end novalidate
%Fourth try: Other method of directly including the image inside the chunk
%<<fig:6highpeaks2018, fig = TRUE>>=
%<img src="C:/Documents/Uni/5.Jaar 5 (Bachelor)/Kwartiel 3/BEP/Plots/RPBU11hp12.png" width="50%"/>
%@
\end{document}
解决方案
解决方案很简单:第一个解决方案,将其上传到背页并在默认情况下在 knitr 块之外调用它
\begin{figure}[htbp]
\includegraphics[width=\linewidth]{name_image.png}
\end{figure}
作品。
推荐阅读
- r - 我应该怎么做才能绘制图片
- php - Yii2 Pjax分页在多个Gridview上不起作用
- s4sdk - 如何使用 RfcQuery 从 ABAP 中检索 xstring 值?
- python-3.x - pylint 误报 E0401 在使用 venv 时在 vscode 中导入错误
- xcode - 如何在swift 4中应用卡片视图cornerRadius和阴影,如iOS appstore
- ms-access - 用于添加记录并随后专门查看/编辑该记录的按钮
- javascript - 反应 Js 代理不工作
- android - 将数据更改通知给 viewPagerAdapter
- javascript - 点击重置按钮后如何删除Cookie?
- c# - C#中的动态方法返回类型