Generating LaTeX output from R dataframe and save it as pdf or word

Hi All,
I would like to have my R dataframe nicely printed in pdf file :

combined_tab <- structure(list(
  Likert_0 = c("21 (12.43%)", "77 (45.56%)", "26 (15.38%)", "148 (87.57%)", "30 (17.75%)", "39 (23.08%)", "26 (15.38%)", "15 (8.88%)", "30 (17.75%)", "44 (26.04%)", "31 (18.34%)", "125 (73.96%)", "52 (30.77%)", "42 (24.85%)", "57 (33.73%)", "83 (49.11%)"),
  Likert_1 = c("14 (8.28%)", "35 (20.71%)", "41 (24.26%)", "5 (2.96%)", "42 (24.85%)", "27 (15.98%)", "19 (11.24%)", "35 (20.71%)", "37 (21.89%)", "41 (24.26%)", "25 (14.79%)", "24 (14.20%)", "32 (18.93%)", "21 (12.43%)", "26 (15.38%)", "27 (15.98%)"),
  Likert_2 = c("31 (18.34%)", "12 (7.10%)", "46 (27.22%)", "5 (2.96%)", "39 (23.08%)", "28 (16.57%)", "31 (18.34%)", "38 (22.49%)", "44 (26.04%)", "27 (15.98%)", "39 (23.08%)", "4 (2.37%)", "29 (17.16%)", "28 (16.57%)", "24 (14.20%)", "24 (14.20%)"),
  Likert_3 = c("24 (14.20%)", "19 (11.24%)", "21 (12.43%)", "8 (4.73%)", "36 (21.30%)", "33 (19.53%)", "35 (20.71%)", "48 (28.40%)", "32 (18.93%)", "35 (20.71%)", "38 (22.49%)", "11 (6.51%)", "34 (20.12%)", "47 (27.81%)", "31 (18.34%)", "16 (9.47%)"),
  Likert_4 = c("79 (46.75%)", "26 (15.38%)", "35 (20.71%)", "3 (1.78%)", "22 (13.02%)", "42 (24.85%)", "58 (34.32%)", "33 (19.53%)", "26 (15.38%)", "22 (13.02%)", "36 (21.30%)", "5 (2.96%)", "22 (13.02%)", "31 (18.34%)", "31 (18.34%)", "19 (11.24%)")
), row.names = c(NA, -16L), class = "data.frame")

How do I do it, please ?
I have read this:
https://stackoverflow.com/questions/9274013/generating-latex-output-from-r-data-frame

and I have done this in R script:

latex_code <- "
\begin{table}[ht]
\centering
\begin{tabular}{rlllll}
  \hline
 & Likert\_0 & Likert\_1 & Likert\_2 & Likert\_3 & Likert\_4 \\ 
  \hline
1 & 21 (12.43\%) & 14 (8.28\%) & 31 (18.34\%) & 24 (14.20\%) & 79 (46.75\%) \\ 
  2 & 77 (45.56\%) & 35 (20.71\%) & 12 (7.10\%) & 19 (11.24\%) & 26 (15.38\%) \\ 
  3 & 26 (15.38\%) & 41 (24.26\%) & 46 (27.22\%) & 21 (12.43\%) & 35 (20.71\%) \\ 
  4 & 148 (87.57\%) & 5 (2.96\%) & 5 (2.96\%) & 8 (4.73\%) & 3 (1.78\%) \\ 
  5 & 30 (17.75\%) & 42 (24.85\%) & 39 (23.08\%) & 36 (21.30\%) & 22 (13.02\%) \\ 
  6 & 39 (23.08\%) & 27 (15.98\%) & 28 (16.57\%) & 33 (19.53\%) & 42 (24.85\%) \\ 
  7 & 26 (15.38\%) & 19 (11.24\%) & 31 (18.34\%) & 35 (20.71\%) & 58 (34.32\%) \\ 
  8 & 15 (8.88\%) & 35 (20.71\%) & 38 (22.49\%) & 48 (28.40\%) & 33 (19.53\%) \\ 
  9 & 30 (17.75\%) & 37 (21.89\%) & 44 (26.04\%) & 32 (18.93\%) & 26 (15.38\%) \\ 
  10 & 44 (26.04\%) & 41 (24.26\%) & 27 (15.98\%) & 35 (20.71\%) & 22 (13.02\%) \\ 
  11 & 31 (18.34\%) & 25 (14.79\%) & 39 (23.08\%) & 38 (22.49\%) & 36 (21.30\%) \\ 
  12 & 125 (73.96\%) & 24 (14.20\%) & 4 (2.37\%) & 11 (6.51\%) & 5 (2.96\%) \\ 
  13 & 52 (30.77\%) & 32 (18.93\%) & 29 (17.16\%) & 34 (20.12\%) & 22 (13.02\%) \\ 
  14 & 42 (24.85\%) & 21 (12.43\%) & 28 (16.57\%) & 47 (27.81\%) & 31 (18.34\%) \\ 
  15 & 57 (33.73\%) & 26 (15.38\%) & 24 (14.20\%) & 31 (18.34\%) & 31 (18.34\%) \\ 
  16 & 83 (49.11\%) & 27 (15.98\%) & 24 (14.20\%) & 16 (9.47\%) & 19 (11.24\%) \\ 
   \hline
\end{tabular}
\end{table}
"  
  
 # Save the LaTeX code to a .tex file
writeLines(latex_code, con = "example.tex")

# Compile the LaTeX file into a PDF
tinytex::latexmk("example.tex") 

but I am getting errors:
! LaTeX Error: Environment table undefined.
Error: LaTeX failed to compile example.

How to correct this to have that dataframe nicely saved in pdf or docx file with this nice Latex output and font.
Latex code I obtained from:

xtable(combined_tab)

It depends on what you are doing but it is fairly easy to do this in a Quarto document with pdf output using the {gt} package.

---
title: "Tables Document"
author: "john the toucanite"
date: today
pdf-engine: pdflatex
format: pdf
header-includes:
   - \usepackage{float}
   - \floatplacement{table}{H}
   - \usepackage{lipsum}
---

```{r}
#| label:   Load_packages
#| include: false

library(data.table) 
library(tidyverse)
library(janitor)
library(gt)
library(here)

```

```{r}
#| label: load-data
#| include: false

DT <- read.csv("combined_tab.csv")
```


It was a dark and stormy night.


```{r}
#| echo: false
#| label: tbl-likert
#| tbl-cap: Likert Scale Scores

gt(DT)  
```

Thank you,
what to do in order to render it to Word ?
what to do to see the whole df in pdf, because this is a bit cropped ?

I never use MS Word but I think this should help Word Basics

I think the modified Quarto documend below does what you want.

I am using LaTeX commands to change the font size.

---
title: "Tables Document"
author: "john the toucanite"
date: today
pdf-engine: pdflatex
format: pdf
header-includes:
   - \usepackage{float}
   - \floatplacement{table}{H}
   - \usepackage{lipsum}
---

```{r}
#| label:   Load_packages
#| include: false

library(data.table) 
library(tidyverse)
library(janitor)
library(gt)
library(here)

```

```{r}
#| label: load-data
#| include: false

DT <- read.csv("combined_tab.csv")
```


It was a dark and stormy night.


 \fontsize{8}{12}\selectfont 

combined_tab <- structure(list(
  Likert_0 = c("21 (12.43%)", "77 (45.56%)", "26 (15.38%)", "148 (87.57%)", "30 (17.75%)", "39 (23.08%)", "26 (15.38%)", "15 (8.88%)", "30 (17.75%)", "44 (26.04%)", "31 (18.34%)", "125 (73.96%)", "52 (30.77%)", "42 (24.85%)", "57 (33.73%)", "83 (49.11%)"),
  Likert_1 = c("14 (8.28%)", "35 (20.71%)", "41 (24.26%)", "5 (2.96%)", "42 (24.85%)", "27 (15.98%)", "19 (11.24%)", "35 (20.71%)", "37 (21.89%)", "41 (24.26%)", "25 (14.79%)", "24 (14.20%)", "32 (18.93%)", "21 (12.43%)", "26 (15.38%)", "27 (15.98%)"),
  Likert_2 = c("31 (18.34%)", "12 (7.10%)", "46 (27.22%)", "5 (2.96%)", "39 (23.08%)", "28 (16.57%)", "31 (18.34%)", "38 (22.49%)", "44 (26.04%)", "27 (15.98%)", "39 (23.08%)", "4 (2.37%)", "29 (17.16%)", "28 (16.57%)", "24 (14.20%)", "24 (14.20%)"),
  Likert_3 = c("24 (14.20%)", "19 (11.24%)", "21 (12.43%)", "8 (4.73%)", "36 (21.30%)", "33 (19.53%)", "35 (20.71%)", "48 (28.40%)", "32 (18.93%)", "35 (20.71%)", "38 (22.49%)", "11 (6.51%)", "34 (20.12%)", "47 (27.81%)", "31 (18.34%)", "16 (9.47%)"),
  Likert_4 = c("79 (46.75%)", "26 (15.38%)", "35 (20.71%)", "3 (1.78%)", "22 (13.02%)", "42 (24.85%)", "58 (34.32%)", "33 (19.53%)", "26 (15.38%)", "22 (13.02%)", "36 (21.30%)", "5 (2.96%)", "22 (13.02%)", "31 (18.34%)", "31 (18.34%)", "19 (11.24%)")
), row.names = c(NA, -16L), class = "data.frame")


 \fontsize{12}{12}\selectfont 


```{r}
#| echo: false
#| label: tbl-likert
#| tbl-cap: Likert Scale Scores

gt(DT)  
```

Thank you,
I received such a warning updating tinytex:

Warning: conflicting [pdf]tex program found on the system path in 
C:\Program Files\MiKTeX 2.9\miktex\bin\x64\; not fixable in user mode.

Is it concerning, problematic, serious ?