0

I have a table

\documentclass[12pt,a4paper]{article}
\usepackage{tabularray}
\usepackage{fouriernc}
\usepackage{mathtools}
\UseTblrLibrary{amsmath,
    booktabs,
    counter,
    diagbox,
    siunitx,
    varwidth}
\usepackage{enumitem}
\usepackage{ninecolors}
%\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\sisetup{output-decimal-marker={,}}

\usepackage{tikz}

\usepackage[paperwidth=19cm, paperheight=27cm,
hmargin=1.7cm,
vmargin={1.8cm,1.7cm}]{geometry}
\usepackage{hyperref}
\newcounter{mycnta}
\newcommand{\mycnta}{\stepcounter{mycnta}\arabic{mycnta}}


\newcommand{\startproblem}[1]{
    \SetCell[r=#1]{c}\mycnta
}
\renewcommand{\arraystretch}{1.3}

\begin{document}
        \begin{longtblr}[
        expand=\startproblem,
        caption={Test}]{
            colspec = {Q[c]X[valign=m]Q[c]},
            rowhead = 1,
            vlines,
            hlines,
            row{1}={yellow9,font=\bfseries},
                cell{1}{2-3}={halign=c},
            cell{2}{2-3} ={gray9},
            column{1}={font=\bfseries},
        } Problem & Content & Point \\
\startproblem{4} &
         $ \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}

enter image description here

I want to align text of the first column at the top of column

enter image description here

How can I get it?

1
  • just add h to the column{1} specifications: column{1}={font=\bfseries,h},
    – Mane32
    Dec 5, 2023 at 4:23

2 Answers 2

2
  • to the multirow cell add specification specifier h
  • in MWE I simplify code, i.e. remove theme definition and its use, however, you can return them if you like to have.

Edit:
Considered is OP comment:

  • numbering of "problems" can be done globally automatic, if all multirow cells span the same number of rows
  • set mode=text in the last row of spanned rows by \multirow cell, should be inserted manually by instruction SetCell{bg=gray9}
\documentclass[12pt,a4paper]{article}
\usepackage[paperwidth=19cm, paperheight=27cm,
            hmargin=1.7cm, vmargin={1.8cm,1.7cm}]{geometry}
\usepackage{fouriernc}

\usepackage{ninecolors}
\usepackage{tabularray}
\UseTblrLibrary{amsmath, booktabs, counter,
                diagbox, siunitx,  varwidth}
\sisetup{output-decimal-marker={,}}
\newcounter{problem}

\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{enumitem}

\usepackage{tikz}

\usepackage{hyperref}


\begin{document}
\begin{longtblr}[
caption={Test}]{hlines, vlines,
                colspec = {Q[c, h, font=\bfseries] X[l, mode=math] Q[c, si={table-format=1.2}]},
                cell{2,6}{1} = {r=4}{h, cmd={\stepcounter{problem}\theproblem}, mode=text},
                cell{2}{2-3} = {bg=gray9},
                row{1} = {yellow9, font=\bfseries, mode=text},
                rowsep = 5pt,
                rowhead = 1,
            } 
Problem & Content   & Point     \\
        & \Delta =(-5)^2 - 4 \cdot 1 \cdot 6 = 1, 
                    & 0.25      \\
        & x = \dfrac{-(-5) -1}{2} = 2. 
                    & 0.25      \\
        & x = \dfrac{-(-5)  + 1}{2} = 3
                    & 0.25      \\
        &   \SetCell{mode=text}
            The given equation has two solutions $x=2$ and $x = 3$. 
                    & 0.25  \\
        & \Delta =(-5)^2 - 4 \cdot 1 \cdot 6 = 1,
                    & 0.25      \\
        & x = \dfrac{-(-5) -1}{2} = 2.
                    & 0.25      \\
        & x = \dfrac{-(-5)  + 1}{2} = 3
                    & 0.25      \\
        &   \SetCell{mode=text}
            The given equation has two solutions $x=2$ and $x = 3$.
                    & 0.25  \\
    \end{longtblr}
\end{document}

enter image description here

  • However, when multirow cells spanned different numbers of columns, than you need insert instruction for multirow cells manually:
\documentclass[12pt,a4paper]{article}
\usepackage[%paperwidth=19cm, paperheight=27cm,
            hmargin=1.7cm, vmargin={1.8cm,1.7cm}]{geometry}
\usepackage{fouriernc}

\usepackage{ninecolors}
\usepackage{tabularray}
\UseTblrLibrary{amsmath, booktabs, counter,
                diagbox, siunitx,  varwidth}
\sisetup{output-decimal-marker={,}}
\newcounter{prob}
\NewTableCommand\problem[1]{\SetRow{bg=gray9}%
                            \SetCell[r=#1]{h, cmd={\stepcounter{prob}\theprob}, bg=white}}

\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{enumitem}

\usepackage{tikz}

\usepackage{hyperref}


\begin{document}
\begin{longtblr}[
caption={Test}]{hlines, vlines,
                colspec = {Q[c, font=\bfseries] X[l, mode=math] Q[c, si={table-format=1.2}]},
                row{1} = {c, yellow9, font=\bfseries, mode=text},
                rowsep = 5pt,
                rowhead = 1,
            }
Problem & Content   & Point     \\
\problem{4}
        &   \Delta =(-5)^2 - 4 \cdot 1 \cdot 6 = 1,
                    & 0.25      \\
        & x = \dfrac{-(-5) -1}{2} = 2.
                    & 0.25      \\
        & x = \dfrac{-(-5)  + 1}{2} = 3
                    & 0.25      \\
        &   \SetCell{mode=text}
            The given equation has two solutions $x=2$ and $x = 3$.
                    & 0.25  \\
\problem{2}
        & \Delta =(-5)^2 - 4 \cdot 1 \cdot 6 = 1,
                    & 0.5      \\
        &   \SetCell{mode=text}
            The given equation has two solutions $x=2$ and $x = 3$.
                    & 0.5  \\
    \end{longtblr}
\end{document}

enter image description here

3
  • I have two problems: 1) In stead of numbering of the problems by hand 1, 2, ... How can I make it automatically? 2) In stead of using cell{2}{2-3} = {bg=gray9} by hand. How can I make it automatically if I have 5 problems?
    – Laurenso
    Dec 5, 2023 at 6:25
  • @Laurenso, see edited answer.
    – Zarko
    Dec 5, 2023 at 6:53
  • Thank you very much.
    – Laurenso
    Dec 5, 2023 at 9:26
1

Tabularray also have keys for vertical alignment of the contents of the cells:

\documentclass[12pt,a4paper]{article}
\usepackage{tabularray}
\usepackage{fouriernc}
\usepackage{mathtools}
\UseTblrLibrary{amsmath,
    booktabs,
    counter,
    diagbox,
    siunitx,
    varwidth}
\usepackage{enumitem}
\usepackage{ninecolors}
%\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{siunitx}
\sisetup{output-decimal-marker={,}}

\usepackage{tikz}

\usepackage[paperwidth=19cm, paperheight=27cm,
hmargin=1.7cm,
vmargin={1.8cm,1.7cm}]{geometry}
\usepackage{hyperref}
\newcounter{mycnta}
\newcommand{\mycnta}{\stepcounter{mycnta}\arabic{mycnta}}


\newcommand{\startproblem}[1]{
    \SetCell[r=#1]{c}\mycnta
}
\renewcommand{\arraystretch}{1.3}

\begin{document}
    \begin{longtblr}[
        expand=\startproblem,
        caption={Test}]{
            colspec = {Q[c]X[valign=m]Q[c]},
            rowhead = 1,
            vlines,
            hlines,
            row{1}={yellow9,font=\bfseries},
            cell{1}{2-3}={halign=c},
            cell{2}{2-3} ={gray9},
            column{1}={font=\bfseries,h},
        } Problem & Content & Point \\
        \startproblem{4} &
        $ \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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .