答案1
通过使用tabularray
包和单独的窄列来表示数字:
\documentclass{article}
\usepackage{geometry}
\usepackage{amssymb, mathtools}
%\usepackage{newtxtext, newtxmath}
\usepackage{tabularray}
\begin{document}
\begin{table}[!th]
\begin{tblr}{hlines,
colspec = {|X[1,l] | X[1,l] |
*{3}{Q[r,h, font=\bfseries] X[2,c,m,mode=dmath] |}},
colsep = 3pt,
rowsep = 3pt,
row{1} = {font=\small\bfseries, c, m}
}
Elements of N
& Elements of X
& \SetCell[c=2]{c} Any $f$
& & \SetCell[c=2]{c} Injective $f$
& & \SetCell[c=2]{c} Surjective $f$
& \\
dist.
& dist.
&1. & x^n
&2. & (x)_n
& 3. & x!S(n.x)
\\
indist.
& dist.
&4. & \left(\binom{x}{n}\right)
&5. & \binom{x}{n}
& 6. & \left(\binom{x}{n-x}\right)
\\
dist.
& indist.
&7. & \begin{multlined}
S(n,0) + S(n,1)\\
+\dots + S(n,x)
\end{multlined}
&8. & \begin{aligned}
1 & \quad \mathrm{if}\ n\leqslant x \\
0 & \quad \mathrm{if}\ n > x
\end{aligned}
& 9. & S(n,x)
\\
indist.
& indist.
&10.& \begin{multlined}
p_0(n) + p_1(n)\\
+\dots + p_x(x)
\end{multlined}
&11.& \begin{aligned}
1 & \quad \mathrm{if}\ n\leqslant x \\
0 & \quad \mathrm{if}\ n > x
\end{aligned}
&12. & p_x(n)
\\
\end{tblr}
\end{table}
\end{document}
附录: 表格设计可能略有不同,前两列较窄,其他列(带有数学表达式)较宽:
为此,对tblr
序言和列标题进行了以下更改:
% document preamble
% ...
\begin{tblr}{hlines,
colspec = {| l | l | % <---
*{3}{Q[r,h, font=\bfseries] X[c,m,mode=dmath] |},% <---
colsep = 3pt,
rowsep = 4pt,
row{1,2}= {font=\small\bfseries, c, m, rowsep=1pt} % <---
}
\SetCell[c=2]{c} Elements of: % <--- new
& & \SetCell[c=2, r=2]{c} Any $f$ % <---
& & \SetCell[c=2,r=2]{c} Injective $f$ % <---
& & \SetCell[c=2,r=2]{c} Surjective $f$ % <---
& \\
X & Y & & & & & & \\ % <--- new
%% table body
答案2
使用,您可以{NiceTabular}
在nicematrix
使用 Tikz 构建主表格后将数字放入单元格中。
\documentclass{article}
\usepackage{geometry}
\usepackage{amssymb}
\usepackage{nicematrix,tikz}
\begin{document}
\begin{table}[!th]
\begin{NiceTabular}{ccX[c]X[c]X[c]}[width=\linewidth,hvlines,cell-space-limits=3pt]
\RowStyle[bold,cell-space-limits=5pt]{}
\Block{}{Elements\\ of N}
& \Block{}{Elements\\ of X}
& Any $f$
& Injective $f$
& Surjective $f$ \\
dist.
& dist.
& $x^n$
& $(x)_n$
& $x!S(n,x)$ \\
indist.
& dist.
& $\left(\binom{x}{n}\right)$
& $\binom{x}{n}$
& $\left(\binom{x}{n-x}\right)$ \\
dist.
& indist.
& $\begin{aligned}
S(n,0) + S(n,1)\\
+\dots + S(n,x)
\end{aligned}$
& $\begin{aligned}
1 & \quad \mathrm{if}\ n\leqslant x \\
0 & \quad \mathrm{if}\ n > x
\end{aligned}$
& $S(n,x)$ \\
indist.
& indist.
& $\begin{aligned}
p_0(n) + p_1(n)\\
+\dots + p_x(x)
\end{aligned}$
& $\begin{aligned}
1 & \quad \mathrm{if}\ n\leqslant x \\
0 & \quad \mathrm{if}\ n > x
\end{aligned}$
& $p_x(n)$ \\
\CodeAfter
\newcounter{cell}
\begin{tikzpicture}
\foreach \i in {2,3,4,5}
\foreach \j in {3,4,5}
{
\stepcounter{cell}
\node [below right] at (\i-|\j) { \bfseries \small \thecell } ;
} ;
\end{tikzpicture}
\end{NiceTabular}
\end{table}
\end{document}
由于创建的 PGF/Tikz 节点,您需要进行多次编译nicematrix
。