如何在 tabularray 包中使用 \[\]?

如何在 tabularray 包中使用 \[\]?

我在这里看到了问题和答案这里在答案中,作者使用了colspec = {Q[c,gray9]Q[11.4cm,l]X[c]}?。如何自动设置列的长度。这是我从中复制的代码这里

\documentclass[12pt]{article}
\usepackage{tabularray}
\UseTblrLibrary{diagbox}
\UseTblrLibrary{varwidth}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{counter}
\usepackage{enumitem}
\usepackage{ninecolors}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\sisetup{output-decimal-marker={,}}
\UseTblrLibrary{siunitx} 
\usepackage[paperwidth=19cm, paperheight=26.5cm, left=1.7cm,right=1.7cm,top=1.8cm,bottom=1.7cm]{geometry}
\DefTblrTemplate{contfoot-text}{normal}{Continued on next page}
\SetTblrTemplate{contfoot-text}{normal}
\DefTblrTemplate{conthead-text}{normal}{(Continued)}
\SetTblrTemplate{conthead-text}{normal}
\SetTblrTemplate{conthead-text}{normal}
\newcounter{mycnta}
\newcommand{\mycnta}{\stepcounter{mycnta}\arabic{mycnta}}
\begin{document}
    \begin{longtblr}[
        caption={Some text}]{
            colspec = {Q[c,gray9]X[l]Q[c]},
            vlines,
            hlines,
            row{1}={yellow9,font=\bfseries},
            cell{2,7,11}{2-3} ={teal9},
            %cell{7}{2-3} ={teal9},
            %cell{11}{2-3} ={teal9},
            hline{1,2,Y,Z} = {solid},
            cell{1}{2-3}={halign=c},
            column{1}={font=\bfseries},
            cell{2-Z}{1}={cmd={\mycnta}},}
        Problem & Content & Point \\
        \SetCell[r=5]{m}    & Solve the equation 
        \[ (2 x+3)\cdot \sqrt{4 x+5}+(6 x+7) \cdot\sqrt{8 x+9}=2. \]
        &  \num{1.00}   \\
        & $ \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}

在此处输入图片描述

当我使用$ (2 x+3)\cdot \sqrt{4 x+5}+(6 x+7) \cdot\sqrt{8 x+9}=2. $. 我得到了结果

\documentclass[12pt]{article}
\usepackage{tabularray}
\UseTblrLibrary{diagbox}
\UseTblrLibrary{varwidth}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{counter}
\usepackage{enumitem}
\usepackage{ninecolors}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\sisetup{output-decimal-marker={,}}
\UseTblrLibrary{siunitx} 
\usepackage[paperwidth=19cm, paperheight=26.5cm, left=1.7cm,right=1.7cm,top=1.8cm,bottom=1.7cm]{geometry}
\DefTblrTemplate{contfoot-text}{normal}{Continued on next page}
\SetTblrTemplate{contfoot-text}{normal}
\DefTblrTemplate{conthead-text}{normal}{(Continued)}
\SetTblrTemplate{conthead-text}{normal}
\SetTblrTemplate{conthead-text}{normal}
\newcounter{mycnta}
\newcommand{\mycnta}{\stepcounter{mycnta}\arabic{mycnta}}
\begin{document}
    \begin{longtblr}[
        caption={Some text}]{
            colspec = {Q[c,gray9]X[l]Q[c]},
            vlines,
            hlines,
            row{1}={yellow9,font=\bfseries},
            cell{2,7,11}{2-3} ={teal9},
            %cell{7}{2-3} ={teal9},
            %cell{11}{2-3} ={teal9},
            hline{1,2,Y,Z} = {solid},
            cell{1}{2-3}={halign=c},
            column{1}={font=\bfseries},
            cell{2-Z}{1}={cmd={\mycnta}},}
        Problem & Content & Point \\
        \SetCell[r=5]{m}    & Solve the equation 
    $ (2 x+3)\cdot \sqrt{4 x+5}+(6 x+7) \cdot\sqrt{8 x+9}=2. $
        &  \num{1.00}   \\
        & $ \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

显然tblr不喜欢X细胞内的环境。

\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{ninecolors}

\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\UseTblrLibrary{counter}

\sisetup{output-decimal-marker={,}}

\DefTblrTemplate{contfoot-text}{normal}{Continued on next page}
\SetTblrTemplate{contfoot-text}{normal}
\DefTblrTemplate{conthead-text}{normal}{(Continued)}
\SetTblrTemplate{conthead-text}{normal}
\SetTblrTemplate{conthead-text}{normal}

\newcounter{mycnta}
\newcommand{\mycnta}{\stepcounter{mycnta}\arabic{mycnta}}

\newcommand{\hackequation}[1]{%
  \unskip\vspace{0.5\abovedisplayskip}\newline
  \makebox[\linewidth]{$\displaystyle#1$}\vspace{0.5\belowdisplayskip}%
}

\begin{document}

\begin{longtblr}[caption={Some text}]
  {
   colspec = {Q[c,gray9]X[l]Q[c]},
   vlines,
   hlines,
   row{1}={yellow9,font=\bfseries},
   cell{2,7,11}{2-3} ={teal9},
   %cell{7}{2-3} ={teal9},
   %cell{11}{2-3} ={teal9},
   hline{1,2,Y,Z} = {solid},
   cell{1}{2-3}={halign=c},
   column{1}={font=\bfseries},
   cell{2-Z}{1}={cmd={\mycnta}},
}
  Problem & Content & Point \\
  \SetCell[r=5]{m} &
    Solve the equation\hackequation{
      (2 x+3)\cdot \sqrt{4 x+5}+(6 x+7) \cdot\sqrt{8 x+9}=2.
    } & \num{1.00}   \\
  & $ \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}

在此处输入图片描述

如果确实需要的话,也可以对方程式进行编号并进行交叉引用。

\documentclass[12pt]{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{ninecolors}

\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\UseTblrLibrary{counter}

\sisetup{output-decimal-marker={,}}

\DefTblrTemplate{contfoot-text}{normal}{Continued on next page}
\SetTblrTemplate{contfoot-text}{normal}
\DefTblrTemplate{conthead-text}{normal}{(Continued)}
\SetTblrTemplate{conthead-text}{normal}
\SetTblrTemplate{conthead-text}{normal}

\newcounter{mycnta}
\newcommand{\mycnta}{\stepcounter{mycnta}\arabic{mycnta}}

\newcommand{\hackequation}[1]{%
  \unskip\vspace{0.5\abovedisplayskip}\newline
  \parbox{\linewidth}{%
    \setlength{\abovedisplayshortskip}{0pt}%
    \setlength{\belowdisplayshortskip}{0pt}%
    \noindent\begin{equation}#1\end{equation}%
  }\vspace{0.5\belowdisplayskip}%
}

\begin{document}

\begin{longtblr}[caption={Some text containing \eqref{test}}]
  {
   colspec = {Q[c,gray9]X[l]Q[c]},
   vlines,
   hlines,
   row{1}={yellow9,font=\bfseries},
   cell{2,7,11}{2-3} ={teal9},
   %cell{7}{2-3} ={teal9},
   %cell{11}{2-3} ={teal9},
   hline{1,2,Y,Z} = {solid},
   cell{1}{2-3}={halign=c},
   column{1}={font=\bfseries},
   cell{2-Z}{1}={cmd={\mycnta}},
}
  Problem & Content & Point \\
  \SetCell[r=5]{m} &
    Solve the equation\hackequation{\label{test}
      (2 x+3)\cdot \sqrt{4 x+5}+(6 x+7) \cdot\sqrt{8 x+9}=2.
    } & \num{1.00}   \\
  & $ \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}

在此处输入图片描述

答案2

像这样:

在此处输入图片描述

  • tabularray不允许显示方程式,
  • 你需要使用内联数学
  • 当你想模仿 tex 遵循“显示”方程时,你可以写
{Solve the equation\\[1ex]
            $(2 x+3)\cdot \sqrt{4 x+5}+(6 x+7) \cdot\sqrt{8 x+9}=2.$}

完成 MWE:

\documentclass[12pt]{article}
\usepackage[paperwidth=19cm, paperheight=26.5cm, 
            hmargin=1.7cm,
            vmargin={1.8cm,1.7cm}]{geometry}

\usepackage{ninecolors}
\usepackage{tabularray}
\UseTblrLibrary{amsmath, booktabs, counter, diagbox, siunitx, varwidth}
\usepackage{amssymb}
\sisetup{output-decimal-marker={,}}
\DefTblrTemplate{contfoot-text}{normal}{Continued on next page}
\SetTblrTemplate{contfoot-text}{normal}
\DefTblrTemplate{conthead-text}{normal}{(Continued)}
\SetTblrTemplate{conthead-text}{normal}
\SetTblrTemplate{conthead-text}{normal}
\newcounter{mycnta}
\newcommand{\mycnta}{\stepcounter{mycnta}\arabic{mycnta}}
\usepackage{enumitem}

\begin{document}
    \begin{longtblr}[
caption={Some text}
            ]{hlines, vlines,
              colspec = {Q[c,gray9] 
                         l
                         S[table-format=1.2]},
              row{1}  = {guard, c, font=\bfseries, bg=yellow9},
              cell{2,7,11}{2-3} = {bg=teal9},
              rowsep=5pt
              }
Problem & Content   & Point     \\
\SetCell[r=5]{m}    1    
        &   {Solve the equation\\[1ex]
            $(2 x+3)\cdot \sqrt{4 x+5}+(6 x+7) \cdot\sqrt{8 x+9}=2.$}
            &  \num{1.00}       \\
        &   $\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}

相关内容