4

I see this problem and the answer at here. I tried by using \\\nopagebreak, but I cannot get a nice longtable. My code

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

\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}}


\newcommand{\startproblem}[1]{
    \SetCell[r=#1]{m}\SetRow{bg=teal9}\SetCell{bg=gray9}\mycnta
}

\begin{document}
    
    
    \begin{longtblr}[
        expand=\startproblem,
        caption={Some text}]{
            colspec = {Q[c,gray9]X[l,valign=m]Q[c]},
            rowhead = 1,
            vlines,
            hlines,
            row{1}={yellow9,font=\bfseries},
            cell{1}{2-3}={halign=c},
            column{1}={font=\bfseries},
        }
        Problem & Content & Point \\
        \startproblem{5}    & Solve the equation $ x^2 - 5x + 6 = 0 $ &  \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} \\
        \startproblem{4}    & Find the derivaty of the function $ y = \dfrac{2x+1}{x-2} $ $ y = \dfrac{2x+1}{x-2} $ $ y = \dfrac{2x+1}{x-2} $ $ y = \dfrac{2x+1}{x-2} $ $ y = \dfrac{2x+1}{x-2} $ $ y = \dfrac{2x+1}{x-2} $&  \num{0.75}  \\
        & $ y' = \dfrac{(2x+1)'(x-2)-(2x+1)(x-2)'}{(x-2)^2}$. & \num{0.25} \\
        & $ y'=\dfrac{2(x-2) -(2x+1)}{(x-2)^2}$. & \num{0.25} \\
        & $y'=-\dfrac{5}{(x-2)^2}$. & \num{0,25} \\
        \startproblem{3}    & Is this $ x^2 + 3x +4 >0$ true or fail? why?  &  \num{0.75}  \\
        &  $ x^2 + 3x +4 >0$ true. & \num{0.25} \\
        & $ x^2 + 3x +4 $ have $ \Delta = -7<0 $ and coefficient of  $ x^2 $ is $ 1 >0$. & \num{0.50}
        \\
        \startproblem{5}    & Solve the equation $ x^2 - 5x + 6 = 0 $ &  \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} \\
        \startproblem{4}    & Find the derivaty of the function $ y = \dfrac{2x+1}{x-2} $ &  \num{0.75}  \\
        & $ y' = \dfrac{(2x+1)'(x-2)-(2x+1)(x-2)'}{(x-2)^2}$. & \num{0.25} \\
        & $ y'=\dfrac{2(x-2) -(2x+1)}{(x-2)^2}$. & \num{0.25} \\
        & $y'=-\dfrac{5}{(x-2)^2}$. & \num{0,25} \\
        \startproblem{3}    & Is this $ x^2 + 3x +4 >0$ true or fail? why?  &  \num{0.75}  \\\nopagebreak
        &  $ x^2 + 3x +4 >0$ true. & \num{0.25} \\
        & $ x^2 + 3x +4 $ have $ \Delta = -7<0 $ and coefficient of  $ x^2 $ is $ 1 >0$. & \num{0.50}
        \\
        \startproblem{5}    & Solve the equation $ x^2 - 5x + 6 = 0 $ &  \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} \\
        \startproblem{20}   & Find the derivaty of the function $ y = \dfrac{2x+1}{x-2} $ &  \num{0.75}  \\\nopagebreak
        & $ y' = \dfrac{(2x+1)'(x-2)-(2x+1)(x-2)'}{(x-2)^2}$. & \num{0.25} \\
        & $ y'=\dfrac{2(x-2) -(2x+1)}{(x-2)^2}$. & \num{0.25} \\
        & $y'=-\dfrac{5}{(x-2)^2}$. & \num{0,25} \\
        & Find the derivaty of the function $ y = \dfrac{2x+1}{x-2} $ &  \num{0.75}  \\
        & $ y' = \dfrac{(2x+1)'(x-2)-(2x+1)(x-2)'}{(x-2)^2}$. & \num{0.25} \\
        & $ y'=\dfrac{2(x-2) -(2x+1)}{(x-2)^2}$. & \num{0.25} \\
        & $y'=-\dfrac{5}{(x-2)^2}$. & \num{0,25} \\
        & Find the derivaty of the function $ y = \dfrac{2x+1}{x-2} $ &  \num{0.75}  \\
        & $ y' = \dfrac{(2x+1)'(x-2)-(2x+1)(x-2)'}{(x-2)^2}$. & \num{0.25} \\
        & $ y'=\dfrac{2(x-2) -(2x+1)}{(x-2)^2}$. & \num{0.25} \\
        & $y'=-\dfrac{5}{(x-2)^2}$. & \num{0,25} \\
        & Find the derivaty of the function $ y = \dfrac{2x+1}{x-2} $ &  \num{0.75}  \\
        & $ y' = \dfrac{(2x+1)'(x-2)-(2x+1)(x-2)'}{(x-2)^2}$. & \num{0.25} \\
        & $ y'=\dfrac{2(x-2) -(2x+1)}{(x-2)^2}$. & \num{0.25} \\
        & $y'=-\dfrac{5}{(x-2)^2}$. & \num{0,25} \\
        & Find the derivaty of the function $ y = \dfrac{2x+1}{x-2} $ &  \num{0.75}  \\
        & $ y' = \dfrac{(2x+1)'(x-2)-(2x+1)(x-2)'}{(x-2)^2}$. & \num{0.25} \\
        & $ y'=\dfrac{2(x-2) -(2x+1)}{(x-2)^2}$. & \num{0.25} \\
        & $y'=-\dfrac{5}{(x-2)^2}$. & \num{0,25} \\
        
    \end{longtblr} 
    
\end{document}

enter image description here

1 Answer 1

4
  • Problem is last \startproblem command in table: it has to big number of spanned rows, so it protrude below of page.
  • Solution is to manually divide it on two parts, for example on 8-a and 8-b
  • I took a liberty and a wee bit make code shorter ...

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}
\sisetup{output-decimal-marker={,}}
\usepackage{amssymb}
\usepackage{enumitem}

\newcounter{mycnta}
\newcommand{\mycnta}{\stepcounter{mycnta}\arabic{mycnta}}
\newcommand{\startproblem}[1]%
{
    \SetCell[r=#1]{m,bg=gray9, font=\bfseries}\mycnta
}

\begin{document}
    \begin{longtblr}[
expand=\startproblem,
caption={Some text} ]{vlines,hlines,
                     colspec = {Q[c,gray9]
                                X[l,valign=m]
                                Q[c, si={table-format=1.2}]},
                     rowhead = 1,
                     row{1}={yellow9,font=\bfseries},
                     cell{1}{2-3}={halign=c},
                    }
Problem & Content & Point \\
\startproblem{5}    
    & Solve the equation $ x^2 - 5x + 6 = 0 $   & 1.00 \\*
    & $\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 \\*
    & The given equation has two solutions $x=2$ and $x = 3$.   
                                                & 0.25 \\
\startproblem{4}    
    & Find the derivate of the functions    
        $y = \dfrac{2x+1}{x-2},\ y = \dfrac{2x+1}{x-2},$
        $y = \dfrac{2x+1}{x-2},\ y = \dfrac{2x+1}{x-2},\ 
         y = \dfrac{2x+1}{x-2},\ y = \dfrac{2x+1}{x-2}$ 
                                                & 0.75 \\*
    & $y' = \dfrac{(2x+1)'(x-2)-(2x+1)(x-2)'}{(x-2)^2}$.        
                                                & 0.25 \\*
    & $y'=\dfrac{2(x-2) -(2x+1)}{(x-2)^2}$.     & 0.25 \\*
    & $y'=-\dfrac{5}{(x-2)^2}$.                 & 0,25 \\
\startproblem{3}    
    & Is this $ x^2 + 3x +4 >0$ true or fail? Why?  
                                                & 0.75 \\*
    &  $ x^2 + 3x +4 >0$ true.                  & 0.25 \\*
    & $ x^2 + 3x +4 $ have $ \Delta = -7<0 $ and coefficient of  $ x^2 $ is $ 1 >0$. 
                                                & 0.50 \\
\startproblem{5}    
    & Solve the equation $ x^2 - 5x + 6 = 0 $   & 1.00 \\*
    & $\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 \\*
    & The given equation has two solutions $x=2$ and $x = 3$. 
                                                & 0.25 \\
\startproblem{4}    
    & Find the derivaty of the function $ y = \dfrac{2x+1}{x-2} $ 
                                                & 0.75 \\*
    & $ y' = \dfrac{(2x+1)'(x-2)-(2x+1)(x-2)'}{(x-2)^2}$. 
                                                & 0.25 \\*
    & $ y'=\dfrac{2(x-2) -(2x+1)}{(x-2)^2}$.    & 0.25 \\*
    & $y'=-\dfrac{5}{(x-2)^2}$.                 & 0,25 \\
\startproblem{3}    & Is this $ x^2 + 3x +4 >0$ true or fail? why?  
                                                & 0.75 \\*
    &  $ x^2 + 3x +4 >0$ true.                  & 0.25 \\*
    & $ x^2 + 3x +4 $ have $ \Delta = -7<0 $ and coefficient of  $ x^2 $ is $ 1 >0$. 
                                                & 0.50 \\
\startproblem{5}    
    & Solve the equation $ x^2 - 5x + 6 = 0 $   & 1.00 \\*
    & $\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 \\*
    & The given equation has two solutions $x=2$ and $x = 3$. 
                                                & 0.25 \\
\startproblem{13}-a  % <--------------- changed
%\SetCell[r=13]{m,bg=gray9, font=\bfseries}\mycnta-a
    & Find the derivaty of the function $ y = \dfrac{2x+1}{x-2} $ 
                                                & 0.75 \\*
    & $ y' = \dfrac{(2x+1)'(x-2)-(2x+1)(x-2)'}{(x-2)^2}$. 
                                                & 0.25 \\*
    & $ y'=\dfrac{2(x-2) -(2x+1)}{(x-2)^2}$.    & 0.25 \\*
    & $y'=-\dfrac{5}{(x-2)^2}$.                 & 0,25 \\*
    & Find the derivaty of the function $ y = \dfrac{2x+1}{x-2} $ 
                                                & 0.75 \\*
    & $ y' = \dfrac{(2x+1)'(x-2)-(2x+1)(x-2)'}{(x-2)^2}$. 
                                                & 0.25 \\*
    & $ y'=\dfrac{2(x-2) -(2x+1)}{(x-2)^2}$.    & 0.25 \\*
    & $y'=-\dfrac{5}{(x-2)^2}$.                 & 0,25 \\*
    & Find the derivaty of the function $ y = \dfrac{2x+1}{x-2} $ 
                                                & 0.75 \\*
    & $ y' = \dfrac{(2x+1)'(x-2)-(2x+1)(x-2)'}{(x-2)^2}$. 
                                                & 0.25 \\*
    & $ y'=\dfrac{2(x-2) -(2x+1)}{(x-2)^2}$.    & 0.25 \\*
    & $y'=-\dfrac{5}{(x-2)^2}$.                 & 0,25 \\*
    & Find the derivaty of the function $ y = \dfrac{2x+1}{x-2} $ 
                                                & 0.75 \\
\SetCell[r=7]{m,bg=gray9, font=\bfseries}\themycnta-b % <--- inserted, changed
    & $ y' = \dfrac{(2x+1)'(x-2)-(2x+1)(x-2)'}{(x-2)^2}$. 
                                                & 0.25 \\*
    & $ y'=\dfrac{2(x-2) -(2x+1)}{(x-2)^2}$.    & 0.25 \\*
    & $y'=-\dfrac{5}{(x-2)^2}$.                 & 0,25 \\
    & Find the derivaty of the function $ y = \dfrac{2x+1}{x-2} $ 
                                                &  \num{0.75}  \\
    & $ y' = \dfrac{(2x+1)'(x-2)-(2x+1)(x-2)'}{(x-2)^2}$. & 0.25 \\*
    & $ y'=\dfrac{2(x-2) -(2x+1)}{(x-2)^2}$.    & 0.25 \\*
    & $y'=-\dfrac{5}{(x-2)^2}$.                 & 0,25 \\
    \end{longtblr}
\end{document}

enter image description here

4
  • What is difference between \\* and \\? Commented Apr 16, 2023 at 4:31
  • @JohnPaulPeter, big. See documentation for longtable. \\* prevent break of table between pages after row terminated by it.
    – Zarko
    Commented Apr 16, 2023 at 4:38
  • Thank you very much. Commented Apr 16, 2023 at 4:40
  • @JohnPaulPeter, you are welcome!
    – Zarko
    Commented Apr 16, 2023 at 4:41

You must log in to answer this question.

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