我正在尝试使用 tikz 在 LaTeX 中绘制光谱序列。我想绘制连接相邻节点的箭头;我已经画了第一个,但它看起来不是水平的。有人知道我该如何解决这个问题吗?
\documentclass{article}
\usepackage{tikz}
\usepackage{dsfont}
\usepackage{pinlabel}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amscd}
\usepackage{txfonts}
\usepackage{geometry}
\usetikzlibrary{matrix,calc,arrows}
\newcommand*\Z{\mathds{Z}}
\newcommand*\ZZ{|[draw,circle]| \Z_2}
\newcommand{\athir}[2]{\displaystyle \bigoplus_{\sigma^{#1}\in C_{#1}}K_{#2} (\mathbb{Z} [G_{\sigma^{#1}}])}
\geometry{lmargin=2.5cm,rmargin=2.5cm,tmargin=3cm,bmargin=3cm}
\parskip= 6pt
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes,
nodes in empty cells,
nodes={minimum width=10ex,
minimum height=10ex,
outer sep=-5pt},
column sep=1ex, row sep=1ex,
text centered,anchor=center]{
q\strut & 0 \strut & \athir{0}{q} & \athir{1}{q} & \cdots & \athir{p}{q} & \cdots \\
\vdots& \vdots & \vdots & \vdots & \ddots & \vdots & \cdots \\
1 & 0 & \athir{0}{1} & \athir{1}{1} & \cdots & \athir{p}{1} & \cdots \\
0 & 0 & \athir{0}{0} & \athir{1}{0} & \cdots & \athir{p}{0} & \cdots \\
-1 & 0 & \athir{0}{-1} & \athir{1}{-1} & \cdots & \athir{p}{-1}& \cdots \\
-2 & 0 & 0 & 0 & & 0 & \cdots \\
\quad\strut & -1 & 0 & 1 & \cdots & p & \strut \\};
\draw[-stealth] (m-1-3) -- (m-1-2);
\draw[thick] (m-1-1.north east) -- (m-7-1.east) ;
\draw[thick] (m-7-1.north) -- (m-7-7.north east) ;
\end{tikzpicture}
\end{document}
答案1
您有两个选择。例如,您可以增加最小节点高度
\matrix (m) [matrix of math nodes,
nodes in empty cells,
nodes={minimum width=5ex, minimum height=7ex,
inner sep=3pt, outer sep=0pt, anchor=north},
column sep=2ex, row sep=0ex]
或者,您可以使用以下语法绘制箭头。
\draw[-stealth] (m-1-3) -- (m-1-3 |- m-1-2.east);
使用第一个选项我得到了该矩阵的以下图片:
附录:根据第二条建议,完成并略微改进了代码(进行了一些手动调整以使矩阵看起来更好):
\documentclass[border=3mm,tikz,preview]{standalone}
\usetikzlibrary{arrows,calc,matrix}
\usepackage{dsfont,txfonts}
\usepackage{amssymb}
%\usepackage{amsfonts,amsmath,amscd,pinlabel,geometry}
\newcommand*\Z{\mathds{Z}}
\newcommand*\ZZ{|[draw,circle]| \Z_2}
\newcommand{\athir}[2]{\displaystyle\bigoplus_{\sigma^{#1}\in C_{#1}}K_{#2} (\mathbb{Z} [G_{\sigma^{#1}}])}
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes,
nodes in empty cells,
nodes={minimum width=5ex, minimum height=6ex,
text depth=1ex,
inner sep=0pt, outer sep=0pt,
anchor=base},
column sep=2ex, row sep=2ex]%
{
q & 0 & \athir{0}{q} & \athir{1}{q} & \cdots & \athir{p}{q} & \cdots \\
[5ex,between origins]
\vdots & \vdots & \vdots & \vdots & \ddots & \vdots & \cdots \\
[3ex,between origins]
1 & 0 & \athir{0}{1} & \athir{1}{1} & \cdots & \athir{p}{1} & \cdots \\
0 & 0 & \athir{0}{0} & \athir{1}{0} & \cdots & \athir{p}{0} & \cdots \\
-1 & 0 & \athir{0}{-1}& \athir{1}{-1}& \cdots & \athir{p}{-1}& \cdots \\
[5ex,between origins]
-2 & 0 & 0 & 0 & & 0 & \cdots \\
[3ex,between origins]
& -1 & 0 & 1 & \cdots & p & \strut \\
};
\draw[-stealth] (m-1-3) -- (m-1-3 -| m-1-2.east);
%
\draw[thick] (m-1-1.north east) -- (m-7-1.east) ;
\draw[thick] (m-7-1.north) -- ($(m-6-7.east)!0.5!(m-7-7.east)$) ;
\end{tikzpicture}
\end{document}
在矩阵中,前两行和后两行之间的距离是手动设置的,struts
省略了,因为节点使用了较小的minimum height
,inner sep
设置为0pt
并text depth=1ex
引入。节点的锚点也更改为anchor=base
。一方面,这更好地对齐了节点内容,另一方面,节点的对齐略有不匹配。因此,水平线的坐标确定为矩阵最后一列中最后两个单元格的中点。行距增加到2ex
。有了这个测量,矩阵对我来说似乎更好一些。