答案1
@clara 答案的变体,其中单元格内容周围的垂直空间增加了 5pt 并重新组织了表格序言:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{hlines, vlines,
colspec = {*{2}{Q[c,wd=2em, mode=dmath]}}, % <--- changed
row{1} = {bg=green},
rowsep = 5pt % <--- added
}
x & g(x) \\
0 & \\
3 & \\
-2 & \\
\frac{3}{4} & \\
\frac{-1}{2} & \\
& 0 \\
& 5 \\
& -3 \\
\end{tblr}
\end{document}
答案2
更新:使用dmath
模式。
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\begin{document}
\begin{tblr}
{
colspec = {Q[c,m]Q[c,m]},
hlines,vlines,
row{1} = {bg=green},
cells = {mode=dmath},
}
x & g(x) \\
0 & \\
3 & \\
-2 & \\
\frac{3}{4} & \\
\frac{-1}{2} & \\
& 0 \\
& 5 \\
& -3 \\
\end{tblr}
\end{document}
答案3
与。{NiceTabular}
nicematrix
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}{cc}[hvlines,colortbl-like,cell-space-limits=3pt]
\rowcolor{green} $x$ & $g(x)$ \\
$0$ & \\
$3$ & \\
$-2$ & \\
$\dfrac{3}{4}$ & \\
$\dfrac{-1}{2}$ & \\
& $0$ \\
& $5$ \\
& $-3$ \\
\end{NiceTabular}
\end{document}
答案4
\documentclass[a4paper,12pt]{article}
\usepackage{amsmath,amssymb}
\usepackage{colortbl}
\begin{document}
{\renewcommand{\arraystretch}{2.5}\begin{tabular}{| c | c |}
\hline
\rowcolor{green} $x$ & $g(x)$ \\ \hline
$0$ & \\ \hline
$3$ & \\ \hline
$-2$ & \\ \hline
$\dfrac{3}{4}$ & \\ \hline
$-\dfrac{1}{2}$ & \\ \hline
& $0$ \\ \hline
& $5$ \\ \hline
& $-3$ \\ \hline
\end{tabular}}
\end{document}