相对于第二行+行放置矩阵似乎无法正常工作,就好像outer sep
没有设置为 0 一样。我放置了一个 x 坐标节点,我希望新矩阵左上角与第一个矩阵第二行右上角的高度相同。但垂直和水平方向都有间隙。
\documentclass[a4paper]{article}
\usepackage[verbose,vmargin=30mm,hmargin=20mm]{geometry}
\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{positioning, matrix,calc}
\tikzset{
texttable/.style={row sep=-\pgflinewidth,
column sep=-\pgflinewidth,outer sep=0pt,
nodes={anchor=center,outer sep=0pt,draw,
text width=#1,text depth=.5ex,text height=10pt, font=\large}}}
\setlength{\parindent}{0pt}
\begin{document}
\begin{tikzpicture}
\matrix at (0,0) [matrix of nodes, nodes in empty cells,
matrix anchor=north west,
texttable={2cm}, align=right] (tb)
{
abc & \node (c) {def};\\
ghi & \node (d) {jkl};\\
mno & pqr\\
stu & vwx\\
};
\coordinate [label=right:$A$] (ref) at ($(.5\textwidth,0)+(0mm,-3mm)$);
\fill (ref) circle (1pt);
\draw [blue] (d.north east) -- ++(60mm,0);
\draw [blue] (ref) -- ++(0mm,-15mm);
\matrix at (ref |- d.north east) [matrix of nodes, nodes in empty cells,
matrix anchor=north west,
texttable={2cm}, align=right] (tb2)
{
ABC & DEF\\
GHI & JKL\\};
\end{tikzpicture}
\end{document}
答案1
尽管我提出了上述意见,但我发现通过转移第二个矩阵的锚点来作弊并不愉快。
实际上,矩阵有自己的inner sep
,您可以将其设置为 0pt。然后,您必须将inner sep
节点设置为不同的大小。
我认为它应该像这样工作:
\documentclass[a4paper]{article}
\usepackage[verbose,vmargin=30mm,hmargin=20mm]{geometry}
\usepackage{tikz,tikzpagenodes}
\usetikzlibrary{positioning, matrix,calc}
\tikzset{
texttable/.style={row sep=-\pgflinewidth,
column sep=-\pgflinewidth,outer sep=0pt,
nodes={anchor=center,outer sep=0pt,draw,
text width=#1,text depth=.5ex,text height=10pt, font=\large}}}
\setlength{\parindent}{0pt}
\begin{document}
\begin{tikzpicture}
\matrix at (0,0) [matrix of nodes, nodes in empty cells,
matrix anchor=north west, nodes={inner sep=3pt},
texttable={2cm}, align=right] (tb)
{
abc & \node (c) {def};\\
ghi & \node (d) {jkl};\\
mno & pqr\\
stu & vwx\\
};
\coordinate [label=right:$A$] (ref) at ($(.5\textwidth,0)+(0mm,-3mm)$);
\fill (ref) circle (1pt);
\draw [blue] (d.north east) -- ++(60mm,0);
\draw [blue] (ref) -- ++(0mm,-15mm);
\matrix at (ref |- d.north east) [matrix of nodes, nodes in empty cells,
matrix anchor=north west, inner sep=0pt,nodes={inner sep=3pt},
texttable={2cm}, align=right] (tb2)
{
ABC & DEF\\
GHI & JKL\\};
\end{tikzpicture}
\end{document}
编辑
对于第二个矩阵,似乎inner sep=0pt
不是精确的设置。相反,最好使用inner sep=-0.5\pgflinewidth
,这样线条就会完全重合,如下图所示: