Graphics, Figures & TablesHow to centering a table and set the caption under the Table

Information and discussion about graphics, figures & tables in LaTeX documents.
ohmp2007
Posts: 7
Joined: Fri Aug 01, 2014 3:07 pm

How to centering a table and set the caption under the Table

Post by ohmp2007 »

Hi!

I need help to find a solution for me problem that i have with the table! I try to find a way to center me table and also to set the caption of me table under me table.

I tried with \centering and also \center but nothing will work. I read that if I use \centering I need a paragraph to work :?: :?:

Code: Select all

	\begin{table}[H]
	\centering
		\begin{tabular}{|c | c| }

		\textbf{Wichtig} & \textbf{Wichtiger} \\ \hline

		Prozesse und Tools & Individuen und Interaktion \\ \hline
		detaillierte Dokumentation & funktionierende Software \\ \hline
		Vertragsverhandlungen & Zusammenarbeit mit dem Kunden \\ \hline
		einem Plan folgen & sich Änderungen anpassen \\ \hline

		\caption{Die Gewichtung des agilen Manifests}
		\label{agiles manifest}

		\end{tabular}
	\end{table}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

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

mas
Posts: 226
Joined: Thu Dec 04, 2008 4:39 am

How to centering a table and set the caption under the Table

Post by mas »

You have to move the caption outside of the tabular environment. The following code does what you want:

Code: Select all

\documentclass{article}
\usepackage{showframe}
\begin{document}

\begin{table}[H]
\centering
  \begin{tabular}{|c | c| }
  \hline
  \textbf{Wichtig} & \textbf{Wichtiger} \\ \hline
  Prozesse und Tools & Individuen und Interaktion \\ \hline
  detaillierte Dokumentation & funktionierende Software \\ \hline
  Vertragsverhandlungen & Zusammenarbeit mit dem Kunden \\ \hline
  einem Plan folgen & sich Änderungen anpassen \\ \hline
  \end{tabular}

  \caption{Die Gewichtung des agilen Manifests}
  \label{agiles manifest}

\end{table}

\end{document}

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

How to centering a table and set the caption under the Table

Post by cgnieder »

ohmp2007 wrote:Hi!

I need help to find a solution for me problem that i have with the table! I try to find a way to center me table and also to set the caption of me table under me table.

I tried with \centering and also \center but nothing will work. I read that if I use \centering I need a paragraph to work :?: :?:
Like mas said. This is easy to understand if you think of the whole {tabular} as one letter, say T. Then the structure of the floating environment {table} becomes a lot clearer:

Code: Select all

\begin{table}
  \centering
  T
  \caption{my caption}
  \label{tab:my-table}
\end{table}
Regards
site moderator & package author
ohmp2007
Posts: 7
Joined: Fri Aug 01, 2014 3:07 pm

Re: How to centering a table and set the caption under the T

Post by ohmp2007 »

@mas

If I cpy&paste your solution. I get an error message: Can be used only in preamble. :?:

thx
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How to centering a table and set the caption under the Table

Post by Johannes_B »

mas posted a complete compilable minimal example, as all helpers do most of the time. You have to delete the obvious parts before copying it to your document.
The complete error message would also be very helpful.

btw: If you are looking for german help, check out our partner site TeXwelt.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
ohmp2007
Posts: 7
Joined: Fri Aug 01, 2014 3:07 pm

How to centering a table and set the caption under the Table

Post by ohmp2007 »

Hi!

i tried it with these code:

Code: Select all

\begin{table}[H]
\centering
  \begin{tabular}{|c | c| }
  \hline
  \textbf{Wichtig} & \textbf{Wichtiger} \\ \hline
  Prozesse und Tools & Individuen und Interaktion \\ \hline
  detaillierte Dokumentation & funktionierende Software \\ \hline
  Vertragsverhandlungen & Zusammenarbeit mit dem Kunden \\ \hline
  einem Plan folgen & sich Änderungen anpassen \\ \hline
  \end{tabular}

  \caption{Die Gewichtung des agilen Manifests}
  \label{agiles manifest}

\end{table}
The result is the same the table begins from the left side. And the caption is not under the table it is at the top of the table. :|
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How to centering a table and set the caption under the Table

Post by Johannes_B »

All you are giving us is a snippet of code, which is pretty useless. Try to prepare a minimal working example to find the cause of the behaviour. You might have loaded package floatrow or something, i am not psychic.

Go back to the example provided by mas and click on »Open in Writelatex« to see, that the table is 1) centered and 2) the caption is below the table.

Additional hint: Tables usually have their caption on top. Have a look at package booktabs.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
ohmp2007
Posts: 7
Joined: Fri Aug 01, 2014 3:07 pm

How to centering a table and set the caption under the Table

Post by ohmp2007 »

Ok!

Here is me code.

usepackages

Code: Select all

\usepackage[utf8x]{inputenc}
\usepackage[scaled]{helvet}
\renewcommand*\familydefault{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

\usepackage{textcomp}
\usepackage{graphicx}
\usepackage{caption}[2008/08/24]

\usepackage{scrhack}
\usepackage{listings}
\usepackage{setspace}
\usepackage{geometry}

\usepackage{color}

\usepackage{subfig}
\usepackage{array}
\usepackage{multirow}
\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{hhline}

\usepackage{graphicx}
\usepackage{pdfpages}

\usepackage[hyphens]{url}
\usepackage[pdftex]{hyperref}

%\usepackage{algorithmicx}

\usepackage{caption}
\usepackage{floatrow}
\usepackage{wrapfig}

\usepackage{acronym}
format

Code: Select all

% listings format
\lstset{frame=single, aboveskip=15pt, framesep=5pt, belowskip=15pt}
\lstset{numbersep=10pt, tabsize=4, numbers=left, numberstyle=\tiny}
\lstset{xleftmargin=15pt, xrightmargin=15pt}

\lstset{basicstyle=\normalsize}
\lstset{keywordstyle=\ttfamily\color{OliveGreen}}
\lstset{identifierstyle=\ttfamily\color{CadetBlue}\bfseries}
\lstset{commentstyle=\color{Brown}}
\lstset{stringstyle=\ttfamily, showstringspaces=ture}
\lstset{breaklines=true}

\lstset{captionpos=b}
\lstset{language=xml}

% setspace format
\onehalfspacing

% geometry format
\geometry{a4paper,left=35mm,right=30mm, top=30mm, bottom=30mm}

% 
\parskip 10pt
\parindent 0mm

% hyperref for pdf

\hypersetup{ 
%    bookmarks=true,         % show bookmarks bar?
%    unicode=false,          % non-Latin characters in Acrobats bookmarks
    pdftoolbar=true,        % show Acrobats toolbar?
    pdfmenubar=true,        % show Acrobats menu?
    pdffitwindow=true,     % window fit to page when opened
    pdfstartview={FitH},    % fits the width of the page to the window
    pdftitle={},    % title
    pdfauthor={},     % author
    pdfsubject={},   % subject of the document
%    pdfcreator={Creator},   % creator of the document
    pdfproducer={}, % producer of the document
    pdfkeywords={}, % list of keywords
    pdfnewwindow=true,      % links in new window
    colorlinks=true,       % false: boxed links; true: colored links#
%
% Coloured Links
%    linkcolor=blue, citecolor=green, filecolor=magenta, urlcolor=cyan
%
% Black Links
    linkcolor=black, citecolor=black, filecolor=black, urlcolor=black
%
%
}


\floatsetup[table]{capposition=top}
\captionsetup[table]{labelfont=bf,font=small,position=top,labelsep=colon,justification=justified,singlelinecheck=off}

\captionsetup[figure]{labelfont=bf,font=small,position=bottom,labelsep=colon,justification=justified,singlelinecheck=off}


\renewcommand*{\thefigure}{\thechapter-\arabic{figure}}
\renewcommand*{\thetable}{\thechapter-\arabic{table}}



User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How to centering a table and set the caption under the Table

Post by Johannes_B »

Why didn't you follow the link i gave you? Again you are giving us snippets of code leaving your work to be done by us.

Code: Select all

\documentclass{article}
\usepackage[utf8x]{inputenc}%I bet you don't need the x
\usepackage[scaled]{helvet}%irrelevent
\renewcommand*\familydefault{\sfdefault}%irrelevent
\usepackage[T1]{fontenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

\usepackage{textcomp}%irrelevent
\usepackage{graphicx}%irrelevent
\usepackage{caption}[2008/08/24]

\usepackage{scrhack}%irrelevent
\usepackage{listings}%irrelevent
\usepackage{setspace}%irrelevent
\usepackage{geometry}%irrelevent

\usepackage{color}%irrelevent

\usepackage{subfig}%irrelevent
\usepackage{array}%irrelevent
\usepackage{multirow}%irrelevent
\usepackage{color}%irrelevent
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}%irrelevent
\usepackage{hhline}%irrelevent

\usepackage{graphicx}
\usepackage{pdfpages}

\usepackage[hyphens]{url}%irrelevent
\usepackage[pdftex]{hyperref}%irrelevent

												    %\usepackage{algorithmicx}

\usepackage{caption}
\usepackage{floatrow}
\usepackage{wrapfig}%irrelevent

\usepackage{acronym}%irrelevent

														    % listings
														    % format
\lstset{frame=single,%irrelevent
	aboveskip=15pt,%irrelevent
	framesep=5pt,%irrelevent
belowskip=15pt}%irrelevent
\lstset{numbersep=10pt,%irrelevent
	tabsize=4,%irrelevent
	numbers=left,%irrelevent
numberstyle=\tiny}%irrelevent
\lstset{xleftmargin=15pt,%irrelevent
xrightmargin=15pt}%irrelevent
%irrelevent
\lstset{basicstyle=\normalsize}%irrelevent
\lstset{keywordstyle=\ttfamily\color{OliveGreen}}%irrelevent
\lstset{identifierstyle=\ttfamily\color{CadetBlue}\bfseries}%irrelevent
\lstset{commentstyle=\color{Brown}}%irrelevent
\lstset{stringstyle=\ttfamily,%irrelevent
showstringspaces=ture}%irrelevent
\lstset{breaklines=true}%irrelevent
%irrelevent
\lstset{captionpos=b}%irrelevent
\lstset{language=xml}%irrelevent

\onehalfspacing%irrelevent

\geometry{a4paper,left=35mm,right=30mm, top=30mm, bottom=30mm}

																					%
\parskip 10pt
\parindent 0mm


\hypersetup{%irrelevant
%    bookmarks=true,         % show bookmarks bar?%irrelevant
%    unicode=false,          % non-Latin characters in Acrobats
%    bookmarks%irrelevant
    pdftoolbar=true,        % show Acrobats toolbar?%irrelevant
    pdfmenubar=true,        % show Acrobats menu?%irrelevant
    pdffitwindow=true,     % window fit to page when opened%irrelevant
    pdfstartview={FitH},    % fits the width of the page to the window
    pdftitle={},    % title
    pdfauthor={},     % author
    pdfsubject={},   % subject of the document
%    pdfcreator={Creator},   % creator of the document
    pdfproducer={}, % producer of the document
    pdfkeywords={}, % list of keywords
    pdfnewwindow=true,      % links in new window
    colorlinks=true,       % false: boxed links; true: colored links#
%
% Coloured Links
%    linkcolor=blue, citecolor=green, filecolor=magenta, urlcolor=cyan
%
% Black Links
    linkcolor=black, citecolor=black, filecolor=black, urlcolor=black
%
%
}


\floatsetup[table]{capposition=top}
\captionsetup[table]{labelfont=bf,font=small,position=top,labelsep=colon,justification=justified,singlelinecheck=off}

\captionsetup[figure]{labelfont=bf,font=small,position=bottom,labelsep=colon,justification=justified,singlelinecheck=off}


\renewcommand*{\thefigure}{\thechapter-\arabic{figure}}%irrelevant
\renewcommand*{\thetable}{\thechapter-\arabic{table}}%irrelevant

\begin{document}
\begin{table}
	\rule{5cm}{4cm}
	\caption{your caption}
\end{table}
\end{document}
 

Be careful, you are loading packages twice.

A minimal working example would be the following:

Code: Select all

\documentclass{article}
\usepackage[utf8]{inputenc}%I bet you don't need the x
\usepackage[T1]{fontenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}

\usepackage{caption}
\usepackage{floatrow}

%\floatsetup[table]{capposition=top}%puts the caption on top
\captionsetup[table]{labelfont=bf,
font=small,
position=top,
labelsep=colon,
justification=justified,
%singlelinecheck=off%switches of centering
}
\captionsetup[figure]{labelfont=bf,font=small,position=bottom,labelsep=colon,justification=justified,singlelinecheck=off}
\begin{document}
\begin{table}
	\centering
	\rule{5cm}{4cm}
	\caption{your caption}
\end{table}
\end{document}
Seeing this, the reasons are obvious even for the unexperienced. If you don't need package floatrow, just take it out.

I see you are writing in german, you might want to check out our partner site TeXwelt. You can have all your questions answered there, in german.

Additionally, please read Minimale Vorlage vs. Maximale Probleme.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
ohmp2007
Posts: 7
Joined: Fri Aug 01, 2014 3:07 pm

How to centering a table and set the caption under the Table

Post by ohmp2007 »

Yes, I think it is difficult to find the solution. But i can not delete the things that you mark as *irrelevant.

Because I have a document with many pages e.g. I need the \usepackage{acronym} for these chapter.

Code: Select all

\chapter*{Abkürzungsverzeichnis}
\addcontentsline{toc}{chapter}{Abkürzungsverzeichniss} 

\begin{acronym}[SEPSEP] % längste Abkürzung steht in eckigen Klammern
    \setlength{\itemsep}{-\parsep} % geringerer Zeilenabstand
    \acro{gmbh}[GmbH]{Gesellschaft mit beschränkter Haftung}
    \acro{bzw}[bzw.]{beziehungsweise}
    \acro{usa}[USA]{Vereinigte Staaten von Amerika}
    \acro{engl}[engl.]{englisch}
    \acro{it}[IT]{Informationstechnologie}
    \acro{u.a.}[u.a.]{und andere}    
\end{acronym}
I fixed the problem with the caption.

Code: Select all

\floatsetup[table]{capposition=bottom}
The next thing is to bring the table into the center.

And if I try to erase packages it brings me only errors...

Thank you!
Last edited by ohmp2007 on Mon Sep 01, 2014 6:00 pm, edited 1 time in total.
Post Reply