Tikz 代码不再运行

Tikz 代码不再运行

这个问题源于马尔可夫链箭头和标签堆叠在一起我得到了 2 个不同的解决方案,一个是 @Zarko 提供的,我接受了这个答案,另一个是 @Sandy G 提供的。但是,在合并到我的主文档之前,这两个解决方案都运行正常,没有任何错误。但是,在合并到我的主文档之后,我开始收到类似的错误Undefined control sequence. ... left, looseness=12, "$1-\theta$" '] (A)Incomplete \iffalse; all text was ignored after line 145.我不明白问题出在哪里,因为代码在我的文档之外运行良好。任何帮助都将不胜感激。以下是我的主要文档代码:


\documentclass[12pt,openany,twoside]{book}
\raggedbottom
\let\cleardoublepage=\clearpage
\usepackage[
a4paper,
left=1in,
right=1in, 
top=1in, 
bottom=1in
]{geometry}

\usepackage[dvipsnames,table]{xcolor}

\usepackage{graphicx}
\newcommand\HRule{\noindent\rule{\linewidth}{1.5pt}}


\usepackage{fancyhdr}
\usepackage{hhline}



\usepackage[marginal]{footmisc}
\renewcommand\footnoterule{\vspace*{-3pt}%
    \hrule width 2in height 1.4pt \vspace*{2.6pt}}
\setlength\footnotemargin{10pt}

\usepackage{titletoc}%this is an option [dotinlabels]
\usepackage[noindentafter,calcwidth]{titlesec}



\usepackage{tikz}
\usetikzlibrary{ shapes.geometric }
\usetikzlibrary{calc}

\usetikzlibrary{arrows.meta, automata,
    bbox,
    chains, 
    positioning,
    quotes}

\usepackage{float}
\usepackage{longtable}
\usepackage{multirow}
\usepackage[ragged]{sidecap}
\usepackage{caption}

\usepackage[font=small,format=hang,skip=5pt,textfont=it]{caption}



%% This code creates the groups
% -----------------------------------------
\usepackage{etoolbox}

\usepackage{regexpatch}
\usepackage{listings}


\usepackage[numbered, framed]{matlab-prettifier}
\let\ph\mlplaceholder % shorter macro
\lstMakeShortInline"
\makeatother

\makeatletter
% --------------------------------------- Matlab Output
\newcommand{\lstlistmatlaboutputname}{List of }
\newcounter{matlaboutput}
\lstnewenvironment{matlaboutput}[1][]{%
    \renewcommand{\lstlistingname}{Output}%
    \renewcommand{\ext@lstlisting}{loo}%
    %\xpatchcmd*{\caption@ORI@lst@MakeCaption}{lol}{lor}{}{}% use this with earlier version caption package
    \setcounter{lstlisting}{\value{matlaboutput}}
    \lstset{
        language =Matlab,       
        style              = Matlab-editor,
        basicstyle         = \ttfamily\footnotesize,
,#1}}
{}

% --------------------------------------- Matlab Code
\newcommand{\lstlistmatlabcodename}{List of Codes}
\newcounter{matlabcode}
\lstnewenvironment{matlabcode}[1][]{%
    \renewcommand{\lstlistingname}{Code}%
    \renewcommand{\ext@lstlisting}{loc}%
    %\xpatchcmd*{\caption@ORI@lst@MakeCaption}{lol}{lop}{}{}% use this with earlier version caption package
    \setcounter{lstlisting}{\value{matlabcode}}
    \lstset{
        language =Matlab,       
        style              = Matlab-editor,
        basicstyle         = \ttfamily\footnotesize,
    ,#1}}
{}

% --------------------------------------- Pseudocode
\newcommand{\lstlistpseudocodename}{List of Pseudocode}
\lstnewenvironment{pseudocode}[1][]{%
    \renewcommand{\lstlistingname}{Pseudocode}%
    \renewcommand{\ext@lstlisting}{lop}%
    %\xpatchcmd*{\caption@ORI@lst@MakeCaption}{lol}{lor}{}{}% use this with earlier version caption package
    \lstset{basicstyle=\ttfamily,#1}}
{}

\newcommand{\lstlistofmatlaboutput}{\begingroup
    \tocfile{\lstlistmatlaboutputname}{loo}
    \endgroup}
\newcommand{\lstlistofmatlabcode}{\begingroup
    \tocfile{\lstlistmatlabcodename}{loc}
    \endgroup}
\newcommand{\lstlistofpseudocode}{\begingroup
    \tocfile{\lstlistpseudocodename}{lop}
    \endgroup}

\makeatother




\begin{document} 
    \sloppy
    
    \chapter{Sample Tikz}
    
    
    %Markov chain:
    %\begin{center}
    \begin{tikzpicture}[auto=right, 
        bezier bounding box,
        node distance = 22mm,
        start chain = going right, 
        every edge/.style = {draw, -Stealth, semithick},
        every state/.style = {draw, thick, on chain}
        ]
        \begin{scope}[nodes=state]
            \node (A)   {$0$};
            \node (B)   {$1$};
            \node (C)   {$2$};
            \node (D)   {$3$};
            \coordinate (E);
        \end{scope}
        %
        \path   (A) edge[loop left, looseness=12,  "$1-\theta$" '] (A);
        \path[bend left, swap] 
        (A) edge["$\theta$"]    (B)
        (B) edge["$\theta$"]    (C)
        (C) edge["$\theta$"]    (D)
        (C) edge["$\theta$"]    (D)
        (D) edge[dashed, "$\theta$"]  (E);
        \path[out=210]
        (B) edge[in=-30, "$1-\theta$"]  (A)
        (C) edge[in=-45, "$1-\theta$"]  (A)      
        (D) edge[in=-60, "$1-\theta$"]  (A);
    \end{tikzpicture}
    %\end{center}
    
\end{document}

答案1

  • 在您的文档序言中,您有声明\lstMakeShortInline"(在包中定义listings),它改变了 Ti 的标准含义,"并且与 Ti 的语法发生冲突Z 库quotes
  • 作为解决方法,您可以通过使用包中定义的listings宏来限制此指令仅在环境中使用 :\AtBeginEnvironmentetoolbox
...
\usepackage{etoolbox}
\usepackage{listings}
\AtBeginEnvironment{listings}{\lstMakeShortInline"}
...
  • caption除此之外,清理代码中重复加载的包并删除单独的\makeatother指令也是很好的。

相关内容