0

From Zarko's solution here: How to draw this TikZ figure?, why isnt this code working?

\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$" (C) edgebend left,"$\eta$" (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}

I get the following error:

! Missing \endcsname inserted.
<to be read again> 
                   \begingroup 
l.2959      (A.260) edge ["$\rho S$" '] (D.100)

?

EDIT:

A similar code earlier in my document works:

\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}

I don't know why this one in particular is causing issues..

EDIT 2:

My preamble(well it was a template given, I know its very old!) is causing the error as it was working before adding my preamble. Any fixes to the preamble are welcome are welcome.

\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}}

Math
  • 765
  • Does the example raise the error? I don't think so. – egreg Jun 27 '22 at 14:06
  • @egreg the edit I provided, it doesn't raise an error. – Math Jun 27 '22 at 14:33
  • @egreg Trying the main code on a fresh file, it works without any issues, do you know why it isn't working on my main document? Shall I add in my preamble? – Math Jun 27 '22 at 14:36
  • Try and add what makes the error. Copy the whole document in a fresh document and just keep the preamble and the diagram. If no error appears, then you know it's something between \begin{document} and the picture (which is unlikely). Otherwise, try and comment out parts of the preamble until you arrive to a minimal set that raises the error. – egreg Jun 27 '22 at 14:53
  • The error occurs with just the preamble and diagram. – Math Jun 27 '22 at 14:55

2 Answers2

2

You should really prune that preamble and use correct ordering. Anyway, the error is due to a missing TikZ library, namely babel (the error is triggered by csquotes).

\usetikzlibrary{babel,arrows.meta, positioning, quotes}
egreg
  • 1,121,712
0

Copying your code and running it in MikTex via LuaLatex results in this image; same with pdflatex:

enter image description here

More investigations: Running TeXworks

  • pdfTex: fails
  • pdfLatex: "undefined control sequence \documentclass ..."
  • pdfLatex+MakeIndex+BibTex: OK (i.e. draws the image)
  • LuaTex: doesn't know Tikz at all etc.
  • LuaLatex: OK
  • LuaLatex+MakeIndex+BibTex: seems to be OK
  • XeTex: "undefined control sequence \documentclass ..."
  • XeLatex: misses a package

ok, just to give you an impression.

MS-SPO
  • 11,519