为 tabularray 创建自定义列

为 tabularray 创建自定义列

如何修复列规格以tabularray获得相同的输出xltabular

在此处输入图片描述

\documentclass{article}
\usepackage[paperheight = 50mm]{geometry}
\usepackage{unicode-math}
\usepackage{xcolor, siunitx, ragged2e, multicol}
\usepackage{tabularray, xltabular, booktabs}
\UseTblrLibrary{booktabs}


\newcolumntype{Y}[1]{>{\Centering\hsize=#1\hsize\linewidth=\hsize}X}
\newcolumntype{L}[1]{>{\RaggedRight\hsize=#1\hsize\linewidth=\hsize}X}

\usepackage{collcell}

\newcolumntype{s}{>{\collectcell\unit}l<{\endcollectcell}}
\makeatletter
\expandafter\renewcommand\expandafter*\expandafter
{\csname NC@rewrite@s\endcsname}[1][]%
{%
    \@temptokena\expandafter
    {%
        \the\@temptokena
        >{\collectcell\unit}l<{\endcollectcell}%
    }%
    \NC@find
}
\makeatother

\newcommand*{\heading}[1]{\multicolumn{2}{c}{#1}}

\begin{document}
    
    \begin{xltabular}{0.7\linewidth}{%
            L{1.6}<{\hspace{1ex}}
            Y{0.4}<{\hspace{1ex}}
            S[
            table-format = 4.3e-1,
            parse-numbers = true,
            table-alignment-mode = none,
            table-number-alignment = right,
            exponent-mode = input,
            exponent-product = \times,
            round-mode = none,
            round-precision = 3,
            tight-spacing = true,
            ]<{\hspace{0.5ex}}
            s[%
            per-mode = symbol,
            bracket-unit-denominator,
            sticky-per%
            ]
            %               U
        }
        \toprule[1.5pt]
        Parameter & Symbol & \heading{Value} \\
        \midrule\endfirsthead
        %
        \midrule
        Parameter & Symbol & \heading{Value} \\
        \midrule\endhead
        %
        \midrule\endfoot
        \bottomrule[1.5pt]\endlastfoot
        %
        zero & m & 1400 & \kg \\ 
        one & f & 0.015 &  \\ 
        two & a & 1.6 & \m\squared \\ 
        three & cd & 0.28 &  \\ 
        four & mu & 0.9 &  \\ 
        five & h & 0.45 & \m \\ 
        six & l1 & 1.2 & \m \\ 
        seven & l2 & 1.4 & \m \\ 
        eight & w & 1.6 & \m \\
        nine & phi & 0.25 & \\ 
    \end{xltabular}
    
    \newpage
    
    \begin{tblr}[
        long, caption = {The Caption},
        ]{
            width = 0.7\linewidth, 
            colspec = {
                L{1.6}<{\hspace{1ex}}
                Y{0.4}<{\hspace{1ex}}
                S[
                table-format = 4.3e-1,
                parse-numbers = true,
                table-alignment-mode = none,
                table-number-alignment = right,
                exponent-mode = input,
                exponent-product = \times,
                round-mode = none,
                round-precision = 3,
                tight-spacing = true,
                ]<{\hspace{0.5ex}}
                s[%
                per-mode = symbol,
                bracket-unit-denominator,
                sticky-per%
                ]
            }, % <<<<<<<<<
            rowhead = 1,
            row{even} = {gray!10},
        }
        \toprule[1.5pt]
        Parameter & Symbol & \heading{Value} \\
        \midrule
        zero & m & 1400 & \kg \\ 
        one & f & 0.015 &  \\ 
        two & a & 1.6 & \m\squared \\ 
        three & cd & 0.28 &  \\ 
        four & mu & 0.9 &  \\ 
        five & h & 0.45 & \m \\ 
        six & l1 & 1.2 & \m \\ 
        seven & l2 & 1.4 & \m \\ 
        eight & w & 1.6 & \m \\
        nine & phi & 0.25 & \\ 
        \bottomrule[1.5pt]
    \end{tblr}

\end{document}

答案1

tabularray使用 排版长表格比使用要容易得多xltabular。另外,不要使用,如果需要,<{\hspace{1ex}}您可以使用leftseprightsep键来输入列。tabularray

\documentclass{article}
\usepackage[paperheight=68mm]{geometry}
%\usepackage{unicode-math}
\usepackage{xcolor}
\usepackage{tabularray}

\UseTblrLibrary{booktabs,siunitx}
\NewColumnType{s}[1][]{Q[l,cmd=\sisetup{#1}\unit]}

\begin{document}

\begin{longtblr}[
  caption = {The Caption},
]{
  width = 0.7\linewidth, 
  colspec = {
     Q[1.6,l]
     Q[0.4,c]
     S[
       table-format = 4.3e-1,
       parse-numbers = true,
       table-alignment-mode = none,
       table-number-alignment = right,
       exponent-mode = input,
       exponent-product = \times,
       round-mode = none,
       round-precision = 3,
       tight-spacing = true,
     ]
     s[%
       per-mode = symbol,
       bracket-unit-denominator,
       sticky-per%
     ]
  }, % <<<<<<<<<
  rowhead = 1,
  row{even} = {gray9},
  cell{1}{3} = {c=2}{c}, % multicolumn
}
\toprule[1.5pt]
  Parameter & Symbol & {{{Value}}} &     \\
\midrule
  zero      & m      & 1400        & \kg \\ 
  one       & f      & 0.015       &     \\ 
  two       & a      & 1.6         & \m\squared \\ 
  three     & cd     & 0.28        &     \\ 
  four      & mu     & 0.9         &     \\ 
  five      & h      & 0.45        & \m  \\ 
  six       & l1     & 1.2         & \m  \\ 
  seven     & l2     & 1.4         & \m  \\ 
  eight     & w      & 1.6         & \m  \\
  nine      & phi    & 0.25        &     \\ 
\bottomrule[1.5pt]
\end{longtblr}

\end{document}

在此处输入图片描述

相关内容