Wrong column spacing due to multicolumn in latex - latex

in the LaTeX table below, the third column gets too way much spacing due to the long \multicolumn cell in the last line. Can anyone think of a way of getting LaTeX to distribute the additional spacing needed evenly across columns?
\documentclass[11pt]{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabular}{lrrr}
\toprule
& ICE-GB & ICE-SING & ICE-EA \\
\midrule
NP & 619 & 595 & 496 \\
\textbf{Arithmetic mean}& \textbf{1.36} & \textbf{1.33} & \textbf{1.22} \\
SD&0.73 & 0.71 & 0.53 \\
Variation coefficient& 0.54 & 0.52 & 0.44 \\
\midrule
Kruskal Wallis rank sum test&\multicolumn{3}{l}{$H = 16.3941, df = 2, p= 0.0002755123$} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
Thanks!

Excess width \multicolumns end up assigning the excess to the last column. You can avoid this by either using a fixed-width \multicolumn - that is, use a p{<len>} column, or for even spreading of columns use a fixed-width column for the non-\multicolumn columns:
\documentclass[11pt]{article}
\usepackage{booktabs,array}
\begin{document}
\noindent
\begin{tabular}{l*{3}{>{\raggedleft\arraybackslash}p{5em}}}
\toprule
& ICE-GB & ICE-SING & ICE-EA \\
\midrule
NP & 619 & 595 & 496 \\
\textbf{Arithmetic mean} & \textbf{1.36} & \textbf{1.33} & \textbf{1.22} \\
SD & 0.73 & 0.71 & 0.53 \\
Variation coefficient & 0.54 & 0.52 & 0.44 \\
\midrule
Kruskal Wallis rank sum test & \multicolumn{3}{r}{$H = 16.3941, df = 2, p= 0.0002755123$} \\
\bottomrule
\end{tabular}
\end{document}
In the above example, the last three columns each have width 5em, and are \raggedleft (similar to an r-column specification).

Related

Latex table alignment problem with multicolumn and multirow

How can I align this table. It does not algin column two and three at center.
I am using following code:
\begin{table}[htbp]
\caption{Comparison with the hybrid architecture}
\label{tab:comparison}
\begin{center}
\begin{tabular}{|l|c|c|}
\hline
\multicolumn{1}{|c|}{} & \multicolumn{2}{c|}{\textit{Average Episode Reward for 10 Runs (deviation)}} \\ \cline{2-3}
\multicolumn{1}{|c|}{} & \multicolumn{2}{c|}{\textit{Disturbance Magnitude}} \\
\cline{2-3}
\multicolumn{1}{|c|}{\multirow{-3}{*}{\textit{Architecture}}}
& 65\% & 70\% \\ \hline
PID & -17.71 & -23.54 \\
CoL-DRL & -2.58 & -12.25 \\
\rowcolor[HTML]{9AFF99} CoL-DRPRL & -1.85 & -6.25 \\ \hline
\end{tabular}
\end{center}
\end{table}

How to top align a table in a table LaTeX

so i started working with latex and i'm trying to fit a table with statistical content into another table for better alignment.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx,dashrule}
\usepackage{tabularx}
\usepackage{xcolor}
\usepackage[a4paper,left=2cm,right=2cm,top=1cm,bottom=1cm]{geometry}
% Document metadata
\title{Statistische Auswertung}
\author{Automatisch Generiert}
\date{2023-02-09 16:24:04}
\begin{document}
% Dokumententitel und Datum generieren
\maketitle
\begin{tabularx}{\textwidth}{|X|X|}
{\begin{tabularx}{\linewidth}{|X|X|}
\hline
age & --- \\
count & 343.0 \\
mean & 60.8 \\
std & 12.1 \\
min & 28.0 \\
25\% & 53.0 \\
50\% & 60.0 \\
75\% & 70.0 \\
max & 89.0 \\
\hline
\end{tabularx}} & \frame{\includegraphics[width=\linewidth]{age.png}} \\
\hline
{\begin{tabularx}{\linewidth}{|X|X|}
\hline
status-fu & --- \\
count & 356 \\
unique & 2 \\
top & False \\
freq & 297 \\
\hline
\end{tabularx}} & \frame{\includegraphics[width=\linewidth]{status_fu.png}} \\
\hline
\end{tabularx}
\end{document}
The Output lools like this:
I want the Sub-tables on the left to be center top aligned with the Images on the right.
Any help???
Cheers!

Latex Overfull /hbox when inserting table. Cannot change width without changing table structure

When I insert my table into latex I get an overfull /hbox error and cannot figure out how to change the width without changing the structure of my table. The code of my table follows as such:
\begin{center}
\begin{tabular}{||c c c||}
\hline
Function() & Computational Cost (Gas)& USD Equivalent \\ [0.5ex]
\hline\hline
Total Deployment & 8342204 & 1.195559526 \\
\hline
Security Registration & 3849155 & 0.5516400614 \\
\hline
\textit{MintSecurity} & 76293 & 0.01093389983 \\
\hline
\textit{TransferFrom} & 55146 & 0.007903226248 \\
\hline
\textit{Swap} & 89343 & 0.0128041552 \\
\hline
\textit{AddLiquidity} & 185368 & 0.02656593847 \\
\hline
\textit{Remove Liquidity} & 67137 & 0.009621711468 \\ [1ex]
\hline
\end{tabular}
\end{center}
In the template you are using, tables are set in a smaller font size, so the problem is solved automatically if you use a table environment instead of center.
In addition, you can use the tabularray package, so the table will automatically match the text width:
\documentclass[conference]{IEEEtran}
\usepackage{tabularray}
\usepackage{lipsum}
\begin{document}
\lipsum[2]
\begin{table}[htbp]
\begin{tblr}{||c X[c] c||}
\hline
Function() & Computational Cost (Gas)& USD Equivalent \\
\hline\hline
Total Deployment & 8342204 & 1.195559526 \\
\hline
Security Registration & 3849155 & 0.5516400614 \\
\hline
\textit{MintSecurity} & 76293 & 0.01093389983 \\
\hline
\textit{TransferFrom} & 55146 & 0.007903226248 \\
\hline
\textit{Swap} & 89343 & 0.0128041552 \\
\hline
\textit{AddLiquidity} & 185368 & 0.02656593847 \\
\hline
\textit{Remove Liquidity} & 67137 & 0.009621711468 \\
\hline
\end{tblr}%
\end{table}
\lipsum[2]
\end{document}

How to remove middle horizontal line in a table in Overleaf

I have a table in Overleaf. I want to remove the horizontal line (crossing the number 0.3). I know I can use \cline{} command to remove some horizontal lines, but I do not know how to use the combination of them.
\begin{tabular}{l|c|c|c|c|c}
\hline
\multirow{2}{*}{Aspects} & Probability & \multicolumn{4}{c}{Methods} \\
\cline{3-6}
& for DE Genes & Binomial Test & Tangram & stereoscope & BayesPrism\\
\cline{3-6}
AUC & \multirow{2}{*}{0.3} & 0.519 & -0.261 & -0.020 & 0.996 \\
\cline{1-2}
\cline{3-6}
Best thresholds & &$0.398$ & $0.019$ & 0.204 & ${\rm e}^{-50}$\\
\hline
\end{tabular}
\caption{The ROC Curve Summary for Data with 5 Clusters with Probability 0.05 for DE
Genes}
\label{5 cluster 0.05}
\end{table}
The table looks like this.
If you want the line only in the first column, use \cline{1-1} instead of \cline{1-2} which will draw it over the first two columns.
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{l|c|c|c|c|c}
\hline
\multirow{2}{*}{Aspects} & Probability & \multicolumn{4}{c}{Methods} \\
\cline{3-6}
& for DE Genes & Binomial Test & Tangram & stereoscope & BayesPrism\\
\cline{3-6}
AUC & \multirow{2}{*}{0.3} & 0.519 & -0.261 & -0.020 & 0.996 \\
\cline{1-1}
\cline{3-6}
Best thresholds & &$0.398$ & $0.019$ & 0.204 & ${\rm e}^{-50}$\\
\hline
\end{tabular}
\end{document}

How to set the fixed width of columns?

Hello everyone I am creating a table on latex my code looks like this:
\begin{table}[H]
\centering
\caption{caption}
\label{my-label}
\begin{tabular}{lll}
\hline
\multicolumn{3}{|c|}{\cellcolor[HTML]{34CDF9}{\color[HTML]{000000} Matriz confusión Genero.}} \\ \hline
\multicolumn{1}{|l|}{} & \multicolumn{1}{l|}{M} & \multicolumn{1}{l|}{F} \\ \hline
\multicolumn{1}{|l|}{M} & \multicolumn{1}{l|}{43} & \multicolumn{1}{l|}{7} \\ \hline
\multicolumn{1}{|l|}{F} & \multicolumn{1}{l|}{11} & \multicolumn{1}{l|}{39} \\ \hline
\end{tabular}
\end{table}
It works well but the problem comes when I try to fix the width of the columns I tried:
\begin{tabular}{l{2cm}|l{2cm}|l{2cm}}
The result is the same table, with variable length of columns, I would like to fix the length of the columns, I would like to appreciate any suggestion to solve this problem.
Consider the following code:
\documentclass[a4paper]{article}
\usepackage{}
\begin{document}
\begin{table}%[H]
\centering
\caption{caption}
\label{my-label}
\begin{tabular}{|p{20mm}|p{15mm}|p{10mm}|}
\hline
% \multicolumn{3}{|c|}{\cellcolor[HTML]{34CDF9}{\color[HTML]{000000} Matriz confusión Genero.}} \\ \hline
\multicolumn{3}{|c|}{Matriz confusión Genero.} \\ \hline
& M & F \\ \hline
M & 43 & 7 \\ \hline
F & 11 & 39 \\ \hline
\end{tabular}
\end{table}
\end{document}
that outputs the following table:
You may be interested in particular in the line
\begin{tabular}{|p{20mm}|p{15mm}|p{10mm}|}
implementing paragraph alignment for the contents of a column of given width (here 20, 15 and 10 mm respectively).
To make it simpler, you should just get rid of all of those \multicolumn{1}{}{} and change
\begin{tabular}{l{2cm}|l{2cm}|l{2cm}}
to
\begin{tabular}{|p{2cm}|p{2cm}|p{2cm}|}

Resources