\documentclass[a5paper,]{article}
\usepackage{amsmath}
% \usepackage{hyperref}
\usepackage{booktabs}
\usepackage{array}
\usepackage{tikz}
\newcolumntype{L}{>{$} m{1in}<{$}}
\newcommand{\myvector}{
\begin{vmatrix}
a_{11} & a_{12} & a_{13}\\
a_{21} & a_{22} & a_{23}\\
a_{31} & a_{32} & a_{33}\\
\end{vmatrix}}
\newcommand{\mybox}{
\begin{tikzpicture}
\draw (0,0) rectangle (1,1);
\end{tikzpicture}
}
\begin{document}
\begin{tabular}{| L | L | L |}
\toprule[1.5pt]
\myvector & & \myvector \\ \midrule
\myvector & \mybox & \myvector \\ \midrule
\myvector & & \myvector \\
\bottomrule[1.5pt]
\end{tabular}
\end{document}
输出:
(1)为什么 Tikz 绘图会导致额外的垂直空间?(请注意,第二行中的元素被向下推。)
(2) 有没有办法根据 Tikz 坐标在表格单元格内“找到自己的位置”?例如,如何从右下角到左上角绘制相同的图形;或者在单元格内水平和垂直居中?
答案1
编辑:看来我第一次尝试时误解了这个问题。希望现在我走在正确的轨道上......
您需要更改tikz
图像的基线:
\documentclass[a5paper,]{article}
\usepackage{amsmath}
\usepackage{array, makecell}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{hyperref}% had to be load last
\newcommand{\myvector}{
\begin{vmatrix}
a_{11} & a_{12} & a_{13}\\
a_{21} & a_{22} & a_{23}\\
a_{31} & a_{32} & a_{33}\\
\end{vmatrix}}
\tikzset{TN/.style = {% Table's Nodes style
baseline=(current bounding box.center),
node distance = 0mm,
M/.style = {minimum size=##1, inner sep=0pt},
N/.style args = {##1/##2}{draw=##1, minimum size=##2, inner sep=2pt,
align=center},
}}
\begin{document}
\[
\setcellgapes{5pt}
\makegapedcells
\begin{array}{| c | c | c |}
\Xhline{1.2pt}
\myvector & \tikz[TN]{
\node (n) [M=22mm] {};
\node[N=red/3mm, above left=of n.south east] {south\\east};
}
& \myvector \\ \hline
\myvector & \tikz[TN]{
\node (n) [N=none/22mm, fill=gray!50] {};
\node[N=red/3mm, above left=of n.south east] {};
\node[N=blue/3mm, below right=of n.north west] {};
\node[N=white/8mm] {};
\node[N=yellow/6mm, fill=yellow,
above right=6mm of n.south west] {}
}
& \myvector \\ \hline
\myvector & \tikz[TN]{
\node[N=black/12mm] {center};
}
& \myvector \\
\Xhline{1.2pt}
\end{array}
\]
\[
\setcellgapes{5pt}
\makegapedcells
\begin{array}{| c | c | c |}
\Xhline{1.2pt}
\myvector & \tikz[TN]{
\node[N=black/12mm] {center};
}
& \myvector \\
\Xhline{1.2pt}
\end{array}
\]
\end{document}
笔记:如果表中的列类型\makegapedcells
为宏,则不起作用m