How to get rid of vertical space? - latex

How can I get rid of vertical extra space in latex? I am getting unnecessary space between the table and the figure in the latex appendix.
\documentclass{scrbook}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tabularray}
\begin{document}
\chapter{Appendix}
\begin{table}[!ht]
\centering
\begin{tabular}{|l|l|l|l|}
\hline
Sender & Receiver & Total(Bits) & Frame Rate (ms) \\ \hline
VCU & ACU & 88 & 10 \\ \hline
VCU & BCU & 488 & 10 \\ \hline
VCU & DataRecorder & 536 & 10 \\ \hline
\end{tabular}
\end{table}
\begin{figure}
\centering
\includegraphics[width = \textwidth,trim={2.3cm 2.3cm 2.3cm 2.3cm},clip]{Device Graphics.pdf}
\caption{Device Block}
\label{fig:DeviceOverview}
\end{figure}
\end{document}
I tried using [H] in front of image but did not work instead [H] got printed in script

You have to specify where your images is allowed to be placed. To give latex the best possible chances to find a good location, you can use [htbp] to allow the image to be placed here, at the top, at the bottom or on a separate float page:
\documentclass{scrbook}
%\usepackage[utf8]{inputenc} % default since several years
%\usepackage{tabularray} % nothing to do with the question
\usepackage{graphicx}
\begin{document}
\chapter{Appendix}
\begin{table}[!ht]
\centering
\begin{tabular}{|l|l|l|l|}
\hline
Sender & Receiver & Total(Bits) & Frame Rate (ms) \\ \hline
VCU & ACU & 88 & 10 \\ \hline
VCU & BCU & 488 & 10 \\ \hline
VCU & DataRecorder & 536 & 10 \\ \hline
\end{tabular}
\end{table}
\begin{figure}[htbp]
\centering
\includegraphics[width=\textwidth,trim={2.3cm 2.3cm 2.3cm 2.3cm},clip]{example-image-duck}
\caption{Device Block}
\label{fig:DeviceOverview}
\end{figure}
\end{document}

Related

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 table - Column size and text alignment

I am quite a beginner in LaTex and generated the following table:
\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{|p{2,5cm}||p{3,5cm}|p{2cm}| p{2cm}|}
\hline
\multicolumn{4}{|c|}{Initial Run of Models} \\
\hline
Objective & Service Level in \% & Costs in € & Number of Lines \\
\hline
Max. direct pass. & 93.48 & 1,258.41 & 7\\
Min. travel time & 77.99 & 933.13 & 7\\
\hline
\end{tabular}
\caption[Initial Run of Models]{\label{Tab:InitialRun}Initial Run of Models}
\end{table}
\end{document}
Is there any way to maintain the width of the columns and still align the text in the columns to be on the right side?
You could use the array package and add >{\raggedleft}:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{|>{\raggedleft}p{2.5cm}||>{\raggedleft}p{3.5cm}|>{\raggedleft}p{2cm}| >{\raggedleft\arraybackslash}p{2cm}|}
\hline
\multicolumn{4}{|c|}{Initial Run of Models} \\
\hline
Objective & Service Level in \% & Costs in € & Number of Lines \\
\hline
Max. direct pass. & 93.48 & 1,258.41 & 7\\
Min. travel time & 77.99 & 933.13 & 7\\
\hline
\end{tabular}
\caption[Initial Run of Models]{\label{Tab:InitialRun}Initial Run of Models}
\end{table}
\end{document}
Personally, I would suggest to use the tabularray package instead. This package makes it easy to set the alignment for row/columns or individual cells.
You could use Q[2.5cm] to specify a width, but if you don't, tabularray will determine a much better width for you.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularray}
\begin{document}
\begin{table}[h]
\centering
\begin{tblr}{
colspec={|Q||Q|Q|Q|},
rows={halign=r},
column{1}={halign=l},
row{1}={halign=c},
row{2}={halign=l},
}
\hline
\SetCell[c=4]{} Initial Run of Models &&& \\
\hline
Objective & Service Level in \% & Costs in € & Number of Lines \\
\hline
Max. direct pass. & 93.48 & 1,258.41 & 7\\
Min. travel time & 77.99 & 933.13 & 7\\
\hline
\end{tblr}
\caption[Initial Run of Models]{\label{Tab:InitialRun}Initial Run of Models}
\end{table}
\end{document}
If you use the package array as suggested in the first answer, then you can define in your header one or more newcolumntypes, for example this one called R, right aligned with the width to be assigned to each column. More details here.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{|R{2,5cm}||R{3,5cm}|R{2cm}|R{2cm}|}
\hline
\multicolumn{4}{|c|}{Initial Run of Models}\\
\hline
Objective & Service Level in \% & Costs in € & Number of Lines\\
\hline
Max. direct pass. & 93.48 & 1,258.41 & 7\\
Min. travel time & 77.99 & 933.13 & 7\\
\hline
\end{tabular}
\caption{\label{Tab:InitialRun}Initial Run of Models}
\end{table}
\end{document}
Here I changed to R all of the four columns but they don't have to be all of the same kind.
Make a search because surely there are many "duplicates" of this question here and on TeX SE.

latex: color one column

I would like to create a table like the following:
in which only one column has a color and the color is applied to alternate rows.
The basic table would be:
\documentclass{article}
\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{float}
\usepackage[margin=2cm,left=2.5cm,includefoot]{geometry}
\begin{document}
\begin{table}[!h]
\centering
\caption{HS Sections}
\begin{tabular}{ccc}
& node & degree \\
\hline
& 1 & 1 \\
& 2 & 2 \\
& 3 & 2 \\
& 4 & 4 \\
& 5 & 2 \\
& 6 & 2 \\
& 7 & 1 \\
\hline
\end{tabular}
\label{tab:Table}
\end{table}
\end{document}
You could either manually use \cellcolor{...} to colour the cells you want or you could cheat a bit by colouring the whole rows in alternate colours and then overpaint the cells of the first column with white:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{float}
\usepackage[margin=2cm,left=2.5cm,includefoot]{geometry}
\begin{document}
\begin{table}[!h]
\centering
\caption{HS Sections}
\rowcolors{2}{cyan!50}{white}
\begin{tabular}{>{\cellcolor{white}}cc}
node & degree \\
\hline
1 & 1 \\
2 & 2 \\
3 & 2 \\
4 & 4 \\
5 & 2 \\
6 & 2 \\
7 & 1 \\
\hline
\end{tabular}
\label{tab:Table}
\end{table}
\end{document}

Getting weird form of table

Hi all if anyone can help me. I am new to latex. I am trying to add table in my latex. I know the format but i don't know what I am doing wrong because my table is not in the form I want moreover it is giving me the error when I add caption.
I need some thing like this in the image
but I am getting this when I compile my latex code
Here is my code:
\begin{center}
\begin{tabular}[!ht]{||c c ||}
\caption{Dataset Specifications}
\centering \label{data}
\hline
Dataset & Samples \\ [0.5ex]
\hline\hline
Vovid & 349 \\
\hline
noncovid & 397 \\ [1ex]
\hline
\end{tabular}
\end{center}
My minimal code:
\documentclass{article}
\setlength{\tabcolsep}{1em}
\renewcommand{\arraystretch}{1.5}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabular}{|c|c|}
\hline
Dataset & Samples \\
\hline
Covid & 349 \\
Non Covid & 397 \\
\hline
\end{tabular}
\caption{Dataset Specifications}
\label{tab:data}
\end{table}
\end{document}
and its output:
Please comment below here if any feature is missing or something is not clear to you :)
How about that:
\begin{table}[!ht]
\centering
\begin{tabular}{|c |c|}
\hline
Dataset & Samples \\ [0.5ex]
\hline
Vovid & 349 \\
noncovid & 397 \\ [1ex]
\hline
\end{tabular}
\caption{Dataset Specifications}
\label{tab:data}
\end{table}
So, the trick is 1) to pack the tabular in a table environment, 2) play with \hline and | to modify the lines around the table cells. More ways to polish tables in https://en.wikibooks.org/wiki/LaTeX/Tables

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