Graphics, Figures & Tables ⇒ Problem centering a table II
Problem centering a table II
NEW: TikZ book now 40% off at Amazon.com for a short time.
And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p
Problem centering a table II
Could you please provide a link to this topic?absam82 wrote:I have similar problem to RE: problem centering a table.
Then you have to find out what is causing this behavior. As first step, make a copy of your document and remove all text in the copy except the table. Is the table still left justified? If yes: Try to remove the usage of packages and settings in your preamble, step by step, until the problem is fixed. Afterwards you know what package or setting has cause the undesired behavior.I have copied and pasted the code provided from the reply. Whenever i take a table from my project and paste it inside the obtained code, it does the job, i.e. it centers the table for me. But the same (my own) code is placed back into my project and i'm back to square one. Particularly, my table does not appear horizontally centered but it is left hand sided.
This technique is described here in detail:
http://www.minimalbeispiel.de/mini-en.html
Problem centering a table II
The requested link is:
http://www.latex-community.org/forum/vi ... 45&t=10794
I have followed your procedure but failed to identify the reason. That is why I have just included the code where I was experimenting with the table
Code: Select all
\documentclass[a4paper,11pt,oneside,english]{article}
\usepackage[margin=2.54cm,top=2.54cm]{geometry}
\usepackage{threeparttable}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage[T1]{fontenc}
\usepackage{txfonts}
\usepackage{setspace}
\usepackage{appendix}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage{blindtext}
\usepackage{babel}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{table}[!ht]
\begin{threeparttable}
\caption{\textbf{Descriptive Statistics}}
% title of Table
\centering
% used for centering table
\begin{tabular}{lccccc}
% centered columns (6 columns)
\hline
%inserts single horizontal lines
& Observations & Mean & Standard & Minimum & Maximum\\
& & & deviation & value & value \\ [0.5ex]
\hline
% inserts single horizontal line
Australia\\
\hline
GDP & 51 & 18676.24 & 6034.740 & 9200.492 & 31036.06 \\ [0.5ex]
% inserting body of the table
GINI & 51 & 23.88235 & 2.923060 & 18.00000 & 30.40000 \\ [0.5ex]
% [1ex] adds vertical space
\hline
Sweden\\
\hline
GDP& 34 & 219293.7 & 39772.90 & 167566.5 & 298281.0 \\ [0.5ex]
% [1ex] adds vertical space
GINI& 31 & 24.91935 & 4.042311 & 19.90000 & 33.20000 \\ [0.5ex]
% [1ex] adds vertical space
\hline
UK\\
\hline
GDP & 48 & 12150.83 & 3646.903 & 7045.878 & 19075.72 \\ [0.5ex]
% [1ex] adds vertical space
GINI& 48 & 31.79583 & 5.586799 & 24.80000 & 40.30000 \\ [0.5ex]
% [1ex] adds vertical space
\hline
USA\\
\hline
GDP & 42 & 20683.58 & 5733.927 & 12989.94 & 30993.88 \\ [0.5ex]
% [1ex] adds vertical space
GINI& 42 & 35.30524 & 1.325444 & 33.50000 & 38.16000 \\ [0.5ex]
\hline
%inserts single line
\end{tabular}
\end{threeparttable}
\label{table:nonlin}
% is used to refer this table in the text
\end{table}
\end{document}
Problem centering a table II
But following the procedure described you were now able to post a small example showing the problem, so we have something were we can take a closer look at.absam82 wrote:I have followed your procedure but failed to identify the reason.
You are using threeparttable, and since a threeparttable is always as width as the table itself the \centering inside the threeparttable has no effect. So for centering a threeparttable one has to put the \centering command outside the threeparttable.
Please note that I also moved the \label command as it should follow the \caption command immediately. (There are some cases where this doesn't matter, but there are some cases as well where it does, so it's best to always place it right after the \caption.)
Your example, modified:
Code: Select all
\documentclass[a4paper,11pt,oneside,english]{article}
\usepackage[margin=2.54cm,top=2.54cm]{geometry}
\usepackage{babel,blindtext}
\usepackage{threeparttable}
\begin{document}
\begin{table}[!ht]
\centering
% used for centering table
\begin{threeparttable}
\caption{\textbf{Descriptive Statistics}}
\label{table:nonlin}
% is used to refer this table in the text
% title of Table
\begin{tabular}{lccccc}
% centered columns (6 columns)
\hline
%inserts single horizontal lines
& Observations & Mean & Standard & Minimum & Maximum\\
& & & deviation & value & value \\ [0.5ex]
\hline
% inserts single horizontal line
Australia\\
\hline
GDP & 51 & 18676.24 & 6034.740 & 9200.492 & 31036.06 \\ [0.5ex]
% inserting body of the table
GINI & 51 & 23.88235 & 2.923060 & 18.00000 & 30.40000 \\ [0.5ex]
% [1ex] adds vertical space
\hline
Sweden\\
\hline
GDP& 34 & 219293.7 & 39772.90 & 167566.5 & 298281.0 \\ [0.5ex]
% [1ex] adds vertical space
GINI& 31 & 24.91935 & 4.042311 & 19.90000 & 33.20000 \\ [0.5ex]
% [1ex] adds vertical space
\hline
UK\\
\hline
GDP & 48 & 12150.83 & 3646.903 & 7045.878 & 19075.72 \\ [0.5ex]
% [1ex] adds vertical space
GINI& 48 & 31.79583 & 5.586799 & 24.80000 & 40.30000 \\ [0.5ex]
% [1ex] adds vertical space
\hline
USA\\
\hline
GDP & 42 & 20683.58 & 5733.927 & 12989.94 & 30993.88 \\ [0.5ex]
% [1ex] adds vertical space
GINI& 42 & 35.30524 & 1.325444 & 33.50000 & 38.16000 \\ [0.5ex]
\hline
%inserts single line
\end{tabular}
\end{threeparttable}
\end{table}
\blindtext
\end{document}
Axel
Re: Problem centering a table II
that's really great, I now solved the problems with the rest of my tables.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Problem centering a table II
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10