我有一张图片,显示绘制为小图片矩阵\pic
:
\documentclass{scrartcl}
\usepackage[svgnames]{xcolor}
\usepackage{tikz,xstring}
\tikzset{FilteredSphere/.pic={
\begin{scope}[every node/.append style={inner sep=1pt, outer sep=2pt}, x=2mm, y=2mm]
%\fill[white] (0,0) circle (2);
% \begin{scope}[gray]
% \draw[dashed] (2,0) arc (0:180:2 and 0.6);
% \draw (0,0) circle (2) ;
% \draw (-2,0) arc (180:360:2 and 0.6);
% \end{scope}
\begin{scope}[opacity=.5]
\IfSubStr{#1}{f}{
\begin{scope}
\clip (0,2) arc (90:-90:2) arc (-90:90:.6 and 2);
\shade[ball color=red!70] (0,0) circle[radius=2];
\end{scope}
\begin{scope}
\clip (0,2) arc (90:-90:2) arc (-90:90:1.2 and 2);
\shade[ball color=red!70] (0,0) circle[radius=2];
\end{scope}
}{}
\IfSubStr{#1}{g}{
\begin{scope}
\clip (0,2) arc (90:-90:-2 and 2) arc (-90:90:.6 and 2);
\shade[ball color=blue!60] (0,0) circle[radius=2];
\end{scope}
\begin{scope}
\clip (0,2) arc (90:-90:-2 and 2) arc (-90:90:-1.3 and 2);
\shade[ball color=blue!60] (0,0) circle[radius=2];
\end{scope}
}{}
\IfSubStr{#1}{h}{
\begin{scope}
\clip (0,2) arc (90:-90:-1.2 and 2) arc (-90:90:1.2 and 2);
\shade[ball color=green!70] (0,0) circle[radius=2];
\end{scope}
}{}
\end{scope}
\begin{scope}[thick]
\IfSubStr{#1}{a}{\draw[red] (0,2) arc (90:-90:-1.3 and 2) node[below left, pos=.9] {\IfSubStr{#1}{A}{$a$}{}};}{}
\IfSubStr{#1}{b}{\draw[blue] (0,2) arc (90:-90:1.2 and 2) node[below right, pos=.9] {\IfSubStr{#1}{B}{$b$}{}};}{}
\IfSubStr{#1}{c}{
\IfSubStr{#1}{h}{
\draw[Aqua, densely dotted] (0,2) arc (90:270:-0.6 and 2) node[left=-2pt, midway] {\IfSubStr{#1}{C}{$c$}{}};
}{
\draw[Aqua] (0,2) arc (90:270:-0.6 and 2) node[left=-2pt, midway] {\IfSubStr{#1}{C}{$c$}{}};
}
}{}
\end{scope}
\IfSubStr{#1}{x}{\fill (0,2) circle (0.15);}{}
\IfSubStr{#1}{y}{\fill (0,-2) circle (0.15);}{}
\path
(0,2) arc (90:-90:2) node[text=red, pos=.4, above right] {\IfSubStr{#1}{F}{$f$}{}}
(0,2) arc (90:-90:-2 and 2) node[text=blue!50!black, pos=.6,, below left] {\IfSubStr{#1}{G}{$g$}{}}
(-1.9, .65) node[text=green!50!black] {\IfSubStr{#1}{H}{$h$}{}}
(0,2) node[left]{\IfSubStr{#1}{X}{$x$}{}}
(0,-2) node[left]{\IfSubStr{#1}{X}{$y$}{}};
\end{scope}
}}
\begin{document}
\begin{tikzpicture}
\matrix [column sep=0.5em, row sep=0.45em, cells={draw}] {
\pic {FilteredSphere={xya}}; &
\pic {FilteredSphere={xyabhH}}; &
\pic {FilteredSphere={xyabchg}}; &
\pic {FilteredSphere={xyabcfgh}};
\\
\pic {FilteredSphere={xya}}; &
\pic {FilteredSphere={xyab}}; &
\pic {FilteredSphere={xyabcgG}}; &
\pic {FilteredSphere={xyabcfg}}; &
\\
\pic {FilteredSphere={xy}}; &
\pic {FilteredSphere={xyb}}; &
\pic {FilteredSphere={xybc}}; &
\pic {FilteredSphere={xybcfF}};
\\
\pic {FilteredSphere={xyXY}}; &
\pic {FilteredSphere={xy}}; &
\pic {FilteredSphere={xycC}}; &
\pic {FilteredSphere={xyc}}; \\
};
\end{tikzpicture}
\end{document}
现在,我被要求在这个矩阵的行和列之间绘制水平和垂直规则。显然,\pic
s 不是节点,我无法命名它们并引用它们的锚点。我该怎么办?
我不想构建一个matrix
,tikzpictures
因为如果可能的话,我想保留将图片整体外部化的能力。另外,我必须处理对齐问题。
答案1
嗯,你的代码有点奇怪:无论我在哪里尝试添加[draw=black]
以显示每个的外形\pic
,希望能够得到你想要的网格,但它却失败了:
- 没有画线
- 也许它被你画图的方式隐藏了
因此,这里有一个后备方案供您选择:
- 在上面画一个网格
- 进一步调整和修改其起点等(仍然需要)
- 改变颜色
\draw [draw=blue,ystep=12.3mm, ...
- 如果有必要,可以裁剪结果以从视觉上去除外线
也许有办法获得最终矩阵的尺寸,以便更好地设置网格参数。我只是用反复试验假设 x 和 y 步长是恒定的。
...
}; % end of matrix
\draw [ystep=12.3mm, yshift=1mm, xstep=13mm, xshift=-1mm] (-3,-3) grid (3,3);
\end{tikzpicture}
\end{document}