我有以下代码
\documentclass[tikz,border=5mm]{standalone}
\usepackage{xcolor}
\begin{document}
\usetikzlibrary{matrix}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes,
nodes in empty cells,nodes={minimum width=5ex,
minimum height=5ex,outer sep=-5pt},
column sep=1ex,row sep=1ex]{
& & & & & & & & \\
\vdots & \vdots & \vdots & \vdots & \cdots & \vdots & \vdots & \vdots & \underline{E^k\textsf{ page}}\\
k & H_{k}(\Omega S^k) & 0 & 0 & \cdots & 0 & H_{k}(\Omega S^k) & 0 & \cdots\\
k-1 & H_{k-1}(\Omega S^k) & 0 & 0 & \cdots & 0 & H_{k-1}(\Omega S^k) & 0 & \cdots\\
k-2 & H_{k-2}(\Omega S^k) & 0 & 0 & \cdots & 0 & H_{k-2}(\Omega S^k) & 0 & \cdots\\
\vdots & \vdots & \vdots & \vdots & \cdots & \vdots & \vdots & \vdots & \cdots\\
3 & H_3(\Omega S^k) & 0 & 0 & \cdots & 0 & H_3(\Omega S^k) & 0 & \cdots\\
2 & H_2(\Omega S^k) & 0 & 0 & \cdots & 0 & H_2(\Omega S^k) & 0 & \cdots\\
1 & H_1(\Omega S^k) & 0 & 0 & \cdots & 0 & H_1(\Omega S^k) & 0 & \cdots\\
0 & H_0(\Omega S^k) & 0 & 0 & \cdots & 0 & H_0(\Omega S^k) &0 & \cdots\\
\quad\strut & 0 & 1 & 2 & \cdots & k-1 & k & k+1 & \cdots \strut \\};
\draw[thick, ->] (m-11-1.east) -- (m-1-1.east) ;
\draw[thick, ->] (m-11-1.north) -- (m-11-9.north) ;
\end{tikzpicture}
\end{document}
输出结果如下:
现在,正如您在该图像的左上角所看到的,“k-2”和“k-1”与“垂直轴”重叠。我怎样才能使这两个东西不重叠?
答案1
我会右对齐第一列的节点(因为它们看起来像是标签),增加列 sep,这是通过以下方式实现的
column 1/.style={nodes={text width=width("$k-2$"),align=right},column sep=2ex},
并移动轴。
\documentclass[tikz,border=5mm]{standalone}
\usepackage{xcolor}
\begin{document}
\usetikzlibrary{matrix}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes,
nodes in empty cells,nodes={minimum width=5ex,
minimum height=5ex,outer sep=-5pt},column sep=1ex,row sep=1ex,
column 1/.style={nodes={text width=width("$k-2$"),align=right},column sep=2ex},
]{
& & & & & & & & \\
\vdots & \vdots & \vdots & \vdots & \cdots & \vdots & \vdots & \vdots & \underline{E^k\textsf{ page}}\\
k & H_{k}(\Omega S^k) & 0 & 0 & \cdots & 0 & H_{k}(\Omega S^k) & 0 & \cdots\\
k-1 & H_{k-1}(\Omega S^k) & 0 & 0 & \cdots & 0 & H_{k-1}(\Omega S^k) & 0 & \cdots\\
k-2 & H_{k-2}(\Omega S^k) & 0 & 0 & \cdots & 0 & H_{k-2}(\Omega S^k) & 0 & \cdots\\
\vdots & \vdots & \vdots & \vdots & \cdots & \vdots & \vdots & \vdots & \cdots\\
3 & H_3(\Omega S^k) & 0 & 0 & \cdots & 0 & H_3(\Omega S^k) & 0 & \cdots\\
2 & H_2(\Omega S^k) & 0 & 0 & \cdots & 0 & H_2(\Omega S^k) & 0 & \cdots\\
1 & H_1(\Omega S^k) & 0 & 0 & \cdots & 0 & H_1(\Omega S^k) & 0 & \cdots\\
0 & H_0(\Omega S^k) & 0 & 0 & \cdots & 0 & H_0(\Omega S^k) &0 & \cdots\\
\quad\strut & 0 & 1 & 2 & \cdots & k-1 & k & k+1 & \cdots \strut \\};
\draw[thick, ->] ([xshift=2ex]m-11-1.east) -- ([xshift=2ex]m-1-1.east) ;
\draw[thick, ->] ([yshift=1ex]m-11-1.north) -- ([yshift=1ex]m-11-9.north) ;
\end{tikzpicture}
\end{document}