我有一张巨大的 tikz 图片(由多达几个 10k 个元素组成,主要是矩形和箭头),并且想使用外部化“分割”文件以避免扩大 tex 的主内存大小(或使用 luatex)。
由于我无论如何都要使用 pgf 层,所以我的想法是将每一层外部化。以下是我到目前为止所做的一个最小示例:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{fp}
\usetikzlibrary{arrows}
\usetikzlibrary{external}
\tikzexternalize[prefix=tikz/]
\pgfdeclarelayer{background}
\pgfdeclarelayer{layer1}
\pgfdeclarelayer{layer2}
\pgfsetlayers{background,layer1,layer2,main}
\def\picWidth{416}
\def\picHeight{240}
\FPeval\relation{\picHeight/\picWidth}
\tikzstyle{blkLine}=[thin]
\tikzstyle{vecLine}=[thick,>=stealth,->]
\begin{document}
\begin{pgfonlayer}{background}
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=\textwidth]{../TikZ_test/BasketballPass_416x240_50_frm16.jpg}};
\end{tikzpicture}
\end{pgfonlayer}
\begin{pgfonlayer}{layer1}
\begin{tikzpicture}
\node[anchor=south west,inner sep=0,fill=white,opacity=0,minimum width=\textwidth,minimum height=\relation\textwidth] (image) at (0,0) {};
\begin{scope}[blkLine,fill opacity=0.2,x={(image.south east)},y={(image.north west)},shift={(image.north west)},yscale=-1]
\filldraw[fill=red!20!yellow] (0,0) rectangle (0.5,0.5);
\filldraw[fill=red!40!yellow] (0,0.5) rectangle (0.5,1);
\filldraw[fill=red!60!yellow] (0.5,0) rectangle (1,1);
\end{scope}
\end{tikzpicture}
\end{pgfonlayer}
\begin{pgfonlayer}{layer2}
\begin{tikzpicture}
\node[anchor=south west,inner sep=0,fill=white,opacity=0,minimum width=\textwidth,minimum height=\relation\textwidth] (image) at (0,0) {};
\begin{scope}[vecLine,x={(image.south east)},y={(image.north west)},shift={(image.north west)},yscale=-1]
\filldraw[color=black] (0.25,0.25) -- (0.75,0.75);
\end{scope}
\end{tikzpicture}
\end{pgfonlayer}
\end{document}
对于不同的层(或者更确切地说是 tikzpictures),pdf 文件生成得非常完美,但“组合”的 pdf 文件是空的。由于分层 tikz 图片不支持外部化,还有其他方法可以正确地组合图片吗?
答案1
我非常确定图层不会为您节省任何东西。我不确定我的想法(覆盖)是否更好。TeX 将所有内容保存在内存中直到页面结束,但 CiruiTikz 还将各种其他内容保存在内存中。如果 CircuiTikz 在关闭时将所有内容缩减为更紧凑的内容(PGF?),那么您可能很幸运。
无论如何,我们的想法是将电路分解成几部分,然后将这些部分叠加起来。
\documentclass{article}
\usepackage{circuitikz}
% Syntax: \overlay(x,y)overlay
% x and y are registration corrections (need units)
% overlay is terminated by a space or end of line, not braces.
\def\overlay(#1,#2)#3
{\noindent\makebox[\textwidth][l]{\hspace*{#1}\raisebox{#2}[0pt][0pt]{#3}
}\hspace*{-\textwidth}}
% \centerbox{text/picture}
\newcommand{\centerbox}[1]{\makebox[\textwidth][c]{#1}}
\begin{document}
Put a border around your overlays to aid registration.
You can always change the color to white.
\begin{tabular}{cc}
\begin{circuitikz}
\draw[color=blue] (-2,-1) -- (-2,3) -- (3,3) -- (3,-1) -- cycle;
\draw (0,0) to[short, *-*] (2,0) (0,2) to[short, *-*] (2,2);
\end{circuitikz}
&
\begin{circuitikz}
\draw[color=blue] (-2,-1) -- (-2,3) -- (3,3) -- (3,-1) -- cycle;
\draw (0,0) to[C=$C_1$] (0,2) (2,0) to[R=$R_1$] (2,2);
\end{circuitikz}
\end{tabular}
\overlay(0pt,0pt)\centerbox{
\begin{circuitikz}
\draw[color=blue] (-2,-1) -- (-2,3) -- (3,3) -- (3,-1) -- cycle;
\draw (0,0) to[short, *-*] (2,0) (0,2) to[short, *-*] (2,2);
\end{circuitikz}}
\centerbox{
\begin{circuitikz}
\draw[color=blue] (-2,-1) -- (-2,3) -- (3,3) -- (3,-1) -- cycle;
\draw (0,0) to[C=$C_1$] (0,2) (2,0) to[R=$R_1$] (2,2);
\end{circuitikz}}
You can also do it like this:
\overlay(1.05cm,-.06cm)\mbox{
\begin{circuitikz}
\draw (0,0) to[short, *-*] (2,0) (0,2) to[short, *-*] (2,2);
\end{circuitikz}}
\mbox{
\begin{circuitikz}
\draw (0,0) to[C=$C_1$] (0,2) (2,0) to[R=$R_1$] (2,2);
\end{circuitikz}}
\end{document}