通过镜像对 tikzcd 中的图表进行二元化的脚本

通过镜像对 tikzcd 中的图表进行二元化的脚本

我的问题非常类似这个但在某些情况下,我希望我的图表被镜像而不是旋转。是否可以在 LaTeX 中编写一个脚本来实现这一点?作为示例,我有这个产品图表:

\begin{tikzcd}
C \arrow[rr] \arrow[drr, "\phi_x"] \arrow[ddrr]
\arrow[dd, "\exists! \Phi", dashed] && \vdots \\
&& F(x) \\
\prod F \arrow[uurr] \arrow[urr, "\pi_x", swap] \arrow[rr] && \vdots
\end{tikzcd}

及其对偶,余积:

\begin{tikzcd}
\vdots \arrow[rr] \arrow[ddrr] && C \\
F(x) \arrow[urr, "\phi_x"] \arrow[drr, "\mu_x", swap] \\
\vdots \arrow[uurr]\arrow[rr] && \coprod F \arrow[uu, "\exists ! \Phi", dashed]
\end{tikzcd}

我曾尝试修改链接问题的接受答案中的脚本,但未能找到解决方案。 谢谢!

答案1

对于像这样的简单图表,您只需将设置column sep为负值,交换标签,然后恢复箭头。这里的负值是通过查看手册找到的。复杂得多,复杂意味着不同的列宽、恢复箭头等,图表可能不那么容易对偶化。(仍然可以编写将所有相关原始键恢复为其“对偶化”值的样式,但为此付出的努力可能不值得。)

\documentclass{article}
\usepackage{tikz-cd}
\tikzcdset{dual/.style={column sep=#1,every label/.append style={swap},
arrows=leftarrow},
dual/.default=-5.5em}
\begin{document}
Original diagram:
\[\begin{tikzcd}
C \arrow[rr] \arrow[drr, "\phi_x"] \arrow[ddrr]
\arrow[dd, "\exists! \Phi", dashed] && \vdots \\
&& F(x) \\
\prod F \arrow[uurr] \arrow[urr, "\pi_x", swap] \arrow[rr] && \vdots
\end{tikzcd}\]
Dual constructed by hand"
\[\begin{tikzcd}
\vdots \arrow[rr] \arrow[ddrr] && C \\
F(x) \arrow[urr, "\phi_x"] \arrow[drr, "\mu_x", swap] \\
\vdots \arrow[uurr]\arrow[rr] && \coprod F \arrow[uu, "\exists ! \Phi", dashed]
\end{tikzcd}\]
Dual constructed by adding the pgf key \texttt{dual} to the original diagram.
\[
\begin{tikzcd}[dual]
C \arrow[rr] \arrow[drr, "\phi_x"] \arrow[ddrr]
\arrow[dd, "\exists! \Phi", dashed] && \vdots \\
&& F(x) \\
\prod F \arrow[uurr] \arrow[urr, "\pi_x", swap] \arrow[rr] && \vdots
\end{tikzcd}\]
\end{document}

在此处输入图片描述

如何让事情变得更容易?您可以将原始图表存储在宏中(使用适当的ampersand replacement),然后重新使用该宏对其进行二元化。

\documentclass{article}
\usepackage{tikz-cd}
\tikzcdset{dual/.style={column sep=#1,every label/.append style={swap},
arrows=leftarrow},dual/.default=-5.5em,ampersand replacement=\&}
\begin{document}
\def\OriginalDiagram{C \arrow[rr] \arrow[drr, "\phi_x"] \arrow[ddrr]
\arrow[dd, "\exists! \Phi", dashed] \&\& \vdots \\
\&\& F(x) \\
\prod F \arrow[uurr] \arrow[urr, "\pi_x", swap] \arrow[rr] \&\& \vdots
}
Original diagram:
\[\begin{tikzcd}
\OriginalDiagram
\end{tikzcd}\]
Dual constructed by adding the pgf key \texttt{dual} to the original diagram.
\[
\begin{tikzcd}[dual]
\OriginalDiagram
\end{tikzcd}\]
\end{document}

在此处输入图片描述

不用说,这种二元性不会将 a\pi变成 a \mu,将 a\prod变成 a \coprod

答案2

row sep我认为我可以通过指出您可以类似地将接受的答案设置为负值来水平镜像图表来为对话添加一些内容。虽然原始问题描述的是垂直镜像。

\documentclass{article}
\usepackage{tikz-cd}
\tikzcdset{vdual/.style={column sep=#1,every label/.append style={swap},
arrows=leftarrow},
vdual/.default=-5.5em, ampersand replacement=\&}
\tikzcdset{hdual/.style={row sep=#1,every label/.append style={swap},
arrows=leftarrow},
hdual/.default=-5.5em, ampersand replacement=\&}

\begin{document}
\def\OriginalDiagram{C \arrow[rr] \arrow[drr, "\phi_x"] \arrow[ddrr]
\arrow[dd, "\exists! \Phi", dashed] \&\& \vdots \\
\&\& F(x) \\
\prod F \arrow[uurr] \arrow[urr, "\pi_x", swap] \arrow[rr] \&\& \vdots
}
Original diagram:
\[\begin{tikzcd}
\OriginalDiagram
\end{tikzcd}\]

Dual constructed by adding the pgf key \texttt{vdual} to the original diagram.
\[
\begin{tikzcd}[vdual]
\OriginalDiagram
\end{tikzcd}\]

Dual constructed by adding the pgf key \texttt{hdual} to the original diagram.
\[
\begin{tikzcd}[hdual]
\OriginalDiagram
\end{tikzcd}\]
\end{document}

结果

如果我没有遵守礼仪,请原谅。

相关内容