使用exams2pdf生成考试解答时如何显示各题目分值?
showpoints = TRUE Not Displaying Points in exams2pdf() with solution Template Hey there! Let's work through why your exam solution document isn't showing question points even when you've set showpoints = TRUE in exams2pdf(). Here are the most common fixes to try:
Confirm the default
solutiontemplate supports points display
The out-of-the-boxsolutiontemplate might not include the LaTeX code needed to render points. To check the template's content, run this in R:cat(readLines(system.file("templates", "solution.tex", package = "exams")), sep = "\n")Look for references to
\exampointsor explicit points rendering code. If you don't see any, the template doesn't supportshowpointsby default—you'll need to customize it.Create a custom template with points display
This is the most reliable fix if the default template is missing the necessary code:- Copy the default template to your working directory so you can edit it:
file.copy(system.file("templates", "solution.tex", package = "exams"), "custom_solution.tex") - Open
custom_solution.texin a text editor. Find the section where questions are structured (look for\begin{question}). Modify it to include points, like this:
If you want points to show in the solution section too, add similar code where solutions are rendered.\begin{question} \textbf{Question \thequestionnum} (\exampoints{} points) \exquestion \end{question} - Use your custom template when generating the PDF:
exams2pdf(your_exam_list, template = "custom_solution.tex", showpoints = TRUE)
- Copy the default template to your working directory so you can edit it:
Double-check question points are defined
showpointsonly works if each question in your exam has apointsattribute set. For example, when creating questions, make sure you specify points like:tstat_question <- tstat("tstat1", points = 4)If you forget to set points for a question, there's nothing for
showpointsto display.Update the exams package
Older versions of the exams package had bugs related toshowpointsrendering. Run this to get the latest version:update.packages("exams")Then regenerate your PDF to see if the issue is resolved.
Give these steps a shot, and if you're still stuck, feel free to share a snippet of your exam code or template content—I can help dig deeper!
内容的提问来源于stack exchange,提问作者Sinval

