在菱形内画两条虚线

在菱形内画两条虚线

我知道如何绘制三个菱形,如下所示:

    \documentclass{article}
    \usepackage{amsmath}
    \usepackage{tikz-cd}
    \usetikzlibrary{shapes.geometric}
    \begin{document}
    \[\begin{tikzcd}[sep = 2em,
        /tikz/rhombus/.style={shape=diamond,draw,minimum size=2em}]
     |[rhombus,draw,minimum size=3em]|{}\arrow[r,shorten >=0.5em,shorten <=0.5em] & 
     |[rhombus,append after command={\pgfextra{\let\myln\tikzlastnode}
     (\myln.north) node[anchor=south,rhombus] {}
     (\myln.south) node[anchor=north,rhombus] {}}]|{}\\
    \end{tikzcd}\]
    \end{document}

但是,如果我想在大菱形内放置 2 条虚线来指示我需要捏住它以获得 3 个菱形的位置,该怎么办?

任何有关绘制此图的帮助都将不胜感激!

答案1

您可以使用execute at end picture将附加的 TikZ 代码添加到图表中。因此,如果您将大节点别名添加alias=foo到节点的样式中,则可以在节点的锚点之间绘制线条。

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz-cd}
\usetikzlibrary{shapes.geometric}
\begin{document}
\[
  \begin{tikzcd}[sep = 2em,
    /tikz/rhombus/.style={shape=diamond,draw,minimum size=2em},
    execute at end picture={
      \draw [densely dotted] (foo.north west) -- (foo.north east);
      \draw [densely dotted] (foo.south west) -- (foo.south east);
    }
    ]
 |[rhombus,draw,minimum size=3em, alias=foo]|{}\arrow[r,shorten >=0.5em,shorten <=0.5em] & 
 |[rhombus,append after command={\pgfextra{\let\myln\tikzlastnode}
 (\myln.north) node[anchor=south,rhombus] {}
 (\myln.south) node[anchor=north,rhombus] {}}]|{}\\
\end{tikzcd}
\]
\end{document}

相关内容