Latex 正在制作 Tikz 生成的 pdf 图形,转换为 eps,然后使用 \includegraphics-transparent 将其包含在 latex 文档中

Latex 正在制作 Tikz 生成的 pdf 图形,转换为 eps,然后使用 \includegraphics-transparent 将其包含在 latex 文档中

首先,我必须说我刚刚开始使用 Tikz。我使用 Tikz 画了一幅画。它生成了 pdf 输出,我使用 pdftops 将其转换为 eps(提交到期刊所需的图形格式)。当我将 eps 文件包含在我的主要 latex 文档中时,它变得透明,尽管 eps 文件不是透明的。请提出一些建议来纠正它。非常感谢

以下是从 Tikz 生成 pdf 的源代码:

\documentclass[class=minimal,border=0pt]{standalone}
\usepackage{tikz,tikzorbital}
% Tikz
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{shapes,decorations,shadows}  
\usetikzlibrary{decorations.pathmorphing}  
\usetikzlibrary{decorations.shapes}  
\usetikzlibrary{fadings}  
\usetikzlibrary{patterns}  
\usetikzlibrary{calc} 
\usetikzlibrary{arrows}
% \usetikzlibrary{arrows.meta}
\usetikzlibrary{automata}
\usepackage{tikzorbital}

\pgfkeys{/tikz/.cd,
    execute style/.style = {#1},
    execute macro/.style = {execute style/.expand once=#1}
}
% % -----------------------------------------------------------------------------
% % some customization of orbital
% % -----------------------------------------------------------------------------
% 
% inner color for orbital filling

\colorlet{innerColor}{black!10}

% color for orbital drawing

\colorlet{drawColor}{black!80}

% more style for lobe orbital drawing

\newcommand{\setOrbitalDrawingNew}[1]{\def\orbitalDrawingNew{#1}}
\setOrbitalDrawingNew{thick}
% general style

\tikzstyle{base} = [draw = drawColor, thick, inner color = innerColor, 
        circle, opacity = 1, 
            execute macro = \orbitalDrawingNew]
% Tikz

\begin{document}
\begin{tikzpicture}[scale=1]
\foreach \myscale in {.9}
{
\foreach \y in {-1}
{\begin{pgfonlayer}{background}
 \draw [ultra thick] (-3.4cm,\y cm) -- (3.4cm,\y cm); 
    \node[left,thick] at (-3.8cm,\y cm) {$(a)$};
\end{pgfonlayer}
\foreach \x in {-3,-1,..., 4}
\shade[ball color=green] (\x cm,\y cm) circle (.21cm);

\foreach \x in {-2,0,...,3}
{
\orbital[pos = {(\x cm,\y cm)},color=red,scale=\myscale]{lobe};
        \begin{pgfonlayer}{background}
        \node at (\x cm,\y cm) [ellipse, minimum width = \myscale * .3cm, 
              minimum height = \myscale * .8cm, draw = drawColor, 
              inner color = innerColor, outer color = blue, 
              execute macro = \orbitalDrawingNew] 
            {};
        \end{pgfonlayer}
 \orbital[pos = {(\x cm,\y cm)},color=red,scale=\myscale,rotate=180]{lobe};
}}}
\end{tikzpicture}
\end{document}

答案1

您可以为图形添加(白色)背景填充。我使用了 Alain Matthes 在这个答案。出于某种原因,需要手动缩放背景填充。否则图形的尺寸会变大。背景填充似乎没有完全覆盖整个图像区域。

下面的图像是从查看器应用程序截取的屏幕截图,其中的棋盘格图案表示透明度。pdftops -eps用于 PDF 到 EPS 的转换,并且convert(除此以外没有用户指定的参数-density)来自 ImageMagick 的用于转换为 PNG 格式。

我发现转换为 EPS 的中间步骤如何影响 ImageMagick 的最终位图输出,这很有趣。

带有问题代码的图像

PDF -> EPS -> PNG

问题中的代码,PDF 转 EPS 转 PNG

PDF 到 PNG

问题中的代码,PDF 转 PNG

带有此答案的代码的图像

PDF -> EPS -> PNG

代码来自这个答案,PDF 转 EPS 转 PNG

PDF 到 PNG

代码来自这个答案,PDF 到 PNG

\documentclass[class=minimal,border=0pt]{standalone}
\usepackage{tikz,tikzorbital}
% Tikz
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{shapes,decorations,shadows}  
\usetikzlibrary{decorations.pathmorphing}  
\usetikzlibrary{decorations.shapes}  
\usetikzlibrary{fadings}  
\usetikzlibrary{patterns}  
\usetikzlibrary{calc} 
\usetikzlibrary{arrows}
% \usetikzlibrary{arrows.meta}
\usetikzlibrary{automata}
\usetikzlibrary{fit}
\usepackage{tikzorbital}

\pgfkeys{/tikz/.cd,
    execute style/.style = {#1},
    execute macro/.style = {execute style/.expand once=#1}
}
% % -----------------------------------------------------------------------------
% % some customization of orbital
% % -----------------------------------------------------------------------------
% 
% inner color for orbital filling

\colorlet{innerColor}{black!10}

% color for orbital drawing

\colorlet{drawColor}{black!80}

% more style for lobe orbital drawing

\newcommand{\setOrbitalDrawingNew}[1]{\def\orbitalDrawingNew{#1}}
\setOrbitalDrawingNew{thick}
% general style

\tikzstyle{base} = [draw = drawColor, thick, inner color = innerColor, 
        circle, opacity = 1, 
            execute macro = \orbitalDrawingNew]
\pgfdeclarelayer{bgcolor}
\pgfsetlayers{bgcolor,background,main,foreground}

% Tikz

\begin{document}
\begin{tikzpicture}[scale=1]
\begin{scope}[local bounding box=bb]
\foreach \myscale in {.9}
{
\foreach \y in {-1}
{\begin{pgfonlayer}{background}
 \draw [ultra thick] (-3.4cm,\y cm) -- (3.4cm,\y cm); 
    \node[left,thick] at (-3.8cm,\y cm) {$(a)$};
\end{pgfonlayer}
\foreach \x in {-3,-1,..., 4}
\shade[ball color=green] (\x cm,\y cm) circle (.21cm);

\foreach \x in {-2,0,...,3}
{
\orbital[pos = {(\x cm,\y cm)},color=red,scale=\myscale]{lobe};
        \begin{pgfonlayer}{background}
        \node at (\x cm,\y cm) [ellipse, minimum width = \myscale * .3cm, 
              minimum height = \myscale * .8cm, draw = drawColor, 
              inner color = innerColor, outer color = blue, 
              execute macro = \orbitalDrawingNew] 
            {};
        \end{pgfonlayer}
 \orbital[pos = {(\x cm,\y cm)},color=red,scale=\myscale,rotate=180]{lobe};
}}}
\end{scope}
\begin{pgfonlayer}{bgcolor}
  \node [xscale=0.971,yscale=0.901,fill=white,fit=(bb)] {};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}

相关内容