I’m writing a document in LaTex with 2 columns where I want a table to ideally be of the same width as the column. I’m not that LaTex savvy so I used an online editor to create the code for my table, and it almost looks the way I want it. Here is the code:
\begin{table}[]
\caption{My caption}
\label{my-label}
\begin{tabular}{llllll}
\hline
Pre-processing & NV$^a$(LV$^b$) & \multicolumn{2}{l}{Calibration} & \multicolumn{2}{l}{Validation} \\ \cline{3-6}
& & RMSE & R$^2$ & RMSE & R$^2$ \\ \hline
$R(\lambda)$ & X(X) & X & X & X & X \\
$D^1(R(\lambda))$ & X(X) & X & X & X & X \\
$D^2(R(\lambda))$ & X(X) & X & X & X & X \\
$-log(R(\lambda))$ & X(X) & X & X & X & X \\
$-log(D^1(R(\lambda))$ & X(X) & X & X & X & X \\
$-log(D^2(R(\lambda))$ & X(X) & X & X & X & X \\
$D^1(-log(R(\lambda)))$ & X(X) & X & X & X & X \\
$D^2(-log(R(\lambda)))$ & X(X) & X & X & X & X \\
$MSC(R(\lambda))$ & X(X) & X & X & X & X \\
$MSC(D^1(R(\lambda)))$ & X(X) & X & X & X & X \\
$MSC(D^2(R(\lambda)))$ & X(X) & X & X & X & X \\
$MSC(-log(R(\lambda)))$ & X(X) & X & X & X & X \\
$MSC(D^1(-log(R(\lambda))))$ & X(X) & X & X & X & X \\
$MSC(-log(D^1(R(\lambda))))$ & X(X) & X & X & X & X \\
$MSC(D^2(-log(R(\lambda))))$ & X(X) & X & X & X & X \\
$MSC(-log(D^2(R(\lambda))))$ & X(X) & X & X & X & X \\
$SNV(R(\lambda))$ & X(X) & X & X & X & X \\
$SNV(D^1(R(\lambda)))$ & X(X) & X & X & X & X \\
$SNV(D^2(R(\lambda)))$ & X(X) & X & X & X & X \\
$SNV(-log(R(\lambda)))$ & X(X) & X & X & X & X \\
$SNV(D^1(-log(R(\lambda))))$ & X(X) & X & X & X & X \\
$SNV(-log(D^1(R(\lambda))))$ & X(X) & X & X & X & X \\
$SNV(D^2(-log(R(\lambda))))$ & X(X) & X & X & X & X \\
$SNV(-log(D^2(R(\lambda))))$ & X(X) & X & X & X & X \\
Multiple simultaneous & X(X) & X & X & X & X \\ \hline
\end{tabular}
\textit{$^a$Number of variables active in final variable selection,$^b$optimal number of latent variables in PLS regression model.}
\end{table}
And when I generate the table it looks like in this image here:
The main problem is that it is too wide. It does not stay within the column width but collides with text in the column to the right. How can I force it to adjust the spaces in the table so it keeps to the column width?
Thanks
Best Answer
I would do the following changes:
tabularx
with prescribed width of one column for table environment\tabcolsep
to half (3pt)\small
multirow
for header of second column\multicolumn
booktabs
packagesthreeparttable
for table notesMWE: