数学节点的静态节点距离 tikz 矩阵

数学节点的静态节点距离 tikz 矩阵

我想在 tikz 中绘制下图,

    \documentclass[b5paper,10pt,twoside]{book}
    \usepackage[hmarginratio=1:1]{geometry}
    \usepackage{tikz}
    \usetikzlibrary{arrows,calc,through,backgrounds,matrix,decorations.pathmorphing}
    \begin{document}

    \begin{center}
    \begin{tikzpicture}
    \matrix(m)[matrix of math nodes, row sep=2em, column sep=2em, text height=1.5ex, text depth=0.25ex]
    {X        & \,        & Z         & \,        & Z/Y      & \,       & (Y/X)[1]   \\
    \,        & Y         & \,        & Z/X       & \,       & Y[1]     &         \,         \\
    \,        & \,        & Y/X       & \,        & X[1]     & \,       &         \,         \\};
    \path[->,font=\scriptsize]
    %top arrows
    (m-1-1) edge[bend left =45] node[above] {$g\circ f    $} (m-1-3)
    (m-1-3) edge[bend left =45] node[above] {$            $} (m-1-5)
    (m-1-5) edge[bend left =45] node[above] {$\theta      $} (m-1-7)
    %lower edge border arrows
    (m-1-1) edge                node[below] {$            $} (m-2-2)
    (m-2-2) edge                node[below] {$            $} (m-3-3)
    (m-3-3) edge[bend right=45] node[below] {$            $} (m-3-5)
    (m-3-5) edge                node[below] {$            $} (m-2-6)
    (m-2-6) edge                node[below] {$            $} (m-1-7)

    %completing second dt
    (m-2-2) edge                node[below] {$            $} (m-1-3)
    (m-1-5) edge                node[below] {$            $} (m-2-6)
    ;
    \path[dashed,->,font=\scriptsize]
    (m-1-3) edge                node[above] {$            $} (m-2-4)
    (m-2-4) edge                node[above] {$            $} (m-3-5)

    (m-3-3) edge                node[above] {$            $} (m-2-4)
    (m-2-4) edge                node[above] {$            $} (m-1-5)
    ;
    \end{tikzpicture}
    \end{center}

    \end{document}

但似乎由于右侧节点中的文本比左侧节点中的文本长,左侧的小工具“披萨片”比右侧的小工具小。 在此处输入图片描述

有谁知道如何强制节点之间的距离相等,这可能适用于此特定图表。对于同一文档中的其他一些图表,我猜我无法更改前提。谢谢!

答案1

更新答案

pgfmanual有时在回答问题之前最好先看看。我之前的答案是正确的,但重读“矩阵和对齐”部分后,我发现了between origins更好地解决 nunatak 问题的选项。

/tikz/column sep=<spacing list>

此选项设置在每两列之间添加的默认空格。 [...]

更一般地, 可能包含一整串数字,用逗号分隔,以及两个关键词between origins和的出现between borders。[...] 但是,如果最后一个出现的是between origins,则会发生以下情况:调整列之间的距离,以使第一列中所有单元格的原点(记住它们都位于直线上)与第二列中所有单元格的原点之间的差异恰好是给定的距离。

between origins选项只能用于第一行中提到的列,也就是说,您不能为仅在后面的行中引入的列指定此选项。

因此,只需更改column sep=3em选项column sep={3em, betweens origins}matrix调整问题就解决了。

在此处输入图片描述

原始答案

Amatrix可帮助您轻松放置节点,但row尺寸column是根据节点文本计算的。如果您想避免错位由于节点大小的差异,您可以使用on grid某些node distance功能轻松地根据节点的中心而不是边界来定位节点。

下一个代码显示了如何解决您的问题。我保留了节点的名称以避免更改edge命令。我还画了一个grid来显示节点的放置方式。

\documentclass[b5paper,10pt,twoside]{book}
\usepackage[hmarginratio=1:1]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{center}
\begin{tikzpicture}

\draw[black!30] (0,0) grid [xstep=1.5cm, ystep=1.5cm] (9,-3.5);
\begin{scope}[on grid, node distance=3cm]
\node (m-1-1) at (0,0) {$X$};
\node[right=of m-1-1] (m-1-3) {$Z$};
\node[right=of m-1-3] (m-1-5) {$Z/Y$};
\node[right=of m-1-5] (m-1-7) {$(Y/X)[1]$};

\node[below right= 1.5cm and 1.5cm of m-1-1] (m-2-2) {$Y$};
\node[right=of m-2-2] (m-2-4) {$Z/X$};
\node[right=of m-2-4] (m-2-6) {$Y[1]$};

\node[below right= 1.5cm and 1.5cm of m-2-2] (m-3-3) {$Y/X$};
\node[right=of m-3-3] (m-3-5) {$X[1]$};
\end{scope}

    \path[->,font=\scriptsize]
%top arrows
(m-1-1) edge[bend left =45] node[above] {$g\circ f    $} (m-1-3)
(m-1-3) edge[bend left =45] node[above] {$            $} (m-1-5)
(m-1-5) edge[bend left =45] node[above] {$\theta      $} (m-1-7)
%lower edge border arrows
(m-1-1) edge                node[below] {$            $} (m-2-2)
(m-2-2) edge                node[below] {$            $} (m-3-3)
(m-3-3) edge[bend right=45] node[below] {$            $} (m-3-5)
(m-3-5) edge                node[below] {$            $} (m-2-6)
(m-2-6) edge                node[below] {$            $} (m-1-7)

%completing second dt
(m-2-2) edge                node[below] {$            $} (m-1-3)
(m-1-5) edge                node[below] {$            $} (m-2-6)
;
\path[dashed,->,font=\scriptsize]
(m-1-3) edge                node[above] {$            $} (m-2-4)
(m-2-4) edge                node[above] {$            $} (m-3-5)

(m-3-3) edge                node[above] {$            $} (m-2-4)
(m-2-4) edge                node[above] {$            $} (m-1-5)
;
\end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

答案2

一种不太好的方式就是使用nodes 的角来连接,像这样:

(m-1-1.north east) edge[bend left =45] node[above] {$g\circ f    $} (m-1-3.north west)

有一些minimum width定义(我将其保持为的宽度$(Y/X)$。你可以调整它。)

\documentclass[b5paper,10pt,twoside]{book}
\usepackage[hmarginratio=1:1]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,through,backgrounds,matrix,decorations.pathmorphing}
\begin{document}

\begin{center}
\begin{tikzpicture}
\matrix(m)[matrix of math nodes, row sep=2em, column sep=2em, text height=1.5ex, text depth=0.25ex,minimum width=\widthof{$(Y/X)$}]
{X        & \,        & Z         & \,        & Z/Y      & \,       & (Y/X)[1]   \\
\,        & Y         & \,        & Z/X       & \,       & Y[1]     &         \,         \\
\,        & \,        & Y/X       & \,        & X[1]     & \,       &         \,         \\};
\path[->,font=\scriptsize]
%top arrows
(m-1-1.north east) edge[bend left =45] node[above] {$g\circ f    $} (m-1-3.north west)
(m-1-3.north east) edge[bend left =45] node[above] {$            $} (m-1-5.north west)
(m-1-5.north east) edge[bend left =45] node[above] {$\theta      $} (m-1-7.north west)
%lower edge border arrows
(m-1-1.south east) edge                node[below] {$            $} (m-2-2.north west)
(m-2-2.south east) edge                node[below] {$            $} (m-3-3.north west)
(m-3-3.south east) edge[bend right=45] node[below] {$            $} (m-3-5.south west)
(m-3-5.north east) edge                node[below] {$            $} (m-2-6.south west)
(m-2-6.north east) edge                node[below] {$            $} (m-1-7.south west)

%completing second dt
(m-2-2.north east) edge                node[below] {$            $} (m-1-3.south west)
(m-1-5.south east) edge                node[below] {$            $} (m-2-6.north west)
;
\path[dashed,->,font=\scriptsize]
(m-1-3.south east) edge                node[above] {$            $} (m-2-4.north west)
(m-2-4.south east) edge                node[above] {$            $} (m-3-5.north west)

(m-3-3.north east) edge                node[above] {$            $} (m-2-4.south west)
(m-2-4.north east) edge                node[above] {$            $} (m-1-5.south west)
;
\end{tikzpicture}
\end{center}

\end{document}

在此处输入图片描述

相关内容