TransWikia.com

longtable/exam: longtable doesn't page-break inside the solution environment

TeX - LaTeX Asked by Diaa on August 1, 2020

In the following, the longtable is not breakable inside the solution environment. So, how to make the it respect newpage to break the table over the two pages?

enter image description here

documentclass[answers]{exam} 
usepackage{longtable}
usepackage{caption,booktabs,siunitx,multicol}
begin{document}
    begin{questions}
        question some question
        begin{solution}
            setlengthLTleft{0pt}
            setlengthLTright{0pt}
            begin{longtable}{
                    @{extracolsep{fill}}
                    lr
                    *{2}{%
                        S[table-format=2.2,
                        round-precision=2,round-mode=places,
                        round-integer-to-decimal=true]%
                    }@{}}
                toprule
                multicolumn{2}{c}{H1 and H2} & H3 & H4 
                midruleendhead
                left & right & 78.79 & 23.45 
                newpage
                left & right & 78.79 & 23.45 
                bottomrule
            end{longtable}
        end{solution}
    end{questions}
end{document}

One Answer

it doesn't seem related to longtable, a simple solution of

aaa

pagebreak

bbb

the page break is similarly ignored. The solution is set in a box and it seems the class does not always unbox it to allow page breaks.

As a pointer to a possible solution this version (just added a vspace) breaks but has a probably unwanted long white block at the end.

documentclass[answers]{exam} 
usepackage{longtable}
newboxmybox
usepackage{caption,booktabs,siunitx,multicol}
begin{document}
setboxmyboxvbox{
}

    begin{questions}
        question some question
        begin{solution}
            setlengthLTleft{0pt}
            setlengthLTright{0pt}
            begin{longtable}{
                    @{extracolsep{fill}}
                    lr
                    *{2}{%
                        S[table-format=2.2,
                        round-precision=2,round-mode=places,
                        round-integer-to-decimal=true]%
                    }@{}}
                toprule
                multicolumn{2}{c}{H1 and H2} & H3 & H4 
                midruleendhead
                left & right & 78.79 & 23.45 
                newpage
                left & right & 78.79 & 23.45 
                bottomrule
            end{longtable}


vspace{textheight}
        end{solution}
    end{questions}
end{document}

enter image description here

Note if you use longtable in a box you can usually get breaking to work but the head and foot will never be added so the lack of a table head on the second page is expected here (and not really fixable using longtable)

Correct answer by David Carlisle on August 1, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP