5

I am trying make this table. My code

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{diagbox}
\usepackage{siunitx}
\usepackage{ninecolors}
\begin{document}
    \begin{table}[htbp]
    \centering
    \begin{tblr}{
            colspec={|c|c|},row{1}={olive9},
        } \hline \text { Interval } & \text { Frequency } \\
        \hline $ \left[a_1 ; a_2\right) $ & $ n_1 $ \\
        {$ \left[a_2 ; a_3\right) $} & $ n_2 $ \\
        $ \ldots $ & $ \ldots $ \\
        {$ \left[a_m ; a_{m+1}\right) $} & $ n_m $ \\
        \hline & $ n $ \\
        \hline 
    \end{tblr}
    \caption{}
\end{table}
\end{document}

In each row of the table, I use $$. How can I use a short key, e.g \newcolumntype{C}{>{$\displaystyle}c<{$}} to all mathmode of the table to remove all $$ in rows?

enter image description here

1 Answers1

5

You can use cells={mode=imath} to change all cells to inline math mode (or use dmath to get display style math):

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{diagbox}
\usepackage{siunitx}
\usepackage{ninecolors}
\begin{document}
    \begin{table}[htbp]
    \centering
    \begin{tblr}{
      colspec={cc},
      row{1}={olive9},
      vlines,
      hline{1,2,Y,Z} = {solid},
      cells={mode=dmath},
      row{1}={mode=text}
    } 
      Interval & Frequency\\
      \left[a_1 ; a_2\right)  &  n_1  \\
      \left[a_2 ; a_3\right)  &  n_2  \\
      \ldots  &  \ldots  \\
      \left[a_m ; a_{m+1}\right) &  n_m  \\
      &  n  \\ 
    \end{tblr}
    \caption{}
\end{table}
\end{document}

enter image description here