【问题标题】:Tikzpictures not rendering in gitbook, even though they appear in pdf_bookTikzpictures 不在 gitbook 中呈现,即使它们出现在 pdf_book 中
【发布时间】:2019-12-04 06:03:16
【问题描述】:

我正在使用bookdown 输入我的一些数学课程的笔记。我想将 tikzpictures 插入我的书中,即使它们在使用 render_book("index.Rmd", "pdf_book") 时呈现完美,但当我使用 @987654324 时,它们根本不会出现在任何浏览器上(我尝试过 Chrome、Firefox 甚至 Internet Explorer) @。同样,当使用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,它就不会出现。我试图做一些类似于这个问题here 中描述的事情,即使用相同的块,但用我的代码替换该代码(尽管我做了中心我的),如下所示:

```{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 中更进一步(出现图形标题并出现“损坏的图像链接”符号,我已经尝试跨浏览器,如上所述)但仍然没有图像。

关于如何让它发挥作用的任何想法?

【问题讨论】:

    标签: r latex knitr bookdown tikz


    【解决方案1】:

    使用fig.ext='pdf',您正在创建一个PDF 文件,您的浏览器无法包含该文件。相反,您可以使用 fig.ext=if(knitr:::is_latex_output()) 'pdf' else 'png' 之类的东西将 PDF 输出与 LaTeX 和 PNG 输出一起用于所有其他情况。或者,您可以完全删除 fig.ext 并使用默认值。鉴于其中一项更改,您的示例适用于 HTML/Gitbook 和 PDF/LaTeX 输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-06
      • 1970-01-01
      • 2016-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多