Generalhow to write knitr tables in multi-columns

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
royer11
Posts: 7
Joined: Tue Jul 23, 2019 12:20 am

how to write knitr tables in multi-columns

Post by royer11 »

Hello, I have difficulties in making the tables print aligned because there is little data in column.


code header
\documentclass[12pt]{extbook}
\usepackage{amsmath,amssymb,amsfonts,latexsym,cancel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{multicol} %----
\usepackage{graphicx}
\usepackage{overpic}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}
\usepackage[usenames,dvipsnames]{xcolor}
and body
\begin{document}
\section{Hi and table data}

\begin{multicols}{3}
<<results='hold',echo=FALSE>>=
library(kableExtra)
muestra = sample(10:60,size=80,replace=TRUE)
tabla = data.frame(n=c(1:10), y=muestra[1:10])
kable(tabla,"latex", longtable = T,booktabs=T,caption="List of peoples") %>%
  kable_styling(latex_options=  c("repeat_header"), font_size = 8)
@
%==================================
<<results='hold',echo=FALSE>>=
library(kableExtra)
muestra = sample(10:60,size=80,replace=TRUE)
tabla = data.frame(n=c(11:21), y=muestra[11:21])
kable(tabla,"latex", longtable = T,booktabs=T) %>%
  kable_styling(latex_options=  c("repeat_header"), font_size = 8)
@
%===================================

<<results='hold',echo=FALSE>>=
library(kableExtra)
muestra = sample(10:60,size=80,replace=TRUE)
tabla = data.frame(n=c(11:21), y=muestra[11:21])
kable(tabla,"latex", longtable = T,booktabs=T) %>%
  kable_styling(latex_options=  c("repeat_header"), font_size = 8)
@
%====================
%and continue until n = c(71:80)
\end{multicols}
\end{document}
I had thought of using multicols but it turns out that it generates error and I have also tried minipage but it does not print as I wish.

Objetive
Image

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Post Reply