如何阻止相同的数字出现在我的 rmarkdown 文档中

问题描述 投票:0回答:1

我使用不同类型的命令生成了几个图形,例如 tikz、rmarkdown chunck、ggplot2,如下所示。不幸的是,它们都是用与“图 1”相同的图号生成的。你对解决这个问题有什么建议吗? 在下文中,我生成了一个可重现的示例。请参考以下代码供您参考。

---
title: "demo" 
author: 
output: 
  pdf_document:
    number_sections: true
link-citations: yes
toc: false
bibliography: /Users/references02.bib
biblio-style: apalike    
in_header: preamble.tex
keep_tex: yes
fontsize: 12pt
linestretch: 1.2
subparagraph: true
number_sections: true
geometry: margin=1in
header-includes:
- \usepackage{amsmath}
- \usepackage{amsthm}
- \usepackage{bbm}
- \numberwithin{equation}{section}
- \usepackage{makecell}
- \usepackage{indentfirst}
- \usepackage{geometry}
- \usepackage{graphicx}
- \usepackage{tikz}
---

```{r fig.align="center", fig.cap="\\label{fig:figure1} figure 1 "}
library(datasets)
library(tseries)
data("AirPassengers")
passengers <- AirPassengers
plot(passengers, main = "Monthly Air Passenger Traffic")
```

\begin{figure}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt        
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=0.32 ] (66.5,28.97) -- (248.5,28.97) -- (248.5,137) -- (66.5,137) -- cycle ;
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=0.25 ] (62.5,265.61) -- (250.25,265.61) -- (250.25,356.79) -- (62.5,356.79) -- cycle ; 
\end{tikzpicture}
\caption{\footnotesize Flow Diagram 1}
\label{fig:figure2}
\end{figure}

\begin{figure}
\tikzset{every picture/.style={line width=0.75pt}} 
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=0.32 ] (66.5,28.97) -- (248.5,28.97) -- (248.5,137) -- (66.5,137) -- cycle ;
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=0.25 ] (62.5,265.61) -- (250.25,265.61) -- (250.25,356.79) -- (62.5,356.79) -- cycle ;
\end{tikzpicture}
\caption{\footnotesize Flow Diagram2}
\label{fig:figure3}
\end{figure}

```{r fig.align="center", fig.cap="\\label{fig:figure4}Trends", warning=FALSE, echo=FALSE, message=FALSE}
library(ggplot2)
library(iris)
qplot(Sepal.Length, data = iris, size = Petal.Width)
```

Look at \cref{fig:figuare1}, \cref{fig:figure2}, \cref{fig:figure3} and \cref{fig:figure4}.

ggplot2 r-markdown figure tikz
1个回答
0
投票

---
title: "demo" 
author: 
output: 
  pdf_document:
    number_sections: true
link-citations: yes
toc: false
biblio-style: apalike    
in_header: preamble.tex
keep_tex: yes
fontsize: 12pt
linestretch: 1.2
subparagraph: true
number_sections: true
geometry: margin=1in
header-includes:
- \usepackage{amsmath}
- \usepackage{amsthm}
- \usepackage{bbm}
- \numberwithin{equation}{section}
- \usepackage{makecell}
- \usepackage{indentfirst}
- \usepackage{geometry}
- \usepackage{graphicx}
- \usepackage{tikz}
- \AtEndPreamble{\usepackage{cleveref}}
---

```{r fig.align="center", fig.cap="\\label{fig:figure1} figure 1 "}
library(datasets)
library(tseries)
data("AirPassengers")
passengers <- AirPassengers
plot(passengers, main = "Monthly Air Passenger Traffic")
```

\begin{figure}
\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt        
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=0.32 ] (66.5,28.97) -- (248.5,28.97) -- (248.5,137) -- (66.5,137) -- cycle ;
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=0.25 ] (62.5,265.61) -- (250.25,265.61) -- (250.25,356.79) -- (62.5,356.79) -- cycle ; 
\end{tikzpicture}
\caption{\footnotesize Flow Diagram 1}
\label{fig:figure2}
\end{figure}

\begin{figure}
\tikzset{every picture/.style={line width=0.75pt}} 
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=0.32 ] (66.5,28.97) -- (248.5,28.97) -- (248.5,137) -- (66.5,137) -- cycle ;
\draw  [fill={rgb, 255:red, 0; green, 0; blue, 0 }  ,fill opacity=0.25 ] (62.5,265.61) -- (250.25,265.61) -- (250.25,356.79) -- (62.5,356.79) -- cycle ;
\end{tikzpicture}
\caption{\footnotesize Flow Diagram2}
\label{fig:figure3}
\end{figure}

```{r fig.align="center", fig.cap="\\label{fig:figure4}Trends", warning=FALSE, echo=FALSE, message=FALSE}
library(ggplot2)

qplot(Sepal.Length, data = iris, size = Petal.Width)
```

Look at \cref{fig:figure1}, \cref{fig:figure2}, \cref{fig:figure3} and \cref{fig:figure4}.

© www.soinside.com 2019 - 2024. All rights reserved.