tikzlibrary:externalize - 生成没有背景的图形

tikzlibrary:externalize - 生成没有背景的图形

你好呀

在带有半透明框的文档中使用库tikz时,生成的图形具有页面背景并在框中显示为孔,如何仅去除生成的图形的背景?externaltcolorboxtcolorbox

梅威瑟:

\documentclass{article}

\usepackage{xcolor}
\pagecolor{black}
\color    {white}

\usepackage{tcolorbox}
\tcbset{every box/.style = {
    notitle,                        % Remove title
    coltext      = white,           % text  color
    opacityfill  = 0.3,             % background opacity
    opacityframe = 0,               % frame      opacity
    colback      = white,           % background color
    colframe     = white,           % border     color
    arc          = 4mm,             % Curvature
    width        = \linewidth,      % Width
    top          = 3mm,             % Space between text and top
    bottom       = 3mm,             % Space between text and bottom
    before upper = {\parindent2ex}, % Paragraph indentation
    before skip  = 0mm,             % Set vspace before box
}}

\usepackage{pgfplots}

% uncommenting generates error
\usetikzlibrary{external}
% External lib
\tikzexternalize[
    up to date check={simple},
    prefix=./.build/figures/
] % turn externalization on/off
\tikzsetfigurename{figure_\arabic{part}.} % set figure names

% Using tikzset generates error
\tikzset{%
    external/system call={%
        lualatex \tikzexternalcheckshellescape
        --halt-on-error
        --shell-escape
        --interaction=batchmode
        % --jobname "\image" "\texsource"
        --jobname "\image" "\texsource"
    }
}

\pgfplotsset{
    compat  = newest,
    width   = 10cm,    % width
    height  =  7cm,    % height
    samples = 10,
}

\begin{document}

% \tikzsetfigurename{figure_\arabic{part}.} % set figure names

\begin{tcolorbox}\centering

    \begin{tikzpicture}
        \begin{axis}[hide axis]
            
            \addplot3 [
                % Aparence
                surf,
                opacity=0.5,
                fill opacity= 1,
                faceted color = white,
                shader=faceted interp,
                % Scope
                data cs = cart, % cart/polar/polarrad
                % Variable
                domain   = -1:1,
                domain y = -1:1,
            ]{
                x^2-y^2
            };
        
        \end{axis}
    \end{tikzpicture}
    \begin{tikzpicture}
        \begin{axis}[hide axis]
            
            \addplot3 [
                % Aparence
                surf,
                opacity=0.5,
                fill opacity= 1,
                faceted color = white,
                shader=faceted interp,
                % Scope
                data cs = cart, % cart/polar/polarrad
                % Variable
                variable   = u,
                variable y = v,
                domain   = 0:360,
                domain y = -180:0,
            ]
            (
                {cos(u)*sin(v)}, 
                {sin(u)*sin(v)}, 
                {cos(v)}
            );
        
        \end{axis}
    \end{tikzpicture}

\end{tcolorbox}

\end{document}

生成:

生成的 pdf

答案1

一种解决方案是\nopagecolor在每个之后添加\begin{tikzpicture},可以广泛添加命令或重命名\tikzpicture以添加\nopagecolor命令。

如果有更好的解决方案我会很高兴知道,在此之前我会使用以下方法:

\documentclass{article}

\usepackage{xcolor}
\pagecolor{black}
\color    {white}

\usepackage{tcolorbox}
\tcbset{every box/.style = {
    notitle,                        % Remove title
    coltext      = white,           % text  color
    opacityfill  = 0.3,             % background opacity
    opacityframe = 0,               % frame      opacity
    colback      = white,           % background color
    colframe     = white,           % border     color
    arc          = 4mm,             % Curvature
    width        = \linewidth,      % Width
    top          = 3mm,             % Space between text and top
    bottom       = 3mm,             % Space between text and bottom
    before upper = {\parindent2ex}, % Paragraph indentation
    before skip  = 0mm,             % Set vspace before box
}}

\usepackage{pgfplots}

% uncommenting generates error
\usetikzlibrary{external}
% External lib
\tikzexternalize[
    up to date check={simple},
    prefix=./.build/figures/
] % turn externalization on/off
\tikzsetfigurename{figure_\arabic{part}.} % set figure names

% Using tikzset generates error
\tikzset{%
    external/system call={%
        lualatex \tikzexternalcheckshellescape
        --halt-on-error
        --shell-escape
        --interaction=batchmode
        % --jobname "\image" "\texsource"
        --jobname "\image" "\texsource"
    }
}

% Modify all tikzpicture to remove background
\let\oldtikzpicture\tikzpicture
\renewcommand\tikzpicture{\oldtikzpicture\nopagecolor}

\pgfplotsset{
    compat  = newest,
    width   = 10cm,    % width
    height  =  7cm,    % height
    samples = 10,
}

\begin{document}

% \tikzsetfigurename{figure_\arabic{part}.} % set figure names

\begin{tcolorbox}\centering

    \begin{tikzpicture}
        % \nopagecolor % Extensive solution
        \begin{axis}[hide axis]
            
            \addplot3 [
                % Aparence
                surf,
                opacity=0.5,
                fill opacity= 1,
                faceted color = white,
                shader=faceted interp,
                % Scope
                data cs = cart, % cart/polar/polarrad
                % Variable
                domain   = -1:1,
                domain y = -1:1,
            ]{
                x^2-y^2
            };
        
        \end{axis}
    \end{tikzpicture}
    \begin{tikzpicture}
        % \nopagecolor % Extensive solution
        \begin{axis}[hide axis]
            
            \addplot3 [
                % Aparence
                surf,
                opacity=0.5,
                fill opacity= 1,
                faceted color = white,
                shader=faceted interp,
                % Scope
                data cs = cart, % cart/polar/polarrad
                % Variable
                variable   = u,
                variable y = v,
                domain   = 0:360,
                domain y = -180:0,
            ]
            (
                {cos(u)*sin(v)}, 
                {sin(u)*sin(v)}, 
                {cos(v)}
            );
        
        \end{axis}
    \end{tikzpicture}

\end{tcolorbox}

\end{document}

得出的结果是: 生成的 pdf

相关内容