![使用 tabularray rowspec ,Q[f] 不會在底部對齊儲存格。以及如何刪除標題?](https://rvso.com/image/456055/%E4%BD%BF%E7%94%A8%20tabularray%20rowspec%20%EF%BC%8CQ%5Bf%5D%20%E4%B8%8D%E6%9C%83%E5%9C%A8%E5%BA%95%E9%83%A8%E5%B0%8D%E9%BD%8A%E5%84%B2%E5%AD%98%E6%A0%BC%E3%80%82%E4%BB%A5%E5%8F%8A%E5%A6%82%E4%BD%95%E5%88%AA%E9%99%A4%E6%A8%99%E9%A1%8C%EF%BC%9F.png)
這是我的程式碼:
latex
% **************************************************
% Document Class
% **************************************************
\documentclass[
paper=A4, %
11pt, % font size
]{scrreprt}
\usepackage{tabularray}
\usepackage[svgnames]{xcolor}
\usepackage{amssymb}
\begin{document}
\NewTblrEnviron{mytblr} % define a new environment
\SetTblrOuter[mytblr]{long}
\SetTblrInner[mytblr]{ % set the default styles
colspec = {|
X[4.0cm,l]|
X[0.7cm,r]|
X[l]|
X[0.7cm,r]|
X[1.2cm,r]|
X[1.0cm,l]|},
width = 1.00\linewidth,
column{2,3,6} = {mode=dmath},
column{5} = {fg=blue},
rowspec={|
Q[h]|
Q[h]|
Q[m]|
Q[f]|
Q[f]|
Q[f]|}
}
\def\s{454}
\def\k{0.00394}
\def\treq{1.7886}
\begin{mytblr}[
caption = {},
]{
% more specs
}
Factor
& t_{req}
& {= k \times s \\ = \k \times \s \\ = \treq}
& t_{req}
& 1.78876
& \mathrm{mm} \\
\end{mytblr}
\end{document}
答案1
tabularray
依賴模板,因此您需要更改預設模板或聲明並設定一個新模板,然後將其與您的表「綁定」。為了演示,我創建了一個名為 的模板nocaptemplate
。這適用於自訂主題mytheme
,而自訂主題又適用於mytblr
.
底部對齊可以透過多種方式實現,但附加到f
最後三列定義對我有用。
您的程式碼中有錯誤。例如,您沒有為第四列設定數學模式並使用數學表達式\t_{...}
。至於多行內容,您嘗試\\
在數學環境中使用。您需要對每行使用內聯數學模式,並可能關閉該列的數學模式或使用多行環境,例如aligned
;這可能是最方便的方法。
使用\newcommand
建立新巨集而不是\def...
,當您嘗試重新定義現有巨集時,它會向您發出警告。
如果您的表格應該跨越多個頁面,請考慮新增rowhead = m
and or ,這將在跨越多個頁面時rowfoot = n
複製第一行m
和最後一行。n
% **************************************************
% Document Class
% **************************************************
\documentclass[
paper=A4, %
11pt, % font size
]{scrreprt}
\usepackage[svgnames]{xcolor}
\usepackage{tabularray}
\usepackage{amsmath,amssymb}
% Removes captions
\DeclareTblrTemplate{caption}{nocaptemplate}{}
\DeclareTblrTemplate{capcont}{nocaptemplate}{}
\NewTblrTheme{mytabletheme}{
\SetTblrTemplate{caption}{nocaptemplate}{}
\SetTblrTemplate{capcont}{nocaptemplate}{}
}
\NewTblrEnviron{mytblr} % define a new environment
\SetTblrOuter[mytblr]{
theme=mytabletheme,
long,
}
\SetTblrInner[mytblr]{ % set the default styles
width = \linewidth,
colspec = {
X[5,l] %<--- X only makes sense when using with proportions
X[1,r] %<--- Otherwise, behaves as a regular Q[...]
X[5,l]
X[1,r,f]
X[2,r,f]
X[2,l,f]
},
column{2-6} = {mode=dmath},
column{5} = {fg=blue},
hlines, vlines,
% row{1,Z} = {font=\bfseries}, %<--- the first and the last row in bold
% rowhead = 1, rowfoot = 1, %<--- would copy the first/last column on subsequent pages
}
\begin{document}
\newcommand\vars{454}
\newcommand\vark{0.00394}
\newcommand\treq{1.7886}
\begin{mytblr}{}
Factor
& t_{req}
& \begin{aligned}[t]&= k \times s\\&= \vark \times \vars\\&= \treq\end{aligned}
& t_{req}
& 1.7887
& \mathrm{mm} \\
\end{mytblr}
\end{document}
答案2
- 你的 MWE 是錯的。使用
rowhead = {1}
table33 時應該至少有兩行! - 桌子真的是長桌嗎?如果沒有,堅持使用
tblr
桌面環境比較簡單 - 我懷疑,表中的第二列和第三列實際上是單元格中包含
aligned
數學的一列。但我不確定,因為您沒有提供任何其他表行的 id 資訊。
看看以下解決方案是否適合您
\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{amsmath}
\DeclareMathOperator{\req}{req}
\begin{document}
\begingroup
\DefTblrTemplate{firsthead, middlehead,lasthead}{default}{} % <---
\def\s{454}
\def\k{0.00394}
\def\treq{1.7886}
\begin{longtblr}{
rowhead = {1},
colspec = {X[0.8, l] X[1.2, c]
Q[f] Q[c, f, fg=blue] Q[f]},
column{2,3} = {mode=dmath},
row{1} = {font=\bfseries, mode=text},
hline{1,2,Z} =1pt, hline{3-Y}=solid, vlines
}
& A & B & C & D \\
Factor & \begin{aligned}[t]
t_{\req} & = k \times s \\
& = \k \times \s \\
& = \treq
\end{aligned}
& t_{\req}
& 1.78876
& mm \\
text & p_{\req} = 2\cdot\treq
& p_{\req}
& 3.57752
& mm \\
\end{longtblr}
\endgroup
\end{document}
編輯:
現在插入使用上述 MWE 生成的圖像!