我想知道在主表格中的以下示例中强制中间垂直对齐的原因是什么。内部表格没有问题,但外部表格不遵守行中定义的不同对齐方式colspec = {Q[l,t] Q[r,b]}
。
谢谢
\documentclass{article}
\usepackage{tikz}
\usepackage{tabularray}
\NewDocumentEnvironment{mathtask}{+b}{%
\begin{tblr}{
colspec={Q[r,b,1cm] Q[c,b,1cm] Q[l,mode=math,1cm]},
vlines,hlines,
}
#1
\end{tblr}}{}
\begin{document}
\centering%
\begin{tblr}{
vlines, hlines,
columns = {0.5\textwidth-13pt, colsep=6pt},
rows = {4cm, rowsep=2pt},
colspec = {Q[l,t] Q[r,b]},
}
\begin{mathtask}
{aaa\\bbb\\ccc\\ddd} & {xx\\yy} & c
\end{mathtask}
&
\begin{mathtask}
{aaa\\bbb} & xxxx & d
\end{mathtask}
\\
\begin{mathtask}
{aaa\\bbb\\ccc\\ddd\\eee\\ff} & {xx\\yy} & e
\end{mathtask}
&
\begin{mathtask}
{aaa\\bbb\\ccc} & {xx\\yy} & f
\end{mathtask}
\end{tblr}
\end{document}
编辑。 原始问题。
\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usepackage{tabularray}
\usepackage[showframe]{geometry}
\newlength{\cwidth} \setlength{\cwidth}{0.49\textwidth}
\newlength{\cheight} \setlength{\cheight}{0.49\textheight}
\newcommand\tasknumber[1]{%
\begin{tikzpicture}[
inner sep=0pt,outer sep=0pt, minimum size=21pt,
baseline={([yshift=-3pt]current bounding box.center)},
]
\node [draw,circle,color=white,fill=white!45!black,] {#1};
\end{tikzpicture}}
\setlength{\tabcolsep}{3pt}
\NewDocumentEnvironment{mathtask}{+b}{%
\begin{tblr}{
colspec={l l l},
column{2}={font=\bfseries},
column{3}={mode=math},
columns={colsep=3pt},
}
#1
\end{tblr}
}{}
\pagestyle{empty}
\begin{document}
\centering
\begin{tblr}{
colspec={l l},
columns={\cwidth-3pt, colsep=3pt},
rows={\cheight, rowsep=3pt},
vline{2} = solid,
hline{2} = solid,
}
\begin{mathtask}
\tasknumber{1} &
Solve the system: &
\begin{cases}
x + y + = 1 \\
x + y + = 1 \\
x + y + = 1 \\
x + y + = 1 \\
x + y + z = 2
\end{cases}
\end{mathtask}
&
\begin{mathtask}
\tasknumber{2} &
Solve the system: &
\begin{cases}
x + y + = 1 \\
x + y + = 3 \\
x + y + z = 2
\end{cases}
\end{mathtask}
\\
\begin{mathtask}
\tasknumber{3} &
Solve the equation: &
x + y + z = 2
\end{mathtask}
&
\begin{mathtask}
\tasknumber{50} &
Solve the system: &
\begin{cases}
x + y + = 1 \\
x + y + z = 2
\end{cases}
\end{mathtask}
\end{tblr}
\end{document}
答案1
当每个单元格一行只有一行文本时,垂直对齐选项t
/ m
/b
对于此行是相同的。对于传统的tabular
(除了仍然有一个对齐漏洞在tabular
环境中)。
虽然mathtask
环境由一个复杂的表格组成,但 TeX 仍然将其视为一个框,因此这些单元格都是单行的(你可以在环境前后添加一些文本来更清楚地看到它mathtask
)。因此在外部表格中,例如colspec={Q[t]Q[b]}
和colspec={Q[b]Q[m]}
和colspec={Q[m]Q[t]}
将产生相同的结果。
我不确定你真正想从代码中得到什么。但你可以更改内部表的对齐方式:
\documentclass{article}
\usepackage{tabularray}
\NewDocumentEnvironment{mathtask}{O{}+b}{%
\begin{tblr}[T]{
colspec={Q[r,#1,1cm] Q[c,#1,1cm] Q[l,mode=math,1cm]},
vlines,hlines,
}
#2
\end{tblr}}{}
\begin{document}
\centering
\begin{tblr}{
vlines, hlines,
columns = {0.5\textwidth-13pt, colsep=6pt},
rows = {4cm, rowsep=2pt},
colspec = {Q[l,t] Q[r,b]},
}
a\begin{mathtask}[t]
{aaa\\bbb\\ccc\\ddd} & {xx\\yy} & c
\end{mathtask}b
&
a\begin{mathtask}[t]
{aaa\\bbb} & xxxx & d
\end{mathtask}b
\\
a\begin{mathtask}[b]
{aaa\\bbb\\ccc\\ddd\\eee\\ff} & {xx\\yy} & e
\end{mathtask}b
&
a\begin{mathtask}[b]
{aaa\\bbb\\ccc} & {xx\\yy} & f
\end{mathtask}b
\end{tblr}
\end{document}
编辑:对于您的原始问题,您需要移出\tasknumber
这些新列mathtask
并设置垂直对齐方式:h
\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usepackage{tabularray}
\usepackage[showframe]{geometry}
\newlength{\cheight} \setlength{\cheight}{0.5\textheight-6.02pt}
\newcommand\tasknumber[1]{%
\begin{tikzpicture}[
inner sep=0pt,outer sep=0pt, minimum size=21pt,
baseline={([yshift=-3pt]current bounding box.center)},
]
\node [draw,circle,color=white,fill=white!45!black,] {#1};
\end{tikzpicture}}
\setlength{\tabcolsep}{3pt}
\NewDocumentEnvironment{mathtask}{+b}{%
\begin{tblr}{
colspec={ll},
column{1}={font=\bfseries},
column{2}={mode=math},
columns={colsep=3pt},
}
#1
\end{tblr}
}{}
\pagestyle{empty}
\begin{document}
\centering
\begin{tblr}{
colspec={Q[h,l]X[l]Q[h,l]X[l]},
colsep=3pt,
rows={\cheight, rowsep=3pt},
vline{3} = solid,
hline{2} = solid,
}
\tasknumber{1} &
\begin{mathtask}
Solve the system: &
\begin{cases}
x + y + = 1 \\
x + y + = 1 \\
x + y + = 1 \\
x + y + = 1 \\
x + y + z = 2
\end{cases}
\end{mathtask}
&
\tasknumber{2} &
\begin{mathtask}
Solve the system: &
\begin{cases}
x + y + = 1 \\
x + y + = 3 \\
x + y + z = 2
\end{cases}
\end{mathtask}
\\
\tasknumber{3} &
\begin{mathtask}
Solve the equation: &
x + y + z = 2
\end{mathtask}
&
\tasknumber{50} &
\begin{mathtask}
Solve the system: &
\begin{cases}
x + y + = 1 \\
x + y + z = 2
\end{cases}
\end{mathtask}
\end{tblr}
\end{document}