-1

When working in R Markdown and using the amazing "fixest" packages for regressions, regression tables appear "tiny" in the knitted document. As a temporary solution, some lines (see code below) in the produced Latex document can be deleted, which however is not a good fix, given that the document is knitted very often, as changes are implemented.

Below a fully working example is attached, which shows the problem. I tried many settings in the "etable" function, but the table gets printed far too small (and I need the "adjustbox" option, since the table (not the working example) includes many models.

Any hint at a solution, that doesn't require manipulating the tex file after every knit is highly appreciated.

Working with R version 4.2.3 (2023-03-15 ucrt) and R Studio 2022.12.0.

The following code is the content a fully working example as R-Markdown (Rmd) file.

Minimouse.

---
title: "R Markdown and Fixest Issue"
author: "Garfield"
date: "`r Sys.Date()`"
output:
  pdf_document:
    keep_tex: true
header-includes:
  - \usepackage{booktabs}
  - \usepackage{fontenc}
  - \usepackage{amsmath}
  - \usepackage{amssymb}
  - \usepackage{tikz}
  - \usetikzlibrary{fit}
  - \usepackage{csquotes}
  - \usepackage{adjustbox}
  - \usepackage{float}
  - \usepackage{tabularx}
  - \usepackage{verbatim}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

## R Markdown Issue

```{r regs, echo=FALSE, message=FALSE}
if(!require(pacman)) install.packages("pacman")
pacman::p_load(tidyverse, fixest)

data <- tibble(x =  rnorm(100), 
               y  = rnorm(100), 
               y2 = rnorm(100))

est <- feols(c(y, y2) ~x , data=data)

Here will be results. 

The table is tiny (!), especially there something is definitely wrong, as the table does not adjust properly adjust to the page width. Note that, it is not aligned properly. 

A temporary solution is to remove the following lines from the latex document and re-compile the document from within the Latex Editor, such as texstudio. 

The three lines (Lines 39, 40, 45) in the Latex document are.

\begin{verbatim}
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
\end{verbatim}

However, since I frequently change and knit the R Markdown document,  this is a very bad solution. Maybe there is a Latex / R Markdown Pro who knows a permanent fix. Any help or hint at a permanent solution is highly appreciated. 


```{r, results='asis', echo=FALSE}
etable(est, 
       adjustbox = TRUE, 
       markdown  = TRUE,
       tex       = TRUE,
       notes = "Here are some notes explaining regression result, which don't align properly.")
```
shafee
  • 15,566
  • 3
  • 19
  • 47
minimouse
  • 131
  • 10

1 Answers1

-1

I have the same issue as you do but I have yet to find a satisfying solution (sorry). I came across this Stack Overflow (from this GitHub), and thought I'd share it in case it is useful and maybe you can adapt it to fix your issue. Or maybe it will summon a white knight who can solve both our issues. It doesn't solve my original issue (etable object in R being too large for the PDF page), but it prevents the table from shrinking to an unreadable size when using adjustbox. Unfortunately, seemingly, by overriding it... (progress?)

From the SO -- Include the following in your YAML header-includes: (etc):

- \setkeys{Gin}{width=\linewidth,height=\textheight,keepaspectratio} 
emma
  • 1
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/34676512) – Jan Jul 14 '23 at 09:18