r - Tikzpictures 不在 gitbook 中呈现,即使它们出现在 pdf_book 中
问题描述
我过去bookdown
常常从我的一些数学课程中输入我的笔记。我想将 tikzpictures 插入到我的书中,即使它们在使用时呈现完美render_book("index.Rmd", "pdf_book")
,但在我使用render_book("index.Rmd", "gitbook")
. 同样在使用preview_chapter
而不是render_book
.
这是可用于渲染我的 Tikz 图像的代码:
\def\firstcircle{(0:-0.5cm) circle (1.5cm)}
\def\secondcircle{(0:0.4cm) circle (0.5cm)}
\colorlet{circle edge}{blue!50}
\colorlet{circle area}{blue!20}
\tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
outline/.style={draw=circle edge, thick}}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{scope}
\clip \firstcircle;
\secondcircle;
\end{scope}
\draw[outline] \firstcircle node {$B$};
\draw[outline] \secondcircle node {$A$};
\end{tikzpicture}
\caption{$A$ as a subset of $B$}
\end{figure}
我用pdf_book
的时候很漂亮。如果我使用gitbook
它就不会出现。我试图做一些与这里问题中描述的类似的事情,即使用相同的块但用我的代码替换该代码(尽管我做了中心我的),如下所示:
```{r, echo=FALSE, engine='tikz', out.width='90%', fig.ext='pdf', fig.align='center', fig.cap='Some caption.'}
\def\firstcircle{(0:-0.5cm) circle (1.5cm)}
\def\secondcircle{(0:0.4cm) circle (0.5cm)}
\colorlet{circle edge}{blue!50}
\colorlet{circle area}{blue!20}
\tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
outline/.style={draw=circle edge, thick}}
\begin{tikzpicture}
\begin{scope}
\clip \firstcircle;
\secondcircle;
\end{scope}
\draw[outline] \firstcircle node {$B$};
\draw[outline] \secondcircle node {$A$};
\end{tikzpicture}
```
当我这样做时,它再次呈现精美,pdfbook
实际上我更进一步gitbook
(出现图形标题并出现“损坏的图像链接”符号,如前所述,我已经尝试跨浏览器)但仍然没有图像。
关于如何让它发挥作用的任何想法?
解决方案
fig.ext='pdf'
您正在创建一个 PDF 文件,您的浏览器无法包含该文件。相反,您可以将fig.ext=if(knitr:::is_latex_output()) 'pdf' else 'png'
PDF 输出与 LaTeX 和 PNG 输出一起用于所有其他情况。或者,您可以完全删除fig.ext
并使用默认值。鉴于其中一项更改,您的示例适用于 HTML/Gitbook 和 PDF/LaTeX 输出。
推荐阅读
- amazon-web-services - 如何通过 Drush 链接到托管在 AWS 上的 Drupal 站点
- docker - 在 Nvidia Docker 中部署 Windows 应用程序
- asp.net-core - AspnetBoilerplate LazyLoading 不起作用
- symfony - 什么是 zend-expressive symfony 控制台命令的容器
- javascript - htm 文件未在 Angular JS 路由中加载
- reactjs - 边缘侧包括自闭合标签
- c# - 在 wpf xaml 中格式化为没有尾随零的货币
- excel - 使用VBA在Excel中的文本到列
- c - &address + sizeof(type) 和 &address + 1 有什么区别?
- javascript - 使用 Mocha 和 Chai 断言包含在 Javascript 数组中的值