tikzexternalize 和 tcolorbox 无法协同工作

tikzexternalize 和 tcolorbox 无法协同工作

如果我外部化 tikzpicture,LaTeX 不会像 includegraphics 那样在草稿模式下保留适当的空间。它无助于正确格式化文本。因此,我结合了这两个命令以包含外部化的图片(如果存在)。我不知道是否可以用其他方式实现。

但是,我也使用 tcolobox,即使我按照多个讨论中的建议添加了 \tcbsetforeverylayer{shield externalize},它也无法一起工作。请问有人知道如何修复它吗?我附上了 MWE。

\documentclass[draft]{tufte-book} 

\usepackage{pgf,tikz,pgfplots}
\usepackage{tkz-euclide}
\usetikzlibrary{patterns}

\pgfplotsset{compat=1.18}

\usetikzlibrary{external}

\newcounter{extcounter}
\setcounter{extcounter}{0}

\newcommand{\cotoje}[1]{#1}
\tikzsetfigurename{XYZ}
\tikzexternalize

% NOTE: Modified from https://tex.stackexchange.com/a/580401/140433
\newcommand{\setpgfexternalcounter}[1]{
  \makeatletter%
  \pgfkeysgetvalue{/tikz/external/figure name}\myexternalname
  \expandafter\gdef\csname c@tikzext@no@\myexternalname\endcsname{#1}%
  \makeatother
}

\newcommand{\externalizuj}[1]{\setpgfexternalcounter{\theextcounter}
 \IfFileExists{./XYZ\theextcounter.pdf}{%
  \includegraphics{./XYZ\theextcounter.pdf}}{%
   #1
  }%
\addtocounter{extcounter}{1}}

\usepackage{lipsum}

\usepackage[most]{tcolorbox}
\tcbsetforeverylayer{shield externalize}

\newcommand{\textbox}[1]{{\tikzset{external/export=false}\tcbsetforeverylayer{shield externalize}
  \begin{tcolorbox}[colback=gray!15!white,colframe=gray,width=(\linewidth-15mm),breakable]
   \tikzset{external/export=false}#1
  \end{tcolorbox}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
\begin{document}
\lipsum[1-2]

\externalizuj{\begin{tikzpicture}
  \node {root}
    child {node {left}}
    child {node {right}
      child {node {child}}
      child {node {child}}
    };
\end{tikzpicture}}

\begin{marginfigure}[2mm]
 \begin{center}
  \externalizuj{
  \begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=2.2cm,y=2.2cm]
   \draw[->,color=black] (-0.3,0) -- (1.5,0);
   \draw[->,color=black] (0,-0.3) -- (0,1.5);
   \clip(-0.3,-0.3) rectangle (1.5,1.5);
   \draw [fill=red] (0.,0.) circle (2.8pt);
   \draw [fill=red] (1.,0.) circle (2.8pt);
   \draw [fill=red] (1.,1.) circle (2.8pt);
   \draw [fill=red] (0.,1.) circle (2.8pt);
  \end{tikzpicture}}\vspace*{-2mm}
 \caption{}\label{Obr:KA.2.1.6a}
 \end{center}
\end{marginfigure}

\begin{marginfigure}[2mm]
 \begin{center}
  \externalizuj{\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=2.2cm,y=2.2cm]
   \draw[->,color=black] (-0.3,0) -- (1.5,0);
   \draw[->,color=black] (0,-0.3) -- (0,1.5);
   \clip(-0.3,-0.3) rectangle (1.5,1.5);
   \draw [fill=red] (0.,0.) circle (2.8pt);
   \draw [fill=red] (1.,0.) circle (2.8pt);
   \draw [fill=red] (1.,1.) circle (2.8pt);
   \draw [fill=red] (0.,1.) circle (2.8pt);
  \end{tikzpicture}}\vspace*{-2mm}
 \caption{}\label{Obr:KA.2.1.6aa}
 \end{center}
\end{marginfigure}

A simple image is \externalizuj{\tikz \fill (0,0) circle(5pt);}.

\lipsum[2-4]

\begin{marginfigure}[2mm]
 \begin{center}
  \externalizuj{\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=2.2cm,y=2.2cm]
   \draw[->,color=black] (-0.3,0) -- (1.5,0);
   \draw[->,color=black] (0,-0.3) -- (0,1.5);
   \clip(-0.3,-0.3) rectangle (1.5,1.5);
   \draw [fill=red] (0.,0.) circle (2.8pt);
   \draw [fill=red] (1.,0.) circle (2.8pt);
   \draw [fill=red] (1.,1.) circle (2.8pt);
   \draw [fill=red] (0.,1.) circle (2.8pt);
   \draw [line width=1.5pt] (0.,1.)-- (0.,0.);
   \draw [line width=1.5pt] (1.,0.)-- (0.,0.);
   \draw [line width=1.5pt] (0.,1.)-- (1.,1.);
   \draw [line width=1.5pt] (1.,1.)-- (1.,0.);
   \draw [line width=1.5pt] (1.,0.)-- (0.,1.);
   \draw [line width=1.5pt] (0.,0.)-- (1.,1.);
  \end{tikzpicture}}\vspace*{-2mm}
 \caption{}\label{Obr:KA.2.1.6b}
 \end{center}
\end{marginfigure}

\lipsum[3-5]

\begin{center}\vspace*{-7mm}
  \textbox{\lipsum[1-2]}
 \end{center}\vspace*{-4mm}

\end{document}

答案1

我找到了解决方案。令人惊讶的是,问题似乎出在\usepackage[most]{tcolorbox}。如果我将其替换为 ,\usepackage[breakable,theorems,fitting,hooks,magazine,poster,raster,skins]{tcolorbox}它就可以正常工作。但是当我添加 时vignette,它就停止工作了。

相关内容