我有简单的RMarkdown文档:
---
output:
word_document: default
html_document: default
---
```{r,engine='tikz', fig.ext = 'png'}
\begin{tikzpicture}
\path (0,0) node
(x) {Hello World!}
(3,1) node[circle,draw](y) {$\int_1^2 x \mathrm d x$};
\draw[->,blue]
(x) -- (y);
\draw[->,red]
(x) -| node[near start,below] {label} (y);
\draw[->,orange] (x) .. controls +(up:1cm) and +(left:1cm) .. node[above,sloped] {label} (y);
\end{tikzpicture}
```
Run Code Online (Sandbox Code Playgroud)
如果我'png'改为'svg':HTML输出很棒
它用tikz引擎产生圆形和矩形.
但是,即使使用100%缩放,生成的图像在DOCX中看起来也很难看并且像素化:

我试图改变fig.width,dpi,out.width但没有得到积极的结果.
对我来说最好的结果将是以下内容:获取具有TikZ代码中指定尺寸的高分辨率图像.
是否可以提高从TikZ插入Word文档的图像的分辨率?
更新1:@CL使用set pandoc dpi使用pandoc_args的建议解决方案不起作用.
更新2:@tarleb解决方案提议{r,engine='tikz', engine.opts …
下面是我的实验 RMarkdown 文档(名为tikz-cyrillic.Rmd):
---
title: "TikZ cyrillic test"
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
dev: tikz
html_document: default
word_document: default
---
```{r,engine='tikz', fig.ext = if (knitr:::is_latex_output()) 'pdf' else 'svg'}
\begin{tikzpicture}
\path (0,0) node
(x) {Hello World!}
(3,1) node[circle,draw](y) {$\int_1^2 x \mathrm d x$};
\draw[->,blue]
(x) -- (y);
\draw[->,red]
(x) -| node[near start,below] {???!} (y);
\draw[->,orange] (x) .. controls +(up:1cm) and +(left:1cm) .. node[above,sloped] {??????} (y);
\end{tikzpicture}
```
Run Code Online (Sandbox Code Playgroud)
它基于pgfmanual.pdf 的 17.11 中的示例。
Gummi 使用TeXLive 和 XeTeX …
Below is the simplest Rmd file which I'm knitting to MS Word document using latest RStudio:
---
output:
word_document: default
bookdown::word_document2: default
---
```{sh, echo=FALSE, comment=''}
cat ~/latex-test.Rmd
```
Run Code Online (Sandbox Code Playgroud)
The contents of ~/latex-test.Rmd are as follows:
Auto-numbered equation:
$$ f(x) = \sin(x) $$
---
LaTeX equation without label (using `\begin{equation}...\end{equation}`)
\begin{equation}
h(z) = \sinh(z)
\end{equation}
---
LaTeX equation with bookdown-supported label (using `\begin{equation}...(\#eq:label)\end{equation}`)
\begin{equation}
f\left(k\right) = \binom{n}{k} p^k\left(1-p\right)^{n-k}
(\#eq:binom)
\end{equation}
---
LaTeX equation with Xaringan-supported label (using `\begin{equation}...\label{label}\end{equation}`):
\begin{equation}
g\left(k\right) …Run Code Online (Sandbox Code Playgroud) 在我的程序中,我需要计算总和:
.
我计算这个总和与新值2500倍C和z.
参数z可以是矢量.我编写了简单的for循环和矢量化版本代码,如下所示:
K = 200;
n_z = 40000;
C = ones(K,1); % an example, in real life the arey some coefficients (at next call will be new)
k = 0:K-1;
z = linspace(0, 2*pi, n_z); % at next call will be new
tic;
my_sum_for = zeros(1, K);
for i=1:n_z
my_sum_for(i) = C' * tan(k' * z(i));
end
toc; % Elapsed time is 1.820485 seconds.
tic;
my_sum = C' * tan(k' * z); …Run Code Online (Sandbox Code Playgroud)