使用 tabularray 生成考试成绩表

使用 tabularray 生成考试成绩表

我想要两个命令来自动生成垂直和水平分级表,使其看起来与下面我手动编写的一样。

在此处输入图片描述

\documentclass[a4paper,addpoints,11pt]{exam} 

\marksnotpoints

\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\vqword{Question}
\vpword{Marks}

\begin{document}
    
    \begin{coverpages}
        
    \begin{tblr}
        [
        presep = 0pt, headsep = 0pt,
        footsep = 0pt, postsep = 0pt,
        ]{
            colsep = 1 em,
            column{1} = {0.15\linewidth},
            width = 0.5\linewidth,
            colspec = {
                X[ c, 2 ]
                X[ c, 1.5 ]
                X[ c, 1.5 ]
            },
            hline{2-Z} = {0.25pt},
            vlines = {0.25pt},
            rows = {m},
            row{1} = {10ex, font = \bfseries},
            row{2-Z} = {6ex, m},
            row{Z} = {font = \bfseries},
            rulesep = 0pt,
            rowsep = 0ex,
        }
        \toprule[1.5pt]
        Question & Marks & Score \\
        1\textsuperscript{st} & 10 & \\
        2\textsuperscript{nd} & 20 & \\
        3\textsuperscript{rd} & 30 & \\
        Total & 60 & \\
        \bottomrule[1.5pt]
    \end{tblr}
    
    \bigskip
    
    \begin{tblr}
        [
        presep = 0pt, headsep = 0pt,
        footsep = 0pt, postsep = 0pt,
        ]{
            colsep = 1 em,
            column{1} = {0.15\linewidth, font = \bfseries},
            column{Z} = {font = \bfseries},
            width = 0.75\linewidth,
            colspec = {
                X[ l, 2 ]
                *{3}{X[ c, 1.5 ]}
                X[ c, 2 ]
            },
            hline{2-Z} = {0.25pt},
            vlines = {0.25pt},
            rows = {6ex, m},
            rulesep = 0pt,
            rowsep = 0ex,
        }
        \toprule[1.5pt]
        Question & 1\textsuperscript{st} & 2\textsuperscript{nd} & 3\textsuperscript{rd} & Total \\
        Marks & 10 & 20 & 30 & 60\\
        Score &  &  &  & \\
        \bottomrule[1.5pt]
    \end{tblr}

    \end{coverpages}

    \begin{questions}
        \question[10]
        Example question
        \question[20]
        Example question
        \question[30]
        Example question
    \end{questions}
    
\end{document}

答案1

为什么不使用类的内置\gradetable命令exam

\documentclass[a4paper,addpoints,11pt]{exam} 
\marksnotpoints
\vpword{Marks}
\hpword{Marks:}%<--
\begin{document}
\begin{coverpages}

\begin{center}
\gradetable[h][questions]%<--
\end{center}

\begin{center}
\gradetable[v][questions]%<--
\end{center}

\end{coverpages}
\begin{questions}
        \question[10]
        Example question
        \question[20]
        Example question
        \question[30]
        Example question
\end{questions}  
\end{document}

在此处输入图片描述

答案2

这就是我所知道的一切。

\documentclass[a4paper,addpoints,11pt]{exam} 

\marksnotpoints

\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\vqword{Question}
\vpword{Marks}

\begin{document}

    \begin{coverpages}
        
        
    \begin{tblr}
        [
        presep = 0pt, headsep = 0pt,
        footsep = 0pt, postsep = 0pt,
        ]{
            colsep = 1 em,
            column{1} = {0.15\linewidth},
            width = 0.5\linewidth,
            colspec = {
                X[ c, 2 ]
                X[ c, 1.5 ]
                X[ c, 1.5 ]
            },
            hline{2-Z} = {0.25pt},
            vlines = {0.25pt},
            rows = {m},
            row{1} = {10ex, font = \bfseries},
            row{2-Z} = {6ex, m},
            row{Z} = {font = \bfseries},
            rulesep = 0pt,
            rowsep = 0ex,
        }
        \toprule[1.5pt]
        Question & Marks & Score \\
        1\textsuperscript{st} & {\csname pointsofq@i\endcsname} & \\
        2\textsuperscript{nd} & {\csname pointsofq@ii\endcsname} & \\
        3\textsuperscript{rd} & {\csname pointsofq@iii\endcsname} & \\
        Total & {\csname exam@numpoints\endcsname} & \\
        \bottomrule[1.5pt]
    \end{tblr}
    
    \bigskip
    
    
    \begin{tblr}
        [
        presep = 0pt, headsep = 0pt,
        footsep = 0pt, postsep = 0pt,
        ]{
            colsep = 1 em,
            column{1} = {0.15\linewidth, font = \bfseries},
            column{Z} = {font = \bfseries},
            width = 0.75\linewidth,
            colspec = {
                X[ l, 2 ]
                *{3}{X[ c, 1.5 ]}
                X[ c, 2 ]
            },
            hline{2-Z} = {0.25pt},
            vlines = {0.25pt},
            rows = {6ex, m},
            rulesep = 0pt,
            rowsep = 0ex,
        }
        \toprule[1.5pt]
        Question & 1\textsuperscript{st} & 2\textsuperscript{nd} & 3\textsuperscript{rd} & Total \\
        Marks & {\csname pointsofq@i\endcsname} & {\csname pointsofq@ii\endcsname} & {\csname pointsofq@iii\endcsname} & {\csname exam@numpoints\endcsname}\\
        Score &  &  &  & \\
        \bottomrule[1.5pt]
    \end{tblr}

    \end{coverpages}
    
    
    
    \begin{questions}
        \question[10]
        Example question
        \question[20]
        Example question
        \question[30]
        Example question
    \end{questions}
    
\end{document} 

相关内容