评论

评论

这是一个小的示例文档。

\documentclass[a4paper]{amsart}

\usepackage{tikz}

\newcommand{\dju}{\mathbin{\coprod}}
\DeclareMathOperator{\id}{id}

\begin{document}

\begin{tikzpicture}[x = 45mm, y = 30mm]
    \node (gh)   at (0, 1) {$  G  \dju   H $};
    \node (fgh)  at (1, 1) {$f(G) \dju   H $};
    \node (ggh)  at (0, 0) {$  G  \dju g(H)$};
    \node (fggh) at (1, 0) {$f(G) \dju g(H)$};
    \begin{scope}[->]
        \draw (gh.east) -- (fgh.west)
              node [midway, above] {$f \dju \id_H$};
        \draw (gh.south) -- (ggh.north)
              node [midway, left] {$\id_G \dju g$};
        \draw (gh.south east) -- (fggh.north west)
              node [midway, above right] {$f \dju g$};
        \draw (fgh.south) -- (fggh.north)
              node [midway, right] {$\id_{f(G)} \dju g$};
        \draw (ggh.east) -- (fggh.west)
              node [midway, below] {$f \dju \id_{g(H)}$};
    \end{scope}
\end{tikzpicture}

\end{document}

当我编译该文档时,它看起来是这样的:

此图看起来相当合理,但如果垂直和水平箭头以不相交并集符号 ( \coprod) 为中心,可能会看起来更好。对角箭头可能应该保持原样,从域的右侧加数的右下角指向余域的左侧加数的左上角。这是我在 mspaint 中摆弄后的上图,向您展示我的意思:

您将如何让 TikZ 绘制这样的图表?我想到的一个方法是将四个节点中的每一个节点都取出,并将\dju和两个加数变成单独的节点,每个加数相对于\dju节点定位。但是,如果这样做,不同符号的数学模式间距是否能够被模仿并不明显。

无关问题:在此图中的两处,不相交并集符号右侧的间距似乎不正确。当数学运算符在左侧而普通字母在右侧时,似乎会发生这种情况。为什么会发生这种情况?如果将序言中\id的 更改为 ,则不会发生这种情况,但这也会使所有间距变大。如果 被完全删除,效果就会消失。我承认我不记得为什么把它放在主文档中。\mathbin\mathord\mathbin

答案1

评论

我没有改变 Harish 的解决方案。我只是重新实现了它,用来tikz-cd显示缩短的代码。

执行

\documentclass[a4paper]{amsart}
\usepackage{tikz-cd}
\newcommand{\dju}{\mathbin{\coprod}}
\DeclareMathOperator{\id}{id}
\newcommand{\Ga}{\hphantom{f()}G}
\newcommand{\Ha}{H\hphantom{g()}}
\begin{document}
No additional scaling:

\begin{tikzcd}
    \Ga  \dju \Ha \arrow{dr}{f \dju \id_{g(H)}} \arrow{d}{\id_G \dju g} \arrow{r}{f \dju \id_H} & f(G) \dju \Ha \arrow{d}{\id_{f(G)} \dju g} \\
    \Ga  \dju g(H) \arrow{r}{f \dju \id_{g(H)}}                                                 & f(G) \dju g(H)
\end{tikzcd}

Increased \texttt{row sep} and \texttt{column sep}:

\begin{tikzcd}[row sep=huge, column sep=huge]
    \Ga  \dju \Ha \arrow{dr}{f \dju \id_{g(H)}} \arrow{d}{\id_G \dju g} \arrow{r}{f \dju \id_H} & f(G) \dju \Ha \arrow{d}{\id_{f(G)} \dju g} \\
    \Ga  \dju g(H) \arrow{r}{f \dju \id_{g(H)}}                                                 & f(G) \dju g(H)
\end{tikzcd}
\end{document}

输出

在此处输入图片描述

答案2

事情可能会变得糟糕……我们可以使用phantom力量。

\documentclass[a4paper]{amsart}

\usepackage{tikz}

\newcommand{\dju}{\mathbin{\coprod}}
\DeclareMathOperator{\id}{id}
\newcommand{\Ga}{\hphantom{f()}G}
\newcommand{\Ha}{H\hphantom{g()}}
\begin{document}

\begin{tikzpicture}[x = 45mm, y = 30mm]
    \node (gh)   at (0, 1) {$  \Ga  \dju   \Ha $};
    \node (fgh)  at (1, 1) {$f(G) \dju   \Ha $};
    \node (ggh)  at (0, 0) {$  \Ga  \dju g(H)$};
    \node (fggh) at (1, 0) {$f(G) \dju g(H)$};
    \begin{scope}[->]
        \draw[shorten <= -3ex] (gh.east) -- (fgh.west)
              node [midway, above] {$f \dju \id_H$};
        \draw (gh.south) -- (ggh.north)
              node [midway, left] {$\id_G \dju g$};
        \draw (gh.335) -- (fggh.north west)
              node [midway, above right] {$f \dju g$};
        \draw (fgh.south) -- (fggh.north)
              node [midway, right] {$\id_{f(G)} \dju g$};
        \draw (ggh.east) -- (fggh.west)
              node [midway, below] {$f \dju \id_{g(H)}$};
    \end{scope}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案3

正是 Harish 的回答让我想到了这个答案。但是,我将其作为单独的答案发布,因为最终结果完全不同。Harish,你的回答非常出色,并给出了良好的结果,我只是想知道是否有一种方法可以做到这一点而不弄虚作假(例如,shorten <= -3ex你的代码来自哪里?反复试验?)我们需要准确地知道箭头要缩短多少,这需要使用框和长度。

\documentclass[a4paper]{amsart}

\usepackage{tikz}

\newcommand{\dju}{\mathbin{\coprod}}
\DeclareMathOperator{\id}{id}

\newlength{\lenA}
\newlength{\lenB}
\newlength{\lenC}
\newlength{\lenD}
\newlength{\lenE}
\newsavebox{\saveboxA}
\newsavebox{\saveboxB}
\newsavebox{\saveboxC}
\newsavebox{\saveboxD}

\begin{document}

\begin{tikzpicture}[x = 55mm, y = 35mm]
    \settowidth{\lenA}{$G$}
    \settowidth{\lenB}{$H$}
    \settowidth{\lenC}{$f(G)$}
    \settowidth{\lenD}{$g(H)$}
    \pgfmathsetlength{\lenE}{max(\lenC, \lenD)}
    \savebox{\saveboxA}[\lenE][r]{$G$}
    \savebox{\saveboxB}[\lenE][r]{$f(G)$}
    \savebox{\saveboxC}[\lenE][l]{$H$}
    \savebox{\saveboxD}[\lenE][l]{$g(H)$}
    \pgfmathsetlength{\lenB}{\lenB - \lenE}
    \pgfmathsetlength{\lenC}{\lenE - \lenC}
    \pgfmathsetlength{\lenD}{\lenD - \lenE}
    \node (gh)   at (0, 1) {$\usebox{\saveboxA} \dju \usebox{\saveboxC}$};
    \node (fgh)  at (1, 1) {$\usebox{\saveboxB} \dju \usebox{\saveboxC}$};
    \node (ggh)  at (0, 0) {$\usebox{\saveboxA} \dju \usebox{\saveboxD}$};
    \node (fggh) at (1, 0) {$\usebox{\saveboxB} \dju \usebox{\saveboxD}$};
    \path (gh.east)         -- ++(\lenB, 0) coordinate (mghfghstart);
    \path (fgh.west)        -- ++(\lenC, 0) coordinate (mghfghend);
    \path (gh.south east)   -- ++(\lenB, 0) coordinate (mghfgghstart);
    \path (fggh.north west) -- ++(\lenC, 0) coordinate (mghfgghend);
    \path (ggh.east)        -- ++(\lenD, 0) coordinate (mgghfgghstart);
    \path (fggh.west)       -- ++(\lenC, 0) coordinate (mgghfgghend);
    \begin{scope}[->, every node/.style = {midway}]
        \draw (mghfghstart)   -- (mghfghend)   node [above]       {$f \dju \id_H$};
        \draw (gh.south)      -- (ggh.north)   node [left]        {$\id_G \dju g$};
        \draw (mghfgghstart)  -- (mghfgghend)  node [above right] {$f \dju g$};
        \draw (fgh.south)     -- (fggh.north)  node [right]       {$\id_{f(G)} \dju g$};
        \draw (mgghfgghstart) -- (mgghfgghend) node [below]       {$f \dju \id_{g(H)}$};
    \end{scope}
\end{tikzpicture}

\end{document}

周围间距不好的谜团\mathbin{\coprod}仍然存在,但与这个问题的主题无关。(我试图定义\dju\amalg,但在同样的情况下,它的间距也很糟糕。)对于那些建议使用 tikz-cd 的人,我会的,但对于我目前的文档,我没有要绘制许多交换图,而且当普通的 TikZ 具有足够的功能来完成我想要做的事情时,我觉得采用新的方式做事不会给我带来很大的好处。

答案4

只是为了使用普通 TeX 的数学模式而好玩。

\def\dju{\mathbin{\coprod}}
\def\id{\mathop{\rm id}}
\def\Ga{\hphantom{f()}G}
\def\Ha{H\hphantom{g()}}
\def\rar#1{\buildrel {#1} \over {\hbox to 4em{\rightarrowfill}}}
\def\dar#1{\Bigg\downarrow\rlap{$\scriptstyle#1$}}
\def\drar#1{\searrow\raise1ex\rlap{$\scriptstyle#1$}}
$$
\matrix{
  \Ga\dju \Ha           & \rar{f\dju\id_H}       & f(G)\dju \Ha\cr
  \noalign{\vskip2ex}
  \dar{\id_G\dju g} & \drar{f\dju g}         & \dar{\id_{f(G)}\dju g} \cr
  \noalign{\vskip1ex}
  \Ga\dju g(H)        & \rar{f\dju\id_{g(H)}}  & f(G)\dju g(H)\cr
}
$$
\bye

在此处输入图片描述

相关内容