我有一张桌子
\documentclass[12pt,a4paper]{article}
\usepackage{tabularray}
\usepackage{fouriernc}
\usepackage{mathtools}
\UseTblrLibrary{amsmath,
booktabs,
counter,
diagbox,
siunitx,
varwidth}
\usepackage{enumitem}
\usepackage{ninecolors}
%\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\sisetup{output-decimal-marker={,}}
\usepackage{tikz}
\usepackage[paperwidth=19cm, paperheight=27cm,
hmargin=1.7cm,
vmargin={1.8cm,1.7cm}]{geometry}
\usepackage{hyperref}
\newcounter{mycnta}
\newcommand{\mycnta}{\stepcounter{mycnta}\arabic{mycnta}}
\newcommand{\startproblem}[1]{
\SetCell[r=#1]{c}\mycnta
}
\renewcommand{\arraystretch}{1.3}
\begin{document}
\begin{longtblr}[
expand=\startproblem,
caption={Test}]{
colspec = {Q[c]X[valign=m]Q[c]},
rowhead = 1,
vlines,
hlines,
row{1}={yellow9,font=\bfseries},
cell{1}{2-3}={halign=c},
cell{2}{2-3} ={gray9},
column{1}={font=\bfseries},
} Problem & Content & Point \\
\startproblem{4} &
$ \Delta =(-5)^2 - 4 \cdot 1 \cdot 6 = 1$, & \num{0.25} \\
& $ x = \dfrac{-(-5) -1}{2} = 2$. & \num{0.25} \\
& $ x = \dfrac{-(-5) + 1}{2} = 3$ & \num{0.25} \\
& The given equation has two solutions $x=2$ and $x = 3$. & \num{0.25} \\
\end{longtblr}
\end{document}
我想将第一列的文本对齐到列的顶部
我怎么才能得到它?
答案1
- 向多行单元格添加规范说明符
h
- 在 MWE 中,我简化了代码,即删除了
theme
定义及其使用,但是,如果您愿意,可以返回它们。
编辑:
考虑的是 OP 评论:
- 如果所有多行单元格跨越相同数量的行,则可以全局自动对“问题”进行编号
- 设置
mode=text
在 \multirow 单元格跨越行的最后一行,应通过指令手动插入SetCell{bg=gray9}
\documentclass[12pt,a4paper]{article}
\usepackage[paperwidth=19cm, paperheight=27cm,
hmargin=1.7cm, vmargin={1.8cm,1.7cm}]{geometry}
\usepackage{fouriernc}
\usepackage{ninecolors}
\usepackage{tabularray}
\UseTblrLibrary{amsmath, booktabs, counter,
diagbox, siunitx, varwidth}
\sisetup{output-decimal-marker={,}}
\newcounter{problem}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{enumitem}
\usepackage{tikz}
\usepackage{hyperref}
\begin{document}
\begin{longtblr}[
caption={Test}]{hlines, vlines,
colspec = {Q[c, h, font=\bfseries] X[l, mode=math] Q[c, si={table-format=1.2}]},
cell{2,6}{1} = {r=4}{h, cmd={\stepcounter{problem}\theproblem}, mode=text},
cell{2}{2-3} = {bg=gray9},
row{1} = {yellow9, font=\bfseries, mode=text},
rowsep = 5pt,
rowhead = 1,
}
Problem & Content & Point \\
& \Delta =(-5)^2 - 4 \cdot 1 \cdot 6 = 1,
& 0.25 \\
& x = \dfrac{-(-5) -1}{2} = 2.
& 0.25 \\
& x = \dfrac{-(-5) + 1}{2} = 3
& 0.25 \\
& \SetCell{mode=text}
The given equation has two solutions $x=2$ and $x = 3$.
& 0.25 \\
& \Delta =(-5)^2 - 4 \cdot 1 \cdot 6 = 1,
& 0.25 \\
& x = \dfrac{-(-5) -1}{2} = 2.
& 0.25 \\
& x = \dfrac{-(-5) + 1}{2} = 3
& 0.25 \\
& \SetCell{mode=text}
The given equation has two solutions $x=2$ and $x = 3$.
& 0.25 \\
\end{longtblr}
\end{document}
- 但是,当多行单元格跨越不同数量的列时,您需要手动插入多行单元格的指令:
\documentclass[12pt,a4paper]{article}
\usepackage[%paperwidth=19cm, paperheight=27cm,
hmargin=1.7cm, vmargin={1.8cm,1.7cm}]{geometry}
\usepackage{fouriernc}
\usepackage{ninecolors}
\usepackage{tabularray}
\UseTblrLibrary{amsmath, booktabs, counter,
diagbox, siunitx, varwidth}
\sisetup{output-decimal-marker={,}}
\newcounter{prob}
\NewTableCommand\problem[1]{\SetRow{bg=gray9}%
\SetCell[r=#1]{h, cmd={\stepcounter{prob}\theprob}, bg=white}}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{enumitem}
\usepackage{tikz}
\usepackage{hyperref}
\begin{document}
\begin{longtblr}[
caption={Test}]{hlines, vlines,
colspec = {Q[c, font=\bfseries] X[l, mode=math] Q[c, si={table-format=1.2}]},
row{1} = {c, yellow9, font=\bfseries, mode=text},
rowsep = 5pt,
rowhead = 1,
}
Problem & Content & Point \\
\problem{4}
& \Delta =(-5)^2 - 4 \cdot 1 \cdot 6 = 1,
& 0.25 \\
& x = \dfrac{-(-5) -1}{2} = 2.
& 0.25 \\
& x = \dfrac{-(-5) + 1}{2} = 3
& 0.25 \\
& \SetCell{mode=text}
The given equation has two solutions $x=2$ and $x = 3$.
& 0.25 \\
\problem{2}
& \Delta =(-5)^2 - 4 \cdot 1 \cdot 6 = 1,
& 0.5 \\
& \SetCell{mode=text}
The given equation has two solutions $x=2$ and $x = 3$.
& 0.5 \\
\end{longtblr}
\end{document}
答案2
Tabularray 还具有用于垂直对齐单元格内容的键:
\documentclass[12pt,a4paper]{article}
\usepackage{tabularray}
\usepackage{fouriernc}
\usepackage{mathtools}
\UseTblrLibrary{amsmath,
booktabs,
counter,
diagbox,
siunitx,
varwidth}
\usepackage{enumitem}
\usepackage{ninecolors}
%\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\sisetup{output-decimal-marker={,}}
\usepackage{tikz}
\usepackage[paperwidth=19cm, paperheight=27cm,
hmargin=1.7cm,
vmargin={1.8cm,1.7cm}]{geometry}
\usepackage{hyperref}
\newcounter{mycnta}
\newcommand{\mycnta}{\stepcounter{mycnta}\arabic{mycnta}}
\newcommand{\startproblem}[1]{
\SetCell[r=#1]{c}\mycnta
}
\renewcommand{\arraystretch}{1.3}
\begin{document}
\begin{longtblr}[
expand=\startproblem,
caption={Test}]{
colspec = {Q[c]X[valign=m]Q[c]},
rowhead = 1,
vlines,
hlines,
row{1}={yellow9,font=\bfseries},
cell{1}{2-3}={halign=c},
cell{2}{2-3} ={gray9},
column{1}={font=\bfseries,h},
} Problem & Content & Point \\
\startproblem{4} &
$ \Delta =(-5)^2 - 4 \cdot 1 \cdot 6 = 1$, & \num{0.25} \\
& $ x = \dfrac{-(-5) -1}{2} = 2$. & \num{0.25} \\
& $ x = \dfrac{-(-5) + 1}{2} = 3$ & \num{0.25} \\
& The given equation has two solutions $x=2$ and $x = 3$. & \num{0.25} \\
\end{longtblr}
\end{document}