knitrを使用して.pdfに変換する.rmdファイルを作成しています。私のマークダウンファイルには、一連の古典的なRプロットがチャンクで生成されていて、そのために番号が付けられ、knitrによってキャプションが付けられています。knitrを使用したRマークダウンのLaTeX図のキャプション
ここでは、私のRプロットを表示する前に、LaTeXで生成された単純な因果図を追加してキャプションを付けたいと思います。私のLaTeXダイアグラムを他のRプロットと同じ順序で数字にするにはどうすればいいですか?私のLaTeXフィギュアにキャプションを追加するのはどうですか?
説明するために私rmarkdownドキュメントの簡単な例:つまり
---
title: "Figure captions"
output:
pdf_document:
fig_caption: yes
number_sections: yes
header-includes:
- \usepackage{tikz}
- \usetikzlibrary{arrows, shapes, positioning, calc}
---
# A simple LaTeX diagram with no caption
This LaTeX diagram should register as 'Figure 1':
\tikzset{line/.style = {draw, -latex},
cloud/.style = {draw, ellipse, node distance=3cm,
minimum height=2em}
}
\begin{tikzpicture}[node distance = 6cm, auto]
\node [cloud] (init) {Z1};
\node [cloud, below left = 2 of init] (X1) {X1};
\node [cloud, below right = 2 of init] (Y1) {Y1};
\node [cloud, below = of init] (Z2) {Z2};
\path [line] (X1) -- (Y1);
\path [line] (init) -- ($(X1)!0.5!(Y1)$);
\path [line] (Z2) -- ($(X1)!0.5!(Y1)$);
\end{tikzpicture}
# A simple R plot with a caption
Here is a generic R plot that should be 'Figure 2', but is generated as 'Figure 1':
```{r figure2, echo=FALSE, fig.cap="This should be called Figure 2"}
library(ggplot2)
qplot(mpg, wt, data = mtcars)
```
を、私は私の中で生成されたプロットと同等のプロットとしての私のLaTeXの図を認識knitr持つ方法を探していますコードチャンクなので、シーケンス内の別の数字として数えることができます。これどうやってするの?
シンプルなLaTeXキャプションを使ってフィギュア環境でtikzコードをラップして問題を解決しました。ありがとう! – ageil
これ以上のものがある場合は、それらを別々にPDFにレンダリング( '\ documentclass {standalone}')し、Figure環境内で '\ includegraphics {}'を使用することもできます – user101089