Graphics, Figures & TablesCenter text in a table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Diogo Remoaldo
Posts: 26
Joined: Mon Apr 06, 2015 8:24 pm

Center text in a table

Post by Diogo Remoaldo »

Hi I using the following code

Code: Select all

\begin{table}[H]
  \centering
  \caption{Janelas utilizadas}
    \begin{tabular}{cccC{2.0cm}C{2.0cm}}
    \toprule
    Janela & U [$W/m^2\cdot K$]    & g     & Espessura do Envidraçado [mm]& Espessura da Caixa de ar [mm]\\
    \midrule
    ClimaPlus & 1,1   & 60,9  & 4  & 15 \\
    ClimaPlus & 1,43  & 60,5  & 4  & 15 \\
    Insulated & 1,27  & 62,4  & 4  & 16 \\
    \bottomrule
    \end{tabular}%
  \label{janela}%
\end{table}%
And I got the table in the picture in the attachment, I would like to center the text in the midle of each collum of the first line (Janela, U, g).

I am also using the collum C as \newcolumntype{C}{>{\centering\arraybackslash}p}

How can I do it?

Thanks for your time!
Attachments
tabela.png
tabela.png (9.7 KiB) Viewed 3122 times

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

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

Center text in a table

Post by Johannes_B »

With a few extra bells and whistles:

Code: Select all

\documentclass{article}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup[table]{position=above}
\usepackage{siunitx}
\newcolumntype{C}{>{\centering\arraybackslash}m}
\begin{document}
\begin{table}[H]
	\centering
	\caption{Janelas utilizadas}
	\begin{tabular}{cSS[table-format=2.1]C{2.0cm}C{2.0cm}}
		\toprule
		Janela & {U /\si{\watt\per\meter\squared\kelvin}} & \si{\gram}     & Espessura do Envidraçado /mm& Espessura da Caixa de ar /mm\\
		\midrule
		ClimaPlus & 1,1   & 60,9  & 4  & 15 \\
		ClimaPlus & 1,43  & 60,5  & 4  & 15 \\
		Insulated & 1,27  & 62,4  & 4  & 16 \\
		\bottomrule
	\end{tabular}%
	\label{janela}%
\end{table}%
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Diogo Remoaldo
Posts: 26
Joined: Mon Apr 06, 2015 8:24 pm

Re: Center text in a table

Post by Diogo Remoaldo »

Thank you very much!
Post Reply