1

why is the fourth column not centered? How to fix that with keeping the style?

\documentclass[12pt,oneside,ngerman,reqno,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsthm}     % ams stuff should be before font loading
\usepackage{lmodern}
\usepackage[T1]{fontenc}        % should be after font loading
\usepackage{fixltx2e,babel}
\usepackage[numbers]{natbib}    % bibtex package
%\usepackage{typearea}           % custom type area
%   \areaset[0mm]{135mm}{210mm}  % typearea configuration
%   \topmargin5mm                % typearea configuration
\usepackage{graphicx}
\usepackage{url}

\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{subfig}
\usepackage{pgfplots}

\usepackage{floatrow}
\usepackage{hhline, array, makecell}
\setcellgapes{4pt}
\makegapedcells
%\usepackage[showframe, margin = 25mm]{geometry}
\usepackage{siunitx}
\newcolumntype{I}{S[table-format=4.0]}
\begin{document}

\begin{tabular}{@{}I|I|I|I|S[table-format = 2.2]@{}}
      {Züge\,[\#]} & {Planungsintervall\,[min]} & {Zeit\,[s]} &{ Lücke\,[\%]} & {Verbesserung\,[MW]} \\
      \hhline{ >{\arrayrulewidth = 2pt}:=:=:=:=:=:}      
   10 & 28 & 25 & 0.00 & 2.05\\ 
   20 & 36 & 12 & 0.00 & 2.79 \\
   50 & 68 & 333 & 0.00 & 1.92 \\
   100 & 122 & 1800 & 1.92 & 2.09\\ 
   200 & 127 & 1800 & 1.08 & 3.94 \\
   500 & 149 & 1800 & 21.37  & 0.00 \\
   1000 & 346 & 509 & 0.00 & 3.00\\ 
   2000 & 460 & 1514 & 0.00 & 3.06\\ 
   \hhline{ >{\arrayrulewidth = 2pt}:=:=:=:=:=:}
   \O &  & 974 & 3.04 & 2.36 \\ \hline
      \Xhline{0.8pt}
\end{tabular}
\end{document}
3
  • You've allowed space for 2 digits before the decimal point (table-format=2.2), but there's only 1 digit before the decimal point for all the data in that column. Dec 27, 2014 at 18:37
  • but 21.37 has two digits before the decimal point Dec 27, 2014 at 18:50
  • 1
    Sorry, I was looking at the last (fifth) column, which is also not centered. For the fourth, you want table-format=2.2, not 4.0... Dec 27, 2014 at 18:54

1 Answer 1

3

Several of the columns had incorrect table-formats for the data they contained, which causes them to appear un-centered.

A solution with more canonical usage of booktabs and siunitx. I've slightly adjusted the value of \tabcolsep so the table fits inside the text width.

\documentclass[12pt,oneside,ngerman,reqno,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amsthm}     % ams stuff should be before font loading
\usepackage{lmodern,babel}

\usepackage{booktabs}

\usepackage{array}
\setlength\tabcolsep{4pt} % slightly narrowed (default 6pt) to fit to text width
\usepackage{siunitx}
\newcolumntype{I}{S[table-format=4.0]}
\begin{document}
\begin{tabular}{IS[table-format=3.0]IS[table-format=2.2]S[table-format = 1.2]}
  \toprule
  {Züge/\si{\#}} & {Planungsintervall/\si{\minute}} & {Zeit/\si{\second}} &{ Lücke/\si{\percent}} & {Verbesserung/\si{\mega\watt}} \\
  \midrule
    10 &  28 &   25 &  0.00 & 2.05 \\
    20 &  36 &   12 &  0.00 & 2.79 \\
    50 &  68 &  333 &  0.00 & 1.92 \\
   100 & 122 & 1800 &  1.92 & 2.09 \\
   200 & 127 & 1800 &  1.08 & 3.94 \\
   500 & 149 & 1800 & 21.37 & 0.00 \\
  1000 & 346 &  509 &  0.00 & 3.00 \\
  2000 & 460 & 1514 &  0.00 & 3.06 \\
  \addlinespace
    \O &     &  974 &  3.04 & 2.36 \\
  \bottomrule
\end{tabular}
\end{document}

enter image description here

2
  • 1
    You could reduce further the width by setting the units in a second row.
    – egreg
    Dec 27, 2014 at 22:12
  • 1
    Or using the \thead command, from makecell, which allows for line breaks inside cells.
    – Bernard
    Dec 27, 2014 at 23:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .