![数学节点的静态节点距离 tikz 矩阵](https://linux22.com/image/282338/%E6%95%B0%E5%AD%A6%E8%8A%82%E7%82%B9%E7%9A%84%E9%9D%99%E6%80%81%E8%8A%82%E7%82%B9%E8%B7%9D%E7%A6%BB%20tikz%20%E7%9F%A9%E9%98%B5.png)
我想在 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
一种不太好的方式就是使用node
s 的角来连接,像这样:
(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}
。