我希望排版一个涉及不同大小的盒子的数学方程式(在我的工作中代表不同大小的矩阵)。
到目前为止我所做的如下:
\documentclass{article}
\usepackage{tikz}
\tikzstyle{mymatrix} = [rectangle, draw = black, anchor=base]
\newcommand{\largetikzmatrix}[1]{\tikz[baseline=(x.base)]{\node[mymatrix,minimum width=35pt,minimum height=35pt,inner sep=0pt] (x) {\makebox[0pt]{\ensuremath{#1}}};}}
\newcommand{\talltikzmatrix}[1]{\tikz[baseline=(x.base)]{\node[mymatrix,minimum width=12pt, minimum height=35pt,inner sep=0pt] (x) {\makebox[0pt]{\ensuremath{#1}}};}}
\newcommand{\smalltikzmatrix}[1]{\tikz[baseline=(x.base)]{\node[mymatrix,minimum width=12pt, minimum height=12pt,inner sep=0pt] (x) {\makebox[0pt]{\ensuremath{#1}}};}}
\begin{document}
\[
\largetikzmatrix{Z_k}
=
\talltikzmatrix{N_k} \smalltikzmatrix{M_k}^{-1}
\]
\end{document}
请注意,我曾经\makebox[0pt]
确保节点内的文本不会使它们变大。我更喜欢下标和框之间有一点冲突,而不是增加节点大小(这会让事情变得更难理解)。
我唯一不满意的是 $N_k$ 节点和 $M_k$ 节点之间缺少间距。我希望间距与数学表达式中两个变量之间的间距相同。我曾寻找过类似的东西来确保\mathvar
图片被解释为数学变量(类似于\mathop
和\mathrel
),但我没有看到,坦率地说,我甚至不确定这是否真的是这里的问题。
我知道我可以\,
人为地在那里放一个来腾出一些空间,但如果我能理解为什么这里不使用 TeX“正常”数学间距以及如何解决这个问题,那就太好了。
答案1
数学表达式中的变量之间没有空格:
\[ a b c \]
给你
\
但是你可以用,,添加你想要的空间\quad
......这也与你的代码一起工作
\documentclass{article}
\usepackage{tikz}
\tikzstyle{mymatrix} = [rectangle, draw = black, anchor=base]
\newcommand{\largetikzmatrix}[1]{\tikz[baseline=(x.base)]{\node[mymatrix,minimum width=35pt,minimum height=35pt,inner sep=0pt] (x) {\makebox[0pt]{\ensuremath{#1}}};}}
\newcommand{\talltikzmatrix}[1]{\tikz[baseline=(x.base)]{\node[mymatrix,minimum width=12pt, minimum height=35pt,inner sep=0pt] (x) {\makebox[0pt]{\ensuremath{#1}}};}}
\newcommand{\smalltikzmatrix}[1]{\tikz[baseline=(x.base)]{\node[mymatrix,minimum width=12pt, minimum height=12pt,inner sep=0pt] (x) {\makebox[0pt]{\ensuremath{#1}}};}}
\begin{document}
\[
\largetikzmatrix{Z_k}
=
\talltikzmatrix{N_k}\ \smalltikzmatrix{M_k}^{-1}
\]
\end{document}
答案2
Ignasi 已经回答了空间问题,所以这只是tikz
绘图上的改进。
\documentclass{article}
\usepackage{tikz,amsmath}
\tikzset{ mymatrix/.style = {rectangle, draw = black, anchor=base},}
\newcommand{\largetikzmatrix}[1]{\tikz[baseline=(x.base)]{\draw[path picture={
\node[anchor=center] (x) at (path picture bounding box.center) {$#1$};
}] (-17pt,-17pt) rectangle (17pt,17pt);}}
\newcommand{\talltikzmatrix}[1]{\tikz[baseline=(x.base)]{\draw[path picture={
\node[anchor=center] (x) at (path picture bounding box.center) {$#1$};
}] (-6pt,-17pt) rectangle (6pt,17pt);}}
\newcommand{\smalltikzmatrix}[1]{\tikz[baseline=(x.base)]{\draw[path picture={
\node[anchor=center] (x) at (path picture bounding box.center) {$#1$};
}] (-6pt,-6pt) rectangle (6pt,6pt);}}
\begin{document}
\[
\largetikzmatrix{Z_k}
=
\talltikzmatrix{N_k}\ \smalltikzmatrix{M_k}^{-1}\]
\end{document}