使用 tabularray rowspec ,Q[f] 不會在底部對齊儲存格。以及如何刪除標題?

使用 tabularray rowspec ,Q[f] 不會在底部對齊儲存格。以及如何刪除標題?

在此輸入影像描述

這是我的程式碼:

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 = mand 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 生成的圖像!

在此輸入影像描述

相關內容