I'm trying to create a table with mailing adresses to print so what I need is to match my table dimensions to the pre-cut sticker paper. So far I've managed to control column width with p{\dimexpr 0.25\linewidth-2\tabcolsep}
(I tried p{5cm}
which is the exact measure of the sticker but it goes too wide off the page for some reason I just don't understand).
However, I don't know how to properly adjust the vertical height of my table.
What I'm doing via Rmarkdown is breaking my data matrix in groups of 4 in order to create a one-row table. Then the next four are in a new table below the previously created one. (This is what I could came up with if someone knows a better way I would really appreciate it)
My problem is all tables adjust to the full size of the page and I want them flushed to the top of the page for printing.
Can someone help me??
This is the latex code produced by R:
\begin{table}[t]
\begin{flushleft}
\begingroup\footnotesize
\begin{tabular}{p{\dimexpr 0.25\linewidth-2\tabcolsep}p{\dimexpr 0.25\linewidth-2\tabcolsep}p{\dimexpr 0.25\linewidth-2\tabcolsep}p{\dimexpr 0.25\linewidth-2\tabcolsep}}
Name & Name & Name & Name \\
Address & Address & Address & Address \\
town & town & town & town \\
city & city & city & city \\
\end{tabular}
\endgroup
\end{flushleft}
\end{table}
\begin{table}[t]
\begin{flushleft}
\begingroup\footnotesize
\begin{tabular}{p{\dimexpr 0.25\linewidth-2\tabcolsep}p{\dimexpr 0.25\linewidth-2\tabcolsep}p{\dimexpr 0.25\linewidth-2\tabcolsep}p{\dimexpr 0.25\linewidth-2\tabcolsep}}
Name & Name & Name & Name \\
Address & Address & Address & Address \\
town & town & town & town \\
city & city & city & city \\
\end{tabular}
\endgroup
\end{flushleft}
\end{table}
This is my curent R code
data <- structure(c("Name", "Address", "town", "city", "Name", "Address",
"town", "city", "Name", "Address", "town", "city", "Name", "Address",
"town", "city", "Name", "Address", "town", "city", "Name", "Address",
"town", "city", "Name", "Address", "town", "city", "Name", "Address",
"town", "city"), dim = c(4L, 8L))
rows <- ncol(data)%/%4
for (i in 1:rows)
{
print(xtable::xtable(data[,(4*(i-1)+1):min(4*i,ncol(data))],
align=rep("p{\\dimexpr 0.25\\linewidth-2\\tabcolsep}",5)),
table.placement = "t",
latex.environments = "flushleft",
hline.after=NULL,
include.rownames=FALSE,
include.colnames=FALSE,
comment=FALSE,
sanitize.text.function = identity,
size=c("\\footnotesize"))
}
p{5cm}
, you would have to put@{}
before, after and between the columns. Like\begin{tabular}{@{}p{5cm}@{}p{5cm}@{}p{5cm}@{}p{5cm}@{}}
, or just easier, set\tabcolsep=0pt
.