Graphics, Figures & TablesData Alignment and Improvements for a Table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
adhraklasoon
Posts: 6
Joined: Sun Sep 09, 2012 6:08 pm

Data Alignment and Improvements for a Table

Post by adhraklasoon »

Hi,

I have a table that looks half decent. A fellow member actually helped me out with another table and I tried to copy-paste some of the code to this one. But the alignment of the data is not OK. Its left aligned on 2 rows and center aligned in the others. I want it center aligned for all rows but don't know how to fix it. Help!

Also, any tips for making the table look more professional would be highly appreciated.

Thank you in advance!
Cheers
Sonia
Attachments
samplefile2.tex
(1.42 KiB) Downloaded 301 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

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Data Alignment and Improvements for a Table

Post by cgnieder »

I believe it was me who answered your previous question. Since it's late right now I only have this advice for now: I used the siunitx package to align the data. If you haven't yet you should read its documentation about tabular material: siunitx

Good night
site moderator & package author
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Data Alignment and Improvements for a Table

Post by cgnieder »

Here is what I would do. Use siunitx' possibility to treat numbers with uncertainties and choose a suiting table-format and make the mid rule span the whole table:

Code: Select all

\documentclass{article}

\usepackage{booktabs,siunitx}
\setlength\heavyrulewidth{1pt}

\begin{document}

\begin{table}[ht]
 \centering
 \sisetup{
   separate-uncertainty  = true,
   table-space-text-post = *,
   table-align-text-post = false,
   range-phrase          = --,
   range-units           = single
 }
 \begin{tabular}{l*3{S[table-format=3.1(3)]}}
  \toprule
   & {\SIrange{50}{59}{yr} (50s)}
   & {\SIrange{60}{69}{yr} (60s)}
   & {\SIrange{70}{79}{yr} (70s)} \\
  \midrule
   \textit{Male}      & {$n=40$}   & {$n=50$}   & {$n=49$} \\  
   Age, yr            &  55.2(31)  &  65.5(29)  &  73.7(29) \\  
   Height, \si{cm}    & 174.6(61)  & 174.2(57)  & 171.3(74)* \\  
   Body mass, \si{kg} &  78.3(114) &  78.9(105) &  78.4(125) \\  
  \midrule
   \textit{Female}    & {$n=42$}   & {$n=52$}   & {$n=50$} \\  
   Age, yr            &  54.7(29)  &  65.4(29)  &  73.7(24) \\  
   Height, \si{cm}    & 162.9(69)  & 163.2(62)  & 160.8(57)* \\  
   Body mass, \si{kg} &  66.8(117) &  67.9(100) &  64.7(109) \\  
  \bottomrule
 \end{tabular}
 \caption[Subject characteristics: age, height, body mass]{Subject characteristics:
   Values are  Mean $\pm$ SD; $n$=number of subjects; Males are significantly
   taller ($P<0.05$) and heavier  ($P<0.05$) than women in all age groups.
   *Significantly different from all other groups ($P<0.05$). }
 \label{subject-characs}
\end{table}

\end{document}
Regards
site moderator & package author
Post Reply