我正在尝试制作一个简单的(美观的)表格。表格环境无法在单元格中引入填充,因此我尝试使用 TikZ。但是我无法让单元格正确对齐。
如何使用节点矩阵(或其他任何矩阵)来获得一个具有圆角且每个单元格中元素居中的 3x3 表格?
我怎样才能使以下内容看起来有规律?
\begin{tikzpicture}
\matrix (mat) [matrix of nodes, row sep=-\pgflinewidth, nodes={draw=black, minimum width=3cm, minimum height=1cm}]
{
\emph{I tried} & Something
& ... \\
$X$ & $X_{X_{X_X}}$
& $f : x \to y \to z \to \tau \to \omega$ \\
$X$ & ${{X^X}^X}^X$
& $f : x \to y$ \\
};
\end{tikzpicture}
答案1
像这样?
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (mat) [matrix of nodes, row sep=-\pgflinewidth, draw, rounded corners, nodes={minimum width=3cm, minimum height=1cm}]
{
\emph{I tried} & Something
& ... \\
$X$ & $X_{X_{X_X}}$
& $f : x \to y \to z \to \tau \to \omega$ \\
$X$ & ${{X^X}^X}^X$
& $f : x \to y$ \\
};
\end{tikzpicture}
\end{document}
或这个?
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (mat) [matrix of nodes,
row sep=0pt,
column sep=0pt,
%draw,
rounded corners,
nodes={minimum width=3cm, minimum height=1cm, anchor=center}]
{
\emph{I tried} & Something
& ... \\
$X$ & $X_{X_{X_X}}$
& $f : x \to y \to z \to \tau \to \omega$ \\
$X$ & ${{X^X}^X}^X$
& $f : x \to y$ \\
};
%%As not all nodes fit in `minimum width|height`
%%We need to manually draw the boxes
\foreach \i in {1,2,3}{
\foreach \j in {1,2,3}
\draw[rounded corners] (mat-2-\i.west|-mat-\j-\i.north) rectangle (mat-2-\i.east|-mat-\j-\i.south);
}
\end{tikzpicture}
\end{document}