为什么使用 tcolorbox 包时会出现“TeX 容量超出”错误

为什么使用 tcolorbox 包时会出现“TeX 容量超出”错误

对于我编写的包(schemabloc -https://ctan.org/pkg/schemabloc) 运行正常,但是当我使用它来显示 Tikz 代码示例时,tcolorbox 包出现了问题。

我从包中提取了似乎导致问题的两个函数。带星号的 \sbComp*... 命令版本系统地显示了错误

TeX 容量超出,抱歉 [grouping levels=255]。\pgf@setlengthorig #1#2->\begingroup \pgfutil@selectfont \pgf@setlengthorig ...

你能看一下代码,看看问题出在哪里吗(我在使用 showexpl 包时也遇到了错误(https://www.ctan.org/pkg/showexpl))

\documentclass{article}
\usepackage{tikz}


\usetikzlibrary{fit,calc,positioning,shapes.misc}

\usepackage[most]{tcolorbox}

\newtcblisting{tikzexample}[1][]{tikz lower, 
           listing side text, fonttitle=\bfseries,
           bicolor, colback=blue!15!white, colbacklower=white,
           colframe=black, righthand width=0.5\textwidth, #1}

\makeatletter

\newcommand{\sbEntree}[2][0,0]{
    \node [coordinate, name=#2] at (#1) {};
\node(#2droite) at (#2){};

}

\newcommand*{\sbCompSum}{\@ifstar\sbCompSumNorm\sbCompSumUsuel}


\newcommand{\sbCompSumUsuel}[7][4]{
    \node [draw, circle,minimum size=2em, right of=#3droite%
,node distance=#1em] (#2) {};
     \node [draw, cross out,minimum size=1.414em,
     right of=#3droite,node distance=#1em] {};
     \node [above of=#2,node distance=0.6em,inner sep=0] {$#4$};
     \node [below of=#2,node distance=0.6em,inner sep=0] {$#5$};
     \node [left of=#2,node distance=0.6em,inner sep=0] {$#6$};
     \node [right of=#2,node distance=0.6em,inner sep=0] {$#7$};
\node (#2droite) at (#2.east){};
\node (#2gauche) at (#2.west){};
}


\newcommand{\sbCompSumNorm}[7][4]{
    \node [draw, circle,minimum size=1.5em, right of=#3,node distance=#1em,] (#2) {};
    \node [ fit=(#2),inner sep=0.5em] (compext)  {};
\node at( compext.75){$#4$};
\node at( compext.-75){$#5$};
\node at( compext.165){$#6$};
\node at( compext.15){$#7$};
\node (#2droite) at (#2.east){};
\node (#2gauche) at (#2.west){};
}


\newcommand*{\sbComp}{\@ifstar\sbCompNorm\sbCompUsuel}
\newcommand{\sbCompUsuel}[3][4]{
\sbCompSum[#1]{#2}{#3}{}{-}{+}{}
}
\newcommand{\sbCompNorm}[3][4]{
\sbCompSum*[#1]{#2}{#3}{}{-}{+}{}
}

\makeatother


\begin{document}

\begin{tikzpicture}
\sbEntree{E};
\sbComp{C1}{E}
\end{tikzpicture}

\begin{tikzexample}[title=Commande  , listing outside text, righthand width=0.45\textwidth,]
\begin{tikzpicture}
\sbEntree{E};
\sbComp{C1}{E}
\end{tikzpicture}
\end{tikzexample}


\begin{tikzpicture}
\sbEntree{E};
\sbComp*{C1}{E}
\end{tikzpicture}

%---------------------------
% code that doesn't work%
%\begin{tikzexample}[title=Commande  , listing outside text, righthand width=0.45\textwidth,]
%\begin{tikzpicture}
%\sbEntree{E};
%\sbComp*{C1}{E}
%\end{tikzpicture}
%\end{tikzexample}

\end{document}

答案1

不要嵌套tikzpicture环境。tikz lower已经tikzpicture在框的下部放置了一个环境,因此您需要从代码中完全省略它或将其注释掉。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit,calc,positioning,shapes.misc}
\usepackage[most]{tcolorbox}

\newtcblisting{tikzexample}[1][]{%
  tikz lower, 
  listing side text, 
  fonttitle=\bfseries,
  bicolor,
  colback=blue!15!white,
  colbacklower=white,
  colframe=black,
  righthand width=0.5\textwidth,
  #1%
}

\makeatletter

\newcommand{\sbEntree}[2][0,0]{%
  \node [coordinate, name=#2] at (#1) {};
  \node(#2droite) at (#2){};
}

\newcommand*{\sbCompSum}{\@ifstar\sbCompSumNorm\sbCompSumUsuel}

\newcommand{\sbCompSumUsuel}[7][4]{%
  \node [draw, circle,minimum size=2em, right of=#3droite,node distance=#1em] (#2) {};
  \node [draw, cross out,minimum size=1.414em,right of=#3droite,node distance=#1em] {};
  \node [above of=#2,node distance=0.6em,inner sep=0] {$#4$};
  \node [below of=#2,node distance=0.6em,inner sep=0] {$#5$};
  \node [left of=#2,node distance=0.6em,inner sep=0] {$#6$};
  \node [right of=#2,node distance=0.6em,inner sep=0] {$#7$};
  \node (#2droite) at (#2.east){};
  \node (#2gauche) at (#2.west){};
}

\newcommand{\sbCompSumNorm}[7][4]{%
  \node [draw, circle,minimum size=1.5em, right of=#3,node distance=#1em] (#2) {};
  \node [ fit=(#2),inner sep=0.5em] (compext)  {};
  \node at( compext.75){$#4$};
  \node at( compext.-75){$#5$};
  \node at( compext.165){$#6$};
  \node at( compext.15){$#7$};
  \node (#2droite) at (#2.east){};
  \node (#2gauche) at (#2.west){};
}

\newcommand*{\sbComp}{\@ifstar\sbCompNorm\sbCompUsuel}
\newcommand{\sbCompUsuel}[3][4]{%
  \sbCompSum[#1]{#2}{#3}{}{-}{+}{}%
}
\newcommand{\sbCompNorm}[3][4]{%
  \sbCompSum*[#1]{#2}{#3}{}{-}{+}{}%
}

\makeatother

\begin{document}

\begin{tikzpicture}
  \sbEntree{E};
  \sbComp{C1}{E}
\end{tikzpicture}

\begin{tikzexample}[title=Commande  , listing outside text, righthand width=0.45\textwidth,]
%   \begin{tikzpicture}
    \sbEntree{E};
    \sbComp{C1}{E}
%   \end{tikzpicture}
\end{tikzexample}

\begin{tikzpicture}
  \sbEntree{E};
  \sbComp*{C1}{E}
\end{tikzpicture}

%---------------------------
% code that doesn't work%
\begin{tikzexample}[title=Commande  , listing outside text, righthand width=0.45\textwidth,]
%   \begin{tikzpicture}
    \sbEntree{E};
    \sbComp*{C1}{E}
%   \end{tikzpicture}
\end{tikzexample}

\end{document}

tcolorboxes 之外编译的图片

相关内容