答案1
我希望这会有所帮助,这取决于您需要绘制的图表类型。
- 我们修补
tikzcd
环境,以便它能够检测何时在内部使用tikzpicture
…… - 并添加一些转发的键,以便环境尽可能
tikzcd
地像正常的 TikZ 一样运行。\matrix
between origins
、overlay
编辑的 TikZ 标签和每个 TikZ-CD 矩阵的自定义组合padding
确保框(即绘制的矩阵)具有相同的大小。当然,为此,所有点都需要具有相同的大小。- 该
cd arrow
键尽可能简单地模拟 TikZ-CD 自己的\ar(row)
命令。
代码
\documentclass{article}
\usepackage{tikz} \usetikzlibrary{cd, positioning, quotes}
\makeatletter
\tikzcdset{
/utils/temp/.initial/.expand once=\tikzcd,
/utils/temp/.prefix=\ifx\path\tikz@command@path\let\tikzpicture\scope\let\endtikzpicture\endscope\fi,
/utils/temp/.get=\tikzcd,
enable tikzcd quotes/.code=%
\pgfkeyssetvalue{/handlers/first char syntax/\expandafter\meaning\string"}{\tikz@quote@parser}%
\def\tikz@quotes@as##1##2{matrices={label={[direction shorthands,##2]##1}}},
forwarded keys/.style={% the \pgfkeyslet stuff makes sure the keys work normal in an arrow label
#1/.style={matrices={/tikz/#1={##1}}},
every label/.append code=\pgfkeyslet{/tikz/commutative diagrams/#1/.@cmd}\pgfutil@undefined}}
\makeatother
\tikzcdset{
forwarded keys/.list={below, left, right, above, name, anchor, matrix anchor},
matrices/.style={every matrix/.append style={#1}},
padding/.style args={#1:#2}{
matrices={inner xsep={(#1)*1ex}, inner ysep={(#2)*1ex}}},
tight/.style={inner sep=+.25ex}}
\tikzset{
Dot Diagram/.code=%
\tikzcdset{
tikzcd to/.tip={Stealth[scale width=.75, inset=+.75pt +.5]}, % arrow tip
matrices={draw, outer sep=+.5ex},
diagrams={% between origins + overlay labels + padding makes it
% easy to create matrices that have same dimensions
enable tikzcd quotes,
row sep={3em,between origins}, column sep={5em,between origins},
/tikz/every label/.style={% the labels on matrices
path only, math nodes, shape=asymmetrical rectangle,
inner sep=+0pt, outer sep=+0pt},
cells={
/tikz/label distance=+-1ex, % because of outer sep=.5ex
/tikz/every label/.style={% we need to reset all dot settings
shape=rectangle, path only, overlay,
commutative diagrams/every label},
nodes={% these are our dots
shape=circle, fill, inner sep=+0pt,
outer sep=+.5ex, minimum size=+.7ex}}}},
math nodes/.style={execute at begin node=$, execute at end node=$},
cd arrow/.style={% a very simple TikZ-CD's \arrow implementation
every edge/.append style={
nodes={math nodes, commutative diagrams/every label},
commutative diagrams/every arrow}}}
\begin{document}
\[
\begin{tikzpicture}[Dot Diagram, node distance=1.5em]
\begin{tikzcd}[name=aa, "{{}=A^2}" right, padding=3:3.1]
|["{(s, t)}"]| & |["{(t, t)}"]| \\
|["{(s, s)}" below]| \ar[ur, "{(a, a)}" tight] & |["{(t, s)}" below]|
\end{tikzcd}
\begin{tikzcd}[name=da, below=of aa, "{{}=A}" right, padding=3:1.7]
|["s" left]| \ar[r, "a"] & |["t" right]|
\end{tikzcd}
\begin{tikzcd}[name=la, left =of aa, "{A={}}" left, padding=1.7:3.1]
|["t"]| \\ |["s" below]| \ar[u, "a"]
\end{tikzcd}
% a very simple TikZ-CD's \arrow implementation
\path[cd arrow] (aa) edge["p_1"] (da)
edge["p_2"] (la);
\end{tikzpicture}
\]
\end{document}