Latex table alignment problem with multicolumn and multirow - latex

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}

Related

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 can I make the verticle line in the table without any gaps?

The verticle line in the third column has 2 gaps. How do I do I make it look full?
Here's the code:
\begin{table}[H]
\centering
\caption{Enzymatic cocktails and the respective tested concentrations in \%(v/v) used in Combined Hydrolysis}
\label{enzymatic cocktails}
\begin{tabular}{#{}ccc#{}}
\toprule
\textbf{Cocktail} & \textbf{Enzymes} & \textbf{Concentration \%(v/v)} \\ \midrule
\multirow{2}{*}{A} & \multicolumn{1}{c|}{Cellulase} & \multirow{8}{*}{\begin{tabular}[c]{#{}c#{}}0.25\\ 0.50\\ 1.00\end{tabular}} \\
& \multicolumn{1}{c|}{$\boldsymbol{\beta}$-glucosidase} & \\ \cmidrule(r){1-2}
\multirow{3}{*}{B} & \multicolumn{1}{c|}{Cellulase} & \\
& \multicolumn{1}{c|}{$\boldsymbol{\beta}$-glucosidase} & \\
& \multicolumn{1}{c|}{xylanase} & \\ \cmidrule(r){1-2}
\multirow{3}{*}{C} & \multicolumn{1}{c|}{Cellulase} & \\
& \multicolumn{1}{c|}{$\boldsymbol{\beta}$-glucosidase} & \\
& \multicolumn{1}{c|}{$\boldsymbol{\beta}$-glucanase and xylanase} & \\ \bottomrule
\end{tabular}
\end{table}
Vertical lines like in c| and horizontal lines such as toprule, bottomrule, midrule, cmidrule from the package booktabs do not match.
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}%[H]
\centering
\caption{Enzymatic cocktails and the respective tested concentrations in \%(v/v) used in Combined Hydrolysis}
\label{enzymatic_cocktails}
\begin{tabular}{#{}ccc#{}}
\hline
\textbf{Cocktail} & \textbf{Enzymes} & \textbf{Concentration \%(v/v)}\\
\hline
\multirow{2}{*}{A} & \multicolumn{1}{c|}{Cellulase} & %
\multirow{8}{*}{\begin{tabular}[c]{#{}c#{}}0.25\\ 0.50\\ 1.00\end{tabular}}\\
& \multicolumn{1}{c|}{$\mathbb{\beta}$-glucosidase} & \\
\cline{1-2}
\multirow{3}{*}{B} & \multicolumn{1}{c|}{Cellulase} & \\
& \multicolumn{1}{c|}{$\boldsymbol{\beta}$-glucosidase} & \\
& \multicolumn{1}{c|}{xylanase} & \\
\cline{1-2}
\multirow{3}{*}{C} & \multicolumn{1}{c|}{Cellulase} & \\
& \multicolumn{1}{c|}{$\mathbb{\beta}$-glucosidase} & \\
& \multicolumn{1}{c|}{$\mathbb{\beta}$-glucanase and xylanase} & \\
\hline
\end{tabular}
\end{table}
\end{document}
So I went back to hlines in my code. Better would be to use the above mentioned package booktabs and avoid vertical lines instead.

How to create a multirow multicolumn table with subheadings below the first row

I am attempting to create a table in latex as below, although I am a bit confused about where and when the \multirow and \multicolumn commands are to be used inside a tabular environment. Col_1, Col_2, and Col_3 are supposed to be subheadings but they need to appear in the second row.
What I started off with is, (the columns are duplicated, so I wanted to split it into multiple rows as shown in the image) :
\begin{table}[H]
\begin{tabular}{lSSSSSSSS}
\toprule
\multirow{2}{*}{\textbf{A}} &
\multicolumn{3}{c}{\textbf{Model_1}} &
\multicolumn{5}{c}{\textbf{Model_2}} \\
& {Col_1} & {Col_2} & {Col_3} & {Col_1} & {Col_2} & {Col_3} & {Col_4} & {Col_5} \\
\midrule
x\% & a\% b\% & c\% & x\% & y\% & z\% & 0. & 0. \\
\bottomrule
\end{tabular}
\caption{results}
\end{table}
You can place your subheaders in a row of their own, no need to worry about mutirows and such
\documentclass{article}
\usepackage{siunitx}
%\usepackage{booktabs}
\usepackage{float}
\begin{document}
\begin{table}[H]
\begin{tabular}{l|S|S|S}
\textbf{A} & \multicolumn{3}{c}{x\%} \\
\hline
& {Col\_1} & {Col\_2} & {Col\_3} \\
Model\_1 & a\% & b\% & c\% \\
\hline
Model\_2 & x\% & y\% & z\% \\
\end{tabular}
\caption{results}
\end{table}
\end{document}
Instead of the layout you show in your image, I rather suggest to avoid vertical lines for a more professional looking result:
\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabular}{#{}lSSSSSSSS#{}}
\toprule
\textbf{A} &
\multicolumn{3}{c}{\textbf{Model\_1}} &
\multicolumn{5}{c}{\textbf{Model\_2}} \\
& {Col\_1} & {Col\_2} & {Col\_3} & {Col\_1} & {Col\_2} & {Col\_3} & {Col\_4} & {Col\_5} \\
\cmidrule(r){2-4}\cmidrule(l){5-9}
x\% & a\% & b\% & c\% & x\% & y\% & z\% & 0. & 0. \\
\bottomrule
\end{tabular}
\caption{results}
\end{table}
\end{document}

Creating Multirow Undefined Control Sequence

I'm creating table from https://www.tablesgenerator.com/# but getting error with multirow:
! Undefined control sequence.
\#sharp ->\multirow {2}{*}{}
l.70 \multicolumn{3}{|l|}{\multirow{2}{*}{}}
I've tried removing the square brackets but didn't work.
\begin{table}[]
\begin{tabular}{lll}
\hline
\multicolumn{3}{|l|}{\multirow{2}{*}{}} \\
\multicolumn{3}{|l|}{} \\ \hline
& & \\
& & \\
& & \\
& &
\end{tabular}
\end{table}
I have all the packages installed. what can be done to resolve this please?
You need \usepackage{multirow} if you want to use \multirow:
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}[htbp]
\begin{tabular}{lll}
\hline
\multicolumn{3}{|l|}{\multirow{2}{*}{}} \\
\multicolumn{3}{|l|}{} \\ \hline
& & \\
& & \\
& & \\
& &
\end{tabular}
\end{table}
\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