我正在尝试将 tikz 图片添加到 Quarto 文档中。我可以成功地做到这一点,但是当我尝试添加交叉引用时它失败了。这必须编织成 PDF 而不是 HTML。
这是一个没有交叉引用的工作图。如果您有任何建议,请告诉我!
---
title: "Testing"
format: pdf
editor: visual
---
See @fig-my-figure for example.
```{r, engine = 'tikz'}
#| echo: false
#| fig.align: center
#|
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.pathreplacing}
\begin{tikzpicture}
\draw (0,0)node(a){} -- (10,0) node (b) {} ;
\foreach \x in {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} % edit here for the vertical lines
\draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt);
\foreach \x in {0, 0.2, 0.4, 0.6, 0.8, 1} % edit here for the numbers
\draw[shift={(\x*10,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below]
{$\x$};
\node at (8, 0.5) (eq1) {$\textcolor{red}{\boldsymbol{SQ}}$};
\node at (4, 0.5) (eq2) {$\textcolor{purple}{\boldsymbol{G_i(0)}}$};
\node at (7, 0.5) (eq2) {$\textcolor{purple}{\boldsymbol{G_i(1)}}$};
\node at (3, 0.5) (eq3) {$\textcolor{blue}{\boldsymbol{P}}$};
\node at (0, 0.5) (eq4) {$\textcolor{black}{\boldsymbol{x_i}}$};
\draw[decorate, decoration={brace, amplitude=6pt, mirror},] ([yshift=0.5cm]4,0.5)-- node[above=0.25cm]
{\shortstack{Text}}([yshift=0.5cm]3,0.5);
\draw[decorate, decoration={brace, amplitude=6pt},] ([yshift=-1cm]7,0)-- node[below=0.25cm]
{\shortstack{Text}}([yshift=-1cm]3,0);
\end{tikzpicture}
```
为了从代码块中进行图形交叉引用,您需要提供两件事,(i)
label
和 (ii) fig-cap
.
label
是您的交叉引用标识符,对于图形,它必须以 fig-
为前缀,例如,fig-my-figure
。 fig-cap
只是您的图片标题,如果您不提供图片标题,交叉引用也将不起作用。所以你需要他们两个。我建议阅读文档.
---
title: "Testing"
format: pdf
---
See @fig-my-figure for example.
```{r, engine = 'tikz'}
#| label: fig-my-figure
#| echo: false
#| fig-align: center
#| fig-cap: "Some Caption"
\usetikzlibrary{arrows}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.pathreplacing}
\begin{tikzpicture}
\draw (0,0)node(a){} -- (10,0) node (b) {} ;
\foreach \x in {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} % edit here for the vertical lines
\draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt);
\foreach \x in {0, 0.2, 0.4, 0.6, 0.8, 1} % edit here for the numbers
\draw[shift={(\x*10,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below]
{$\x$};
\node at (8, 0.5) (eq1) {$\textcolor{red}{\boldsymbol{SQ}}$};
\node at (4, 0.5) (eq2) {$\textcolor{purple}{\boldsymbol{G_i(0)}}$};
\node at (7, 0.5) (eq2) {$\textcolor{purple}{\boldsymbol{G_i(1)}}$};
\node at (3, 0.5) (eq3) {$\textcolor{blue}{\boldsymbol{P}}$};
\node at (0, 0.5) (eq4) {$\textcolor{black}{\boldsymbol{x_i}}$};
\draw[decorate, decoration={brace, amplitude=6pt, mirror},] ([yshift=0.5cm]4,0.5)-- node[above=0.25cm]
{\shortstack{Text}}([yshift=0.5cm]3,0.5);
\draw[decorate, decoration={brace, amplitude=6pt},] ([yshift=-1cm]7,0)-- node[below=0.25cm]
{\shortstack{Text}}([yshift=-1cm]3,0);
\end{tikzpicture}
```