加载 groupplots 库时 Tikz 的自定义形状失败

加载 groupplots 库时 Tikz 的自定义形状失败

我正在使用book文档类来编写报告,其中我使用tikz名为的自定义形状绘制一些电路/块示意图dff我最初发现的这里然后稍微定制一下。

一切都运行正常,直到我将tikzgroupplots库(用于下面 MWE 中未显示的其他绘图)添加到我的序言中。然后,我的自定义形状无法再绘制,我得到的只是大量的“未定义的控制序列”和“Package PGF Math”错误,这些错误似乎与我的dff形状有关,但我无法理解。

下面的 MWE 显示了我用来精确定位冲突命令的完整前言;只需取消注释该行即可\usepgfplotslibrary{groupplots}看到它失败。任何关于如何解决这个问题的帮助或建议都将不胜感激。

\documentclass[a4paper]{book}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{float}
\usepackage{hyperref}
    \def\subfigureautorefname{Fig.}
    \def\figureautorefname{Fig.}
\usepackage{mathtools}
\usepackage{mathdots}
\usepackage{multirow}
\usepackage{placeins}
\usepackage{subfig}
\usepackage{xcolor}
%\usepackage{tikz}

\usepackage[pdftex]{graphicx}
    \graphicspath{{./img/}}
    \DeclareGraphicsExtensions{.pdf}

\usepackage[capitalise,noabbrev]{cleveref}
    \creflabelformat{equation}{#2#1#3}
\usepackage{siunitx}
    \sisetup{exponent-product=\cdot,detect-all}

\usepackage{pgfplots, tikz-3dplot}
\usepgfplotslibrary{external}
%\usepgfplotslibrary{groupplots}
\tikzexternalize[prefix=test-\overlaynumber-]
\tikzsetexternalprefix{tikzpics/}
\usetikzlibrary{3D,
                    calc,%
                    decorations.markings,%
                    decorations.pathreplacing,%
                    external,%
                    positioning,%
                    circuits.logic.mux,%
                    shapes.gates.logic.US,%
                    shapes.geometric}
%\tikzset{node distance/.append code={ \pgfkeyssetvalue{/tikz/node distance value}{#1} }}   % it's supposed to allow retrieving node distance with \pgfkeysvalueof{/tikz/node distance value}
\pgfplotsset{compat=newest, table/search path={./dat},scaled ticks=false,%
            every axis/.append style={enlargelimits=false, axis on top,},%
            every mark/.append style={mark size=1pt, mark line=solid},%
            tick label style={font=\small, /pgf/number format/fixed}, label style={font=\small}, legend style={font=\small},%
            xlabel style={at={(ticklabel cs:0.5,-5pt)},anchor=near ticklabel},%
            ylabel style={at={(ticklabel cs:0.5,-5pt)},anchor=near ticklabel}}
\pgfdeclarelayer{back}
\pgfsetlayers{back,main}
\usepackage[americaninductors]{circuitikz}

\definecolor{mat1}{rgb}{0,0.447,0.7410}
\definecolor{mat2}{rgb}{0.8500,0.3250,0.0980}
\definecolor{mat3}{rgb}{0.9290,0.6940,0.1250}
\definecolor{mat4}{rgb}{0.4940,0.1840,0.5560}

% Rotated Data Flip Flip (DFF) shape
\pgfdeclareshape{dff}{
  % The 'minimum width' and 'minimum height' keys, not the content, determine
  % the size
  \savedanchor\northeast{%
    \pgfmathsetlength\pgf@x{\pgfshapeminwidth}%
    \pgfmathsetlength\pgf@y{\pgfshapeminheight}%
    \pgf@x=0.5\pgf@x
    \pgf@y=0.5\pgf@y
  }
  % This is redundant, but makes some things easier:
  \savedanchor\southwest{%
    \pgfmathsetlength\pgf@x{\pgfshapeminwidth}%
    \pgfmathsetlength\pgf@y{\pgfshapeminheight}%
    \pgf@x=-0.5\pgf@x
    \pgf@y=-0.5\pgf@y
  }
  % Inherit from rectangle
  \inheritanchorborder[from=rectangle]

  % Define same anchor a normal rectangle has
  \anchor{center}{\pgfpointorigin}
  \anchor{north}{\northeast \pgf@x=0pt}
  \anchor{east}{\northeast \pgf@y=0pt}
  \anchor{south}{\southwest \pgf@x=0pt}
  \anchor{west}{\southwest \pgf@y=0pt}
  \anchor{north east}{\northeast}
  \anchor{north west}{\northeast \pgf@x=-\pgf@x}
  \anchor{south west}{\southwest}
  \anchor{south east}{\southwest \pgf@x=-\pgf@x}
  \anchor{text}{
    \pgfpointorigin
    \advance\pgf@x by -.5\wd\pgfnodeparttextbox%
    \advance\pgf@y by -.5\ht\pgfnodeparttextbox%
    \advance\pgf@y by +.5\dp\pgfnodeparttextbox%
  }

  % Define anchors for signal ports
  \anchor{D}{
    \pgf@process{\northeast}%
    \pgf@x=0pt%
    \pgf@y=-\pgf@y%
  }
  \anchor{CLK}{
    \pgf@process{\northeast}%
    \pgf@x=-1\pgf@x%
    \pgf@y=0pt%
  }
  \anchor{Q}{
    \pgf@process{\northeast}%
    \pgf@x=0pt%
    \pgf@y=\pgf@y%
  }
  % Draw the rectangle box and the port labels
  \backgroundpath{
    % Rectangle box
    \pgfpathrectanglecorners{\southwest}{\northeast}
    % Angle (>) for clock input
    \pgf@anchor@dff@CLK
    \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgf@xc=\pgf@x \pgf@yc=\pgf@y
    \pgfmathsetlength\pgf@x{.4ex} % size depends on font size
    \advance\pgf@ya by \pgf@x
    \advance\pgf@xb by \pgf@x
    \advance\pgf@yc by -\pgf@x
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
    \pgfclosepath

    % Draw port labels
    \begingroup
    \tikzset{flip flop/port labels} % Use font from this style
    \tikz@textfont

    \endgroup
  }
}

% Key to add font macros to the current font
\tikzset{add font/.code={\expandafter\def\expandafter\tikz@textfont\expandafter{\tikz@textfont#1}}} 

% Define default style for this node
\tikzset{flip flop/port labels/.style={font=\sffamily\tiny}}
\tikzset{every dff node/.style={draw,minimum width=0.4cm,minimum 
height=0.4cm,inner sep=1mm,outer sep=0pt,cap=round,add 
font=\sffamily}}


\begin{document}

\begin{figure}[t]
\centering
\begin{tikzpicture}[auto, node distance=4mm and 4mm, circuit logic,every node/.style={font=\tiny},]%
    \ctikzset{bipoles/thickness=1}
    
    \node (data) at (0.5,0.3) [anchor=north]{data};
    \node [shape=dff, draw] (ff1) [above=of data] {FF};
\end{tikzpicture}
\end{figure}

\end{document}

相关内容