how to include regression table in PDF?
11:54 18 Nov 2025

This is related to another post where I had problems including a ggplot together with a regression table; fixed the ggplot part, so splitting out the regression table issue.

  1. I can generate the pdf with a modelsummary generated table without problems with knitr.
  2. Using the same Rmd, and looking at the generated tex file, I see that exams does not seem to run the modelsummary call for some reason. What's going on?

First the Rmd.

```{r, results = "hide"}
library(modelsummary)
# library(exams)  # uncomment for simple knit to pdf


questions <- list()
questions[[1]] <- "is 1 true?"
questions[[2]] <- "is 2 true?"

solution = list()
solution[[1]] = TRUE
solution[[2]] = FALSE

```

Question
========


Here is some output

```{r}
m = lm(speed ~ dist, cars)
m
```

```{r}
modelsummary(m,output = "latex")
```



```{r questionlist, echo = FALSE, results = "asis"}
answerlist(questions, markup = "markdown")
```

Solution
========

```{r solutionlist, echo = FALSE, results = "asis"}
answerlist(solution, markup = "markdown")
```

Meta-information
================
extype: mchoice
exsolution: `r mchoice2string(solution)`
exname: test

running this with exams2pdf yields the following intermediate tex tile in the temp folder:

library(exams)
exams2pdf("test.Rmd",texdir = "textemp",verbose = TRUE)
# same result with additional arg
# usepackage =  c("tabularray", "float","graphicx","codehigh", "ulem", "booktabs","siunitx")
# does not seem a latex error
# exercise1.tex
\begin{question}
Here is some output

\begin{verbatim}
m = lm(speed ~ dist, cars)
m
\end{verbatim}

\begin{verbatim}
## 
## Call:
## lm(formula = speed ~ dist, data = cars)
## 
## Coefficients:
## (Intercept)         dist  
##      8.2839       0.1656
\end{verbatim}

\begin{verbatim}
modelsummary(m,output = "latex")
\end{verbatim}
\begin{answerlist}
  \item is 1 true?
  \item is 2 true?
\end{answerlist}
\end{question}

\begin{solution}
\begin{answerlist}
  \item TRUE
  \item FALSE
\end{answerlist}
\end{solution}

Here we see that while the output of printing m gets correctly captured and displayed in the tex, there is nothing visible for the modelsummary(m) call. seems it never ran. Consequently the produced pdf does not have any regression table in it.

Now plain knitr to pdf: works.

enter image description here

what's going on here? if it's not supported, what is the recommended way to display several regressions next to each other in an R-exam? Thanks for any help!

r-exams