来自 Zarko 的解决方案:如何绘制这个 TikZ 图形?,为什么这段代码不起作用?
\documentclass[12pt, a4paper]{report}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning, quotes}
\begin{document}
\begin{figure} \centering
\begin{tikzpicture}[
node distance = 33mm and 33mm,
N/.style = {draw, minimum size=12mm, inner sep=0pt},
> = Stealth,
every edge/.append style = {draw, ->},
every edge quotes/.append style = {font=\small\linespread{0.75}\selectfont,
inner sep=5pt}
]
\node [N] (A) {$S$};
\node [N,right=of A] (B) {$A$};
\node [N,below=of B] (C) {$I$};
\node [N, left=of C] (D) {$R$};
%
\draw [<-] (A) -- ++(-1,0) node[left] {$b\left(1-\nu\right)$};
\draw [<-] (D) -- ++(-1,0) node[left] {$b\nu$};
\draw [->] (A) -- ++( 0,1) node[above] {$\mu S$};
\draw [->] (B) -- ++( 0,1) node[above] {$\mu A$};
\draw [->] ([xshift=-3.5mm] C.south) -- ++(0,-0.4) node[below] {$\alpha I$};
\draw [->] ([xshift=+3.5mm] C.south) -- ++(0,-0.4) node[below] {$\mu I$};
\draw [->] (D) -- ++(0,-1) node[below] {$\mu R$};
%
\draw
(A.260) edge ["$\rho S$" '] (D.100)
(A) edge ["$(\beta_A A+\beta_I I)S$"] (B)
(B) edge ["$\delta$" '] (C)
(B) edge["$\sigma A$"] (D)
(C) edge["$\gamma_I$"](D)
(C) edge[bend left,"$\eta$"](D)
(D.80) edge ["$\xi R$" '] (A.280)
;
\end{tikzpicture}
% \setlength{\textfloatsep}{10pt plus 1.0pt minus 2.0pt} % is really needed?
\caption{Flow diagram for the SAIRS model.}
\end{figure}
\end{document}
我收到以下错误:
! Missing \endcsname inserted.
<to be read again>
\begingroup
l.2959 (A.260) edge ["$\rho S$" '] (D.100)
?
编辑:
我的文档中早些时候提到过类似的代码:
\begin{figure} \centering
\begin{tikzpicture}[
node distance = 11mm and 33mm,
N/.style = {draw, minimum size=12mm, inner sep=0pt},
> = {Stealth[scale=0.6]},
every edge/.append style = {draw, ->},
every edge quotes/.append style = {font=\small\linespread{0.75}\selectfont,
inner sep=5pt, sloped}
]
\node [N] (A) {$S$};
\node [N,above right=of A] (B) {$I_1$};
\node [N,below right=of A] (C) {$I_2$};
\node [N,above right=of C] (D) {$J$};
\node [N,right=of D] (E) {$A$};
%
\draw [<-] (A) -- ++(-1,0) node[left] {$\mu$};
\draw [->] (A) -- ++(0,-1) node[below] {$\nu S$};
\draw [->] ([xshift=3.75mm] B.south) -- ++(0,-0.4) node[below] {$\nu I_1$};
\draw [->] (C) -- ++(0,-1) node[below] {$\nu I_2$};
\draw [->] (D) -- ++(0,-1) node[below] {$\nu J$};
\draw [->] ([xshift=-3.5mm] E.south) -- ++(0,-0.4) node[below] {$\alpha A$};
\draw [->] ([xshift=+3.5mm] E.south) -- ++(0,-0.4) node[below] {$\nu A$};
%
\draw ([yshift=+1mm] A.east)
edge [ultra thick, draw=gray,"\slash\slash\slash" anchor=center,
"$\begin{gathered}
p\beta_1 S I_2\\
q\beta_2 S J\\
r\beta_3 S A
\end{gathered}$" ] (B.west)
([yshift=-1mm] A.east)
edge [ultra thick, draw=gray,"\slash\slash\slash" anchor=center,
"$\begin{gathered}
(1-p)\beta_2 S I_2\\
(1-q)\beta_2 S J\\
(1-r)\beta_3 S A
\end{gathered}$" '] (C.west)
(B) edge [rotate=90,"$\epsilon I_1$"] (C)
(D.west) edge ["$\xi_1 J$" ] ( B.east)
( C.east) edge ["$p_1 I_2$" ] (D.west)
([yshift=-2mm] D.west) edge ["$\xi_2 J$" '] ([yshift=-2mm] C.east)
(D) edge ["$p_2 J$"] (E);
\end{tikzpicture}
\setlength{\textfloatsep}{10pt plus 1.0pt minus 2.0pt}
\caption{Flow diagram for the HIV/AIDS model.}
\end{figure}
我不知道为什么这一点尤其会引起问题。
编辑2:
我的序言(好吧,这是一个模板,我知道它很旧了!)导致错误,因为它在添加我的序言之前就可以正常工作。欢迎对序言进行任何修复。
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{bm}
\usepackage{nccmath}
\usepackage{amsfonts, graphicx, verbatim, mathtools,amssymb, amsthm, mathrsfs,amsmath}
\usepackage{color}
\usepackage{array}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage{rsfso}
\usepackage{enumitem}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning, quotes}
\usepackage{parskip}
\usepackage{lipsum}
\usepackage{floatrow}
\usepackage{epstopdf}
\usepackage[capitalise]{cleveref}
\usepackage{siunitx}
\usepackage{tocloft}
\usepackage{listings}
\usepackage{booktabs}
\usepackage{nicematrix}
\usepackage{subcaption}
\usepackage{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage[thinc]{esdiff}
\usepackage [english]{babel}
\usepackage [autostyle, english = american]{csquotes}
\usepackage[style=numeric,maxbibnames=99,sortcites=true,backend=bibtex]{biblatex}
\allowdisplaybreaks
\setlength\bibitemsep{0.5\baselineskip}
\addbibresource{biblio.bib}
\MakeOuterQuote{"}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclareMathOperator{\Tr}{Tr}
\providecommand{\U}[1]{\protect\rule{.1in}{.1in}}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{acknowledgement}[theorem]{Acknowledgement}
\newtheorem{algorithm}[theorem]{Algorithm}
\newtheorem{axiom}[theorem]{Axiom}
\newtheorem{case}[theorem]{Case}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{Theorem}[theorem]{Theorem}
\newtheorem{conclusion}[theorem]{Conclusion}
\newtheorem{condition}[theorem]{Condition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{Fact}[theorem]{Fact}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{criterion}[theorem]{Criterion}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{exercise}[theorem]{Exercise}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{fact}[theorem]{Fact}
\newtheorem{lma}[theorem]{Lemma}
\newtheorem{notation}[theorem]{Notation}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{Property}[theorem]{Property}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{Comment}[theorem]{Comment}
\newtheorem{solution}[theorem]{Solution}
\newtheorem{summary}[theorem]{Summary}
\newcommand{\ve}{\varepsilon}
\newcommand{\cvgpr}{\xrightarrow{\text{\upshape\tiny P}}}
\newcommand{\cvgdist}{\xrightarrow{\mathrm{d}}}
\newcommand{\G}{{\mathcal{G}}}
\newcommand{\ls}{\limsup_{n\to\infty}}
\newcommand{\rE}{\mathbb{E}}
\newcommand{\A}{{\mathcal{A}}}
\newcommand{\rP}{\mathbb{P}}
\newcommand{\p}{{\mathbb{P}}}
\newcommand{\Z}{{\mathbb{Z}}}
\newcommand{\re}{\mathrm{e}}
\newcommand{\ep}{\varepsilon}
\newcommand{\qand}{\quad\mbox{and}\quad}
\newcommand{\quso}{\quad\mbox{so}\quad}
\newcommand{\Ups}{{\Upsilon}}
\newcommand{\iu}{{i\mkern1mu}}
\newcommand{\II}{{\mathcal{I}}}
\newcommand{\ra}{\rightarrow}
\newcommand{\I}{{\mathbf 1}}
\newcommand{\R}{{\mathbb R}}
\newcommand{\N}{{\mathbb N}}
\newcommand{\LL}{{\mathbb L}}
\newcommand{\E}{{\mathbb{E}}}
\newcommand{\ri}{\mathrm{i}}
\newcommand{\rd}{\mathrm{d}}
\newcommand{\XXi}{\Xi_{k,m}^{(n)}}
\newcommand{\xxi}{\bar{\xi}}
\newcommand{\eqdef}{\stackrel{\mathrm{def}}{=}}
\newcommand{\eqdist}{\stackrel{\mathrm{D}}{=}}
\newcommand{\braket}[2]{{\langle{#1|#2}\rangle}}
\newcommand{\independent}{\perp}
\newcommand{\F}{{\mathcal{F}}}
\newcommand{\cross}{\mathbin{\tikz [x=1.4ex,y=1.4ex,line width=.075ex] \draw (0,0) -- (1,1) (0,1) -- (1,0);}}%
\newcommand\widebar[1]{\mathop{\overline{#1}}}
\def\Plus{\texttt{+}}
\setlength{\textfloatsep}{10pt plus 1.0pt minus 2.0pt}
\crefdefaultlabelformat{\textbf{#2#1#3}}
\crefname{figure}{\textbf{Fig.}}{\textbf{Figures}}
答案1
你确实应该删减那个前言,并使用正确的顺序。无论如何,错误是由于缺少 Ti钾Z 库,即babel
(该错误是由 触发的csquotes
)。
\usetikzlibrary{babel,arrows.meta, positioning, quotes}