Tikzcd:如果我一次将图像模式应用于所有单元格,则填充节点会失败

Tikzcd:如果我一次将图像模式应用于所有单元格,则填充节点会失败

path picture我正在尝试使用推荐的背景图像填充一些图片这里或者这里。如果我将样式直接放入单元格中,效果很好|[path card]| my content,但如果我将它放在里面,则无法编译cells={nodes={path card}}。知道哪里出了问题吗?

在此处输入图片描述

梅威瑟:

\documentclass[]{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{cd,calc,positioning,shadows}

\begin{document}

\tikzset{
  path card/.style={
    path picture={
      \node[] at (path picture bounding box.center) {
        \includegraphics[height=3cm]{example-image}};}},
}
{
  \begin{tikzcd}[
    nodes in empty cells,
    column sep=1mm,
    row sep=1mm,
    cells={
      nodes={
        inner sep=0pt,
        minimum width=3.9mm,
        minimum height=6mm,
        drop shadow,
        draw,
        fill=white,
        rounded corners=2pt,
        anchor=center,
        shape=rectangle,
        font={\fontsize{4}{12}\selectfont},
        %path card, %% <- uncomment this line, everything breaks.
      }
    },
    ]
     |[path card]| &  & [1mm] & \\
                   &  &       & \\[1mm]
                   &  &       & \\
                   &  &       &
  \end{tikzcd}
}%


\end{document}

答案1

path picture您为所有包含包含包含包含...的节点定义样式(选项) - 问题。使用(或单独使用以避免警告)node中断无限递归。path picture=nonepath picture

\documentclass[tikz]{standalone}
\usepackage{graphicx}
\usetikzlibrary{matrix,shadows}

\tikzset{
  path card/.style={
    path picture={
      \node[path picture] at (path picture bounding box.center) {
        \includegraphics[height=3cm]{example-image}};}},
}

\begin{document}
\begin{tikzpicture}
\matrix [
matrix of  nodes,
nodes in empty cells,
  column sep=1mm,
    row sep=1mm,
      nodes={
        inner sep=0pt,
        minimum width=3.9mm,
        minimum height=6mm,
        drop shadow,
        draw,
        fill=white,
        rounded corners=2pt,
        anchor=center,
        shape=rectangle,
        font={\fontsize{4}{12}\selectfont},
        path card,
    },
]{
 & &[1mm]  &\\
 & & &\\[1mm]
 & & &\\
 & & &\\
};
\end{tikzpicture}
\end{document}

16 个矩形及示例图像

相关内容