How to define a cellsize in LaTeX for wraptable? - latex

I have created the following table in LaTex with wrap table from Package wrapfigure.
\documentclass[a4paper,11pt,oneside,numbers=noendperiod,setspace,parskip=half]{scrbook}
\usepackage[ngerman, english]{babel}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{wrapfig}
\usepackage[table,xcdraw]{xcolor}
\begin{document}
\blindtext
\begin{wraptable}{l}{8cm}
\begin{tabular}{lcccc}
\hline
\rowcolor[HTML]{656565}
\multicolumn{1}{|c|}{\cellcolor[HTML]{656565}{\color[HTML]{FFFFFF}
\textbf{Surface geometry}}} & \multicolumn{4}{c|}{\cellcolor[HTML]{656565}{\color[HTML]{FFFFFF} \textbf{Terrain Classes}}} \\ \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{#{}l#{}}fine texture,\\ high convexity\end{tabular}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{643403}\textbf{1}} & \multicolumn{1}{c|}{\cellcolor[HTML]{F8A102}\textbf{5}} & \multicolumn{1}{c|}{\cellcolor[HTML]{009901}\textbf{9}} & \multicolumn{1}{c|}{\cellcolor[HTML]{34FF34}\textbf{13}} \\ \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{#{}l#{}}fine texture,\\ low convexity\end{tabular}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{CE6301}\textbf{3}} & \multicolumn{1}{c|}{\cellcolor[HTML]{FFCC67}\textbf{7}} & \multicolumn{1}{c|}{\cellcolor[HTML]{34CDF9}\textbf{11}} & \multicolumn{1}{c|}{\cellcolor[HTML]{3531FF}\textbf{15}} \\ \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{#{}l#{}}coarse texture,\\ low convexity\end{tabular}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{F007F4}\textbf{2}} & \multicolumn{1}{c|}{\cellcolor[HTML]{A34894}\textbf{6}} & \multicolumn{1}{c|}{\cellcolor[HTML]{C5C783}\textbf{10}} & \multicolumn{1}{c|}{\cellcolor[HTML]{FCFF2F}\textbf{14}} \\ \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{#{}l#{}}coarse texture,\\ low convexity\end{tabular}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{F690E5}\textbf{4}} & \multicolumn{1}{c|}{\cellcolor[HTML]{F6C8EC}\textbf{8}} & \multicolumn{1}{c|}{\cellcolor[HTML]{DFE360}\textbf{12}} & \multicolumn{1}{c|}{\cellcolor[HTML]{FFFC9E}\textbf{16}} \\ \hline
& \multicolumn{1}{l}{\textit{steep}} & \multicolumn{2}{l}{} & \multicolumn{1}{l}{\textit{gentle}}
\end{tabular}
\end{wraptable}
\blindtext
\end{document}
This looks currently like that:
Table in document:
How is it possible, to change, or set a specific cell size of the columns for all the "Terrain Classes" 1 to 16? Like alls cells have the same width 1.5cm?

Here are my proposed changes to your code:
Change the tabular command to fixed-width columns
Change cells from \multicolumn{1}{c}{<stuff>} to simply <stuff>
Change \\ at end of tabular row to \tabularnewline
I have also taken the liberty to choose 1cm instead of 1.5cm (too wide) and increase the wrapping size to accommodate the wider table.
\documentclass[a4paper,11pt,oneside,numbers=noendperiod,setspace,parskip=half]{scrbook}
\usepackage[ngerman, english]{babel}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{wrapfig}
\usepackage[table,xcdraw]{xcolor}
\begin{document}
\blindtext
\begin{wraptable}{l}{10cm}
\begin{tabular}{|l*{4}{|>{\centering}p{1cm}}|}
\hline
\rowcolor[HTML]{656565}
\multicolumn{1}{|c|}{\cellcolor[HTML]{656565}{\color[HTML]{FFFFFF}
\textbf{Surface geometry}}} & \multicolumn{4}{c|}{\cellcolor[HTML]{656565}{\color[HTML]{FFFFFF} \textbf{Terrain Classes}}} \\ \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{#{}l#{}}fine texture,\\ high convexity\end{tabular}}} &
\cellcolor[HTML]{643403}\textbf{1} &
\cellcolor[HTML]{F8A102}\textbf{5} &
\cellcolor[HTML]{009901}\textbf{9} &
\cellcolor[HTML]{34FF34}\textbf{13} \tabularnewline \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{#{}l#{}}fine texture,\\ low convexity\end{tabular}}} &
\cellcolor[HTML]{CE6301}\textbf{3} &
\cellcolor[HTML]{FFCC67}\textbf{7} &
\cellcolor[HTML]{34CDF9}\textbf{11} &
\cellcolor[HTML]{3531FF}\textbf{15} \tabularnewline \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{#{}l#{}}coarse texture,\\ low convexity\end{tabular}}} &
\cellcolor[HTML]{F007F4}\textbf{2} &
\cellcolor[HTML]{A34894}\textbf{6} &
\cellcolor[HTML]{C5C783}\textbf{10} &
\cellcolor[HTML]{FCFF2F}\textbf{14} \tabularnewline \hline
\multicolumn{1}{|l|}{\textit{\begin{tabular}[c]{#{}l#{}}coarse texture,\\ low convexity\end{tabular}}} &
\cellcolor[HTML]{F690E5}\textbf{4} &
\cellcolor[HTML]{F6C8EC}\textbf{8} &
\cellcolor[HTML]{DFE360}\textbf{12} &
\cellcolor[HTML]{FFFC9E}\textbf{16} \tabularnewline \hline
\multicolumn{1}{l}{} & \multicolumn{1}{l}{\textit{steep}} & \multicolumn{2}{l}{} & \multicolumn{1}{l}{\textit{gentle}}
\end{tabular}
\end{wraptable}
\blindtext
\end{document}
Here's the result:

Related

Vertical and horizontal cell centering in LaTex table

I am making a LaTex table and have trouble centering text (and images) inside cells themselves. The table as a whole is centered on the page, but what I want is that text and images in every cell are centered both vertically and horizontally.
This is my code
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{tabularray}
\usepackage{float}
\usepackage{graphicx}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|c|}
\hline
\rowcolor[HTML]{C0C0C0}
\textbf{Particle} & \textbf{Orientation} & \textbf{Symbol} & \textbf{Letter} \\[4ex] \hline
& in & {\includegraphics[scale=0.8]{im/inel.jpg}} & $u$ \\[2ex] \cline{2-4}
\multirow{-2}{*}{fermion} & out & {\includegraphics[scale=0.8]{im/outel.jpg}} & $\overline{u}$ \\[2ex] \hline
& in & {\includegraphics[scale=0.8]{im/inpoz.jpg}} & $\overline{v}$ \\[2ex] \cline{2-4}
\multirow{-2}{*}{antifermion} & out & {\includegraphics[scale=0.8]{im/outpoz.jpg}} & $v$ \\[2ex] \hline
& in & {\includegraphics[scale=0.8]{im/inph.jpg}} & $\epsilon_\mu$ \\[2ex] \cline{2-4}
\multirow{-2}{*}{foton} & out & {\includegraphics[scale=0.8]{im/outph.jpg}} & $\epsilon_{\mu}^*$ \\[2ex] \hline
\end{tabular}
\end{table}
\end{document}
This is what my code gives me (also notice how some lines are obscured by the images - that is not how I wanted it):
And, this is what I want:
Any help is welcome! Thank you
You are already loading the tabularray package, just use it instead of a tabular:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{tabularray}
\usepackage{float}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\begin{document}
\begin{table}[H]
\centering
\begin{tblr}{
cells={valign=m,halign=c},
row{1}={bg=lightgray,font=\bfseries,rowsep=8pt},
colspec={QQQQ},
hlines,
vlines
}
Particle & Orientation & Symbol & Letter\\
\SetCell[r=2]{} fermion& in & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $u$ \\
& out & \includegraphics[scale=0.5,valign=c]{example-image-duck}& $\overline{u}$ \\
\SetCell[r=2]{} antifermion & in & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $\overline{v}$ \\
& out & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $v$ \\
\SetCell[r=2]{} photon & in & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $\epsilon_\mu$ \\
& out & \includegraphics[scale=0.5,valign=c]{example-image-duck} & $\epsilon_{\mu}^*$ \\
\end{tblr}
\end{table}
\end{document}

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}

Misplaced \noalign if using \ifstrequal

I get a "misplaced \noaling" error within an tabularx environment if I am using \ifstrequal.
This is working:
\documentclass{article}
\usepackage{tabularx}
\usepackage{etoolbox}
\begin{document}
\begin{tabularx}{\textwidth}{rrrrr}
I & am & a & useless & table \\
\ifstrequal{a}{a}{
I & am & a & useless & table \\
} {
I & am & a & useless & table \\
}
\end{tabularx}
\end{document}
This not:
\documentclass{article}
\usepackage{tabularx}
\usepackage{etoolbox}
\begin{document}
\begin{tabularx}{\textwidth}{rrrrr}
I & am & a & useless & table \\
\ifstrequal{a}{a}{
\hline
I & am & a & useless & table \\
\hline
} {
I & am & a & useless & table \\
}
\end{tabularx}
\end{document}
You could resort to good old \ifx:
\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\newcommand{\stringa}{a}
\newcommand{\stringb}{b}
\begin{document}
\begin{tabularx}{\textwidth}{rrrrr}
I & am & a & useless & table \\
\ifx\stringa\stringa
\midrule
I & am & a & useless & table \\
\midrule
\else
I & am & a & useless & table \\
\fi
\end{tabularx}
\end{document}
(I'm using rules from the booktabs package instead of \hline because they give better spacing)

Resources