其中两行的高度约为 3 厘米。第 2 行第 1 列被规划为类似多列的形式。
但首先,我遇到了第 1 行最后一列的问题。
我该如何正确设置措施?
顺便说一句:对于其他一些东西,我需要如图所示的坐标,所以我认为使用 TikZ 矩阵并不是坏主意。
\documentclass[]{scrartcl}
\usepackage{lmodern}
\usepackage[showframe=true,
width=18cm, height=26cm,
]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc, matrix}
\usepackage{tikzpagenodes}
\pagestyle{empty}
\pgfmathsetlengthmacro\InnerSep{5pt}
\pgfmathsetlengthmacro\ColumnSep{3mm}
\begin{document}
\begin{tikzpicture}[
shift={(current page text area.center)},
overlay,remember picture,
nodes={inner sep=0pt,outer sep=0pt},
Header/.style={
nodes={draw=blue,
minimum width=3cm, minimum height=3cm, text width=3cm-\InnerSep, }
},
]
% For comparison %%%%%%%%%%%%%%%%%%
\node[anchor=north west, inner sep=0pt,outer sep=0pt,
cyan, draw,
minimum width=1.0\textwidth,
%text width=1.0\textwidth-\InnerSep,
text height=5.5cm,
minimum height=6cm,
%text depth=6cm-4mm,
align=left,
] at (-0.5\textwidth, 0.5\textheight) (Textbox) {For comparison: This dimension should the matrix have!};
%%%%%%%%%%%%%%%%%%%%%%%%%
% Textbox
\matrix[matrix of nodes, nodes in empty cells,
%inner sep=\pgflinewidth,
column sep=\ColumnSep,
anchor=north west,
draw=red,
nodes={inner sep=\InnerSep, outer sep=0pt, anchor=north west, align=center},
row 1 column 1/.style={Header, draw, very thick},
row 1 column 2/.style={Header},
row 1 column 3/.style={
nodes={draw=brown,
text=blue, draw=blue, align=left,
minimum width=\textwidth-2*3cm-2*\ColumnSep-2*\InnerSep-4*\pgflinewidth,
minimum height=3cm,
text width=\textwidth-2*3cm-2*\ColumnSep-4*\InnerSep-4*\pgflinewidth,
text depth=3cm-2*\InnerSep, % Error
}
},
] at (-0.5\textwidth, 0.5\textheight)
{
X & Y & 3 3 3 3 \\
1 & 2 & 3 \\
};
\end{tikzpicture}
\end{document}
答案1
它必须是3*\pgflinewidth
而不是4*\pgflinewidth
。为什么是 3?因为 2 太少而 4 太多。 ;-) 好吧,更严重的是,只有 50% 的线宽在节点内。因此有两个错误朝着相反的方向发展。你似乎没有考虑到外边界,所以你应该放6*\pgflinewidth
,但你只需要 50% 就使其成为3*\pgflinewidth
。除此之外,如果你设置了文本深度并希望获得特定的目标高度,你还需要设置文本高度。
\documentclass[]{scrartcl}
\usepackage{lmodern}
\usepackage[showframe=true,
width=18cm, height=26cm,
]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc, matrix}
\usepackage{tikzpagenodes}
\pagestyle{empty}
\pgfmathsetlengthmacro\InnerSep{5pt}
\pgfmathsetlengthmacro\ColumnSep{3mm}
\begin{document}
\begin{tikzpicture}[
shift={(current page text area.center)},
overlay,remember picture,
nodes={inner sep=0pt,outer sep=0pt},
Header/.style={
nodes={draw=blue,
minimum width=3cm, minimum height=3cm, text width=3cm-\InnerSep, }
},
]
% For comparison %%%%%%%%%%%%%%%%%%
\node[anchor=north west, inner sep=0pt,outer sep=0pt,
cyan, draw,
minimum width=1.0\textwidth,
%text width=1.0\textwidth-\InnerSep,
text height=5.5cm,
minimum height=6cm,
%text depth=6cm-4mm,
align=left,
] at (-0.5\textwidth, 0.5\textheight) (Textbox) {For comparison: This dimension should the matrix have!};
%%%%%%%%%%%%%%%%%%%%%%%%%
% Textbox
\matrix[matrix of nodes, nodes in empty cells,
%inner sep=\pgflinewidth,
column sep=\ColumnSep,
anchor=north west,
draw=red,
nodes={inner sep=\InnerSep, outer sep=0pt, anchor=north west, align=center},
row 1 column 1/.style={Header, draw, very thick},
row 1 column 2/.style={Header},
row 1 column 3/.style={
nodes={text=blue, draw=blue, align=left,
minimum width=\textwidth-2*3cm-2*\ColumnSep-2*\InnerSep-3*\pgflinewidth,
minimum height=3cm,
text width=\textwidth-2*3cm-2*\ColumnSep-4*\InnerSep-3*\pgflinewidth,
text height=0.5cm,
text depth=2.5cm-2*\InnerSep,
}
},
] at (-0.5\textwidth, 0.5\textheight)
{
X & Y & 3 3 3 3 \\
1 & 2 & 3 \\
};
\end{tikzpicture}
\end{document}