Centering the latex table in the page - latex

I have the following table in LaTeX, and although I have used the \centering in the code, it is not centred when knitted. In addition it extends more than the text width as shown in the figure below
\begin{table}[H]
\centering
\caption[mnodels summary]{Summary results of the models \label{tab:modelssummary}}
\begin{tabular}{cccccc}
\toprule
\multicolumn{6}{c}{~ \textbf{~~Models Performance }} \\
\hline
\textbf{Model} & \textbf{Residual Mean} & \textbf{Constant Variance} & \textbf{Autocorrelation} & \textbf{Adj. R-Squared} & \textbf{AIC} \\
\hline\hline
\textbf{Model 1} & OK & OK & YES & 0.83 & 4804.8 \\
\textbf{Model 2} & OK & OK & YES & 0.84 & 4569.5 \\
\textbf{Model 3} & OK & OK & YES & 0.83 & 4763.7 \\
\textbf{Model 4} & OK & OK & YES & 0.87 & 3760.5 \\
\textbf{Model 5} & OK & OK & YES & 0.86 & 3964.5 \\
\textbf{Model 6} & No & No & YES & 0.32 & 10879.7~ \\
\textbf{Model 7} & No & No & YES & 0.80 & 5434.2 \\
\bottomrule
\end{tabular}
\end{table}
and it will look like this:
How can I resolve this?

If you accept multi lines in headings and abbreviations, you can squeeze the table and even fit within the default latex page. Then, \centering will work
and the code
\documentclass{article}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup[table]{position=top,skip=6pt}
\usepackage{makecell}
\usepackage{ragged2e} % Centering
\usepackage{siunitx} % S[...]
% Makecell - settings
\renewcommand\theadfont{\normalsize\normalfont\bfseries}
\renewcommand\theadalign{tc}
% Custom column types
\newcolumntype{C}{>{\Centering\bfseries}p{1.4cm}}
\newcolumntype{P}[1]{>{\Centering}p{#1}}
\begin{document}
\begin{table}[tbh]
\centering
\setlength\tabcolsep{0pt}
\caption[mnodels summary]{Summary results of the models}\label{tab:modelssummary}
\begin{tabular}{
C #{\hspace{1em}}
*4{P{1.25cm}}
#{\hspace{0.75em}}
S[group-minimum-digits=4,table-format=4.1]
}
\toprule
& \multicolumn{5}{c}{\textbf{Models Performance}} \\
\cmidrule{2-6}
\thead{Model}
& \thead{Resid.\\Mean}
& \thead{Const.\\Var.}
& \thead{Auto\\corr.}
& \thead{Adj.\\R\textsuperscript{2}}
& {\thead{AIC}} \\ % {} required for S[] to work
\midrule\midrule
1 & OK & OK & YES & 0.83 & 4804.8 \\
2 & OK & OK & YES & 0.84 & 4569.5 \\
3 & OK & OK & YES & 0.83 & 4763.7 \\
4 & OK & OK & YES & 0.87 & 3760.5 \\
5 & OK & OK & YES & 0.86 & 3964.5 \\
6 & No & No & YES & 0.32 & 10879.7 \\
7 & No & No & YES & 0.80 & 5434.2 \\
\bottomrule
\end{tabular}
\end{table}
\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!

Manage the multiple row in Overleaf

I have made a table with multiple columns and rows arguments like this
\begin{table}[H]
\centering
\begin{tabular}{lccccc}
\hline
\multirow{2}{*}{Aspects} & Probability & \multicolumn{4}{c}{Methods} \\
\cline{3-6}
& for DE Genes & Binomial Test & Tangram & stereoscope & BayesPrism\\
\hline
\multirow{3}{*}{AUC} & 0.3 & 0.867 & 0.029 & 0.074 & 0.992 \\
& 0.1 & 0.722 & 0.023 & 0.015 & 0.987\\
& 0.05 & 0.512 & 0.055 & 0.025 & 0.972\\
\hline
\multirow{3}{*}{Best Thresholds} & 0.3 & ${0.135$ & 0.029 & 0.072 & $1e-10$ \\
& 0.1 & ${1e-60$ & 0.026 & 0.065 & $1e-10$\\
& 0.05 & $1e-60$ & 0.033 & 0.069 & $1e-10$\\
\hline
\end{tabular}
\caption{The ROC Curve Summary for Data with 15 Clusters}
\label{15 cluster summary}
\end{table}
It will give the results like this
I want to make the entries "Best Thresholds" be in two rows (filling 3 rows arguments) so that the table is not too wide. Could anyone helps how to make it?
You can place the text in a \parbox:
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabular}{lccccc}
\hline
\multirow{2}{*}{Aspects} & Probability & \multicolumn{4}{c}{Methods} \\
\cline{3-6}
& for DE Genes & Binomial Test & Tangram & stereoscope & BayesPrism\\
\hline
\multirow{3}{*}{AUC} & 0.3 & 0.867 & 0.029 & 0.074 & 0.992 \\
& 0.1 & 0.722 & 0.023 & 0.015 & 0.987\\
& 0.05 & 0.512 & 0.055 & 0.025 & 0.972\\
\hline
\multirow{3}{*}{\parbox{2cm}{\raggedright Best Thresholds}} & 0.3 & $0.135$ & 0.029 & 0.072 & $1e-10$ \\
& 0.1 & $1e-60$ & 0.026 & 0.065 & $1e-10$\\
& 0.05 & $1e-60$ & 0.033 & 0.069 & $1e-10$\\
\hline
\end{tabular}
\caption{The ROC Curve Summary for Data with 15 Clusters}
\label{15 cluster summary}
\end{table}
\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 place the figure in the overleaf in the middle?

I a trying to put a table in my report. I want to place it in the middle of the page.
but it is shifted to the right side. How can I fix it? (I am using overleaf)
I really appreciate it if anyone could help me to fix the problem.
This is the code:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{floatrow}
\floatsetup[table]{capposition=top}
\usepackage{natbib}
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{tabularx}
\usepackage{caption}
\begin{table}[p]
\centering
\small
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}
\hline
\textbf{Sub fault} & \textbf{Lat} & \textbf{Lon} & \textbf{\begin{tabular}[c]{#{}c#{}}Depth\\ (Km)\end{tabular}} & \textbf{\begin{tabular}[c]{#{}c#{}}Strike\\ (Deg.)\end{tabular}} & \textbf{\begin{tabular}[c]{#{}c#{}}Dip \\ (Deg.)\end{tabular}} & \textbf{\begin{tabular}[c]{#{}c#{}}Length\\ (Km)\end{tabular}} & \textbf{\begin{tabular}[c]{#{}c#{}}Width\\ (Km)\end{tabular}} & \textbf{\begin{tabular}[c]{#{}c#{}}Rake \\ (Deg.)\end{tabular}} & \textbf{\begin{tabular}[c]{#{}c#{}}Slip (m)\\ Mw=9.0\end{tabular}} \\ \hline
\textbf{1} & 18.9848 & -65.6921 & 22.1 & 89.59 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{2} & 19.4069 & -65.6953 & 5 & 89.59 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{3} & 18.9484 & -66.5742 & 22.1 & 84.98 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{4} & 19.3688 & -66.6133 & 5 & 84.98 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{5} & 18.8738 & -67.5412 & 22.1 & 85.87 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{6} & 19.2948 & -67.5734 & 5 & 85.87 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{7} & 18.7853 & -68.4547 & 22.1 & 83.64 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{8} & 19.2048 & -68.5042 & 5 & 83.64 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{9} & 18.8870 & -63.8800 & 22.1 & 95.37 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{10} & 19.3072 & -63.8382 & 5 & 95.37 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{11} & 18.9650 & -64.8153 & 22.1 & 94.34 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{12} & 19.3859 & -64.7814 & 5 & 94.34 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{13} & 18.0566 & -61.5491 & 17.94 & 112.84 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{14} & 18.4564 & -61.3716 & 5 & 112.34 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{15} & 18.4149 & -62.4217 & 17.94 & 117.86 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{16} & 18.7985 & -62.2075 & 5 & 117.86 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{17} & 18.7844 & -63.1649 & 17.94 & 110.46 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{18} & 19.1798 & -63.0087 & 5 & 110.46 & 20 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{19} & 16.4535 & -59.9029 & 17.94 & 136.99 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{20} & 16.7494 & -59.5716 & 5 & 136.99 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{21} & 17.0903 & -60.5996 & 17.94 & 138.71 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{22} & 17.3766 & -60.2580 & 5 & 138.71 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{23} & 17.8560 & -61.1559 & 17.94 & 141.07 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\textbf{24} & 18.1286 & -60.8008 & 5 & 141.07 & 15 & 100 & 50 & 90 & 7.4 \\ \hline
\end{tabular}
\captionsetup{justification=centering}
\caption{\label{tab:table-name}source parameters for a Mw 9.0 PRT co-seismic source based on 24 sub-faults (Gica eal,2008). Corresponding surface elevation computed with Okadas (1985) method is shown in fig 3}
\end{table}
\clearpage
Your issue here is that the table is too wide to fit within the text block. As such, LaTeX pushes is against the left margin and let it overflow into the right margin. If you don't want to change anything and just centre it, you can wrap the entire tabular inside a \makebox[\linewidth]:
\begin{table}
\centering
\small
\makebox[\linewidth]{%
\begin{tabular}{| *{10}{c|} }
<your table here>
\end{tabular}%
}
\caption{<caption>}
\end{table}
For more details and options, see My table doesn't fit; what are my options?
You can try the following:
\begin{center}
\begin{tabular}{ | c | c | c | }
\hline
symbol & value & unit \\ \hline
$z Na$ & 11 & - \\ \hline
$z F$ & 9 & - \\ \hline
$Emax Na$ & 0.545 & $[MeV]$ \\ \hline
\end{tabular}
\end{center}
Refer: How to center table in latex

How do you add vertical lines to a table?

I am making a table and I am not able to make vertical lines to appear. I followed a few examples and they are still not appearing.
\begin{table}[h!]
\centering
\begin{tabular}{||c c c c||}
\hline
\multicolumn{4}{|c|}{Telescope Data} \\
\hline
Channels & \makecell{Beam Size\\ (arcsec)} & \makecell{Noise \\ (mJy/beam)} & Position of Peak Flux \\ [0.5ex]
\hline
1-10 & \makecell{\textbf{min:} 1.42 \\ \textbf{max:} 1.95} & 4.9928 & \makecell{\textbf{peak(x):} 15 \\ \textbf{peak(y):} -13.5 \\ \textbf{peak(flux, max):} 0.002846} \\ [3ex]
\hline
52-61 & \makecell{\textbf{min:} 1.423 \\ \textbf{max:} 1.95} & 0.0018912 & \makecell{\textbf{peak(x):} -0.25 \\ \textbf{peak(y):} 0 \\ \textbf{peak(flux, max):} 0.029341} \\ [3ex]
\hline
103-112 & \makecell{\textbf{min:} 1.427 \\ \textbf{max:} 1.956} & 0.000802855 & \makecell{\textbf{peak(x):} -16 \\ \textbf{peak(y):} 0 \\ \textbf{peak(flux, max):} 0.00241892} \\ [3ex]
\hline
\end{tabular}
\end{table}

Resources