微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 pgfplots 中使用 include_tikz 时如何避免“!LaTeX 错误:环境轴未定义”?

如何解决在 pgfplots 中使用 include_tikz 时如何避免“!LaTeX 错误:环境轴未定义”?

我已经成功地在 R/exams .Rmd 文件中包含了几个在 TikZ 中制作的图形。当我尝试使用 pgfplotsinclude_tikz() 下包含绘图时,不会发生同样的情况。每当包含 \begin {axis}\end {axis} 时,请注意错误“!LaTeX 错误:环境轴未定义”。

在 RStudio 控制台中,图例出现:“这是 pdfTeX,版本 3.14159265-2.6-1.40.21(TeX Live 2020)(预加载格式 = pdflatex)受限 \ write18 enabled.entering extended mode”,即使在 TexStudio 中启用写-18。当我包含除 pgfplots 之外的其他 TikZ 图表时,这些消息都不会出现。

任何 TikZ 图形在 TexMaker 或 TexStudio 中运行时都可以工作,这表明它不是缺少 LaTeX 库或包的问题。

我包含了一部分改编自 https://www.latex4technics.com/?note=1HCT代码

```{r datos1,echo = FALSE,results = "hide"}

library(exams)
typ <- match_exams_device()

image01<-'
         \\begin{tikzpicture}
         \\begin{axis}[legend pos=south east]
         \\addlegendimage{empty legend}
         \\addplot {sqrt(x)}; 
         \\addplot {ln(x)}; 
         \\addlegendentry{\\hspace{-.6cm}\\textbf{A title}}
         \\addlegendentry{$\\sqrt{x}$}
         \\addlegendentry{$\\ln{x}$}
         \\end{axis}
         \\end{tikzpicture}
         '
```

```{r grafica01,results = "asis"}
include_tikz(image01,name = "grafiko1",markup = 
"markdown",format = typ,library = c("arrows"),packages = 
"booktabs",width = "7cm",header = "\\usepackage{/home/r- 
exams/Documentos/NuevoRStudio/Rmarkdowns/
esqueleto/exercises/schoice/ 
LaboratorioTikZ/3dplot}")
```

解决方法

答案就在您的问题标题中。您需要包含 pgfplots 包:

include_tikz(image01,packages = "pgfplots",...)

不需要您问题中调用的其他 packageslibraryheader 参数。

原因是,对于 include_tikz(),您只需在链接的完整 .tex 文件中使用 {tikzpicture} 代码:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
...
\end{tikzpicture}
\end{document}

注意第二行中的 \usepackge{pgfplots}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。