0

I need the numbers in the following table aligned by ":". Unfortunately the additional "," in the numbers causes some problems which I can't solve.

\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{siunitx}
\sisetup{locale = DE}

\begin{document}
    \begin{tabular}{@{}
            l %
            S[input-decimal-markers={:},table-format=2,1:1, output-decimal-markers={:}] %
            S[input-decimal-markers={:},table-format=1,1:1, output-decimal-markers={:}] %
            @{}}
        Jahr & {\begin{tabular}[l]{@{}l@{}}Unkomplizierte\\ Leistenhernie\end{tabular}} & {\begin{tabular}[l]{@{}l@{}}Inkarzerierte\\ Leistenhernie\end{tabular}}\\ 
        1976 & 10,0:1 & 6,3:1\\
        1977 & 8,7:1 & 5,6:1\\
        1978 & 8,8:1 & 7,4:1\\
        1979 & 8,4:1 & 7,0:1\\
        1980 & 8,0:1 & 5,6:1\\
    \end{tabular}
\end{document}
2
  • Could you explain a bit more, what that colon stands for? Why don't you align at the comma instead, which would look the same?
    – LaRiFaRi
    Commented Oct 24, 2014 at 7:10
  • well, sometimes the easiest solution is the one we are not thinking of. Works great with format=2.1 and table-space-text-post, thank you!
    – traily
    Commented Oct 24, 2014 at 14:49

2 Answers 2

1

You could just align all numbers with their comma and add some extra space for the :1. This will look exactly like what you tried to do. Is the colon really the decimal marker? Or did you try to hack around here?

% arara: pdflatex

\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{siunitx}
\sisetup{locale = DE}

\begin{document}
    \begin{tabular}{@{}
            l %
            S[table-format=2.1, table-space-text-post = :1] %
            S[table-format=1.1, table-space-text-post = :1] %
            @{}}
        Jahr & {\begin{tabular}{@{}l@{}}Unkomplizierte\\ Leistenhernie\end{tabular}} & {\begin{tabular}{@{}l@{}}Inkarzerierte\\ Leistenhernie\end{tabular}}\\ 
        1976 & 10,0:1 & 6,3:1\\
        1977 & 8,7:1 & 5,6:1\\
        1978 & 8,8:1 & 7,4:1\\
        1979 & 8,4:1 & 7,0:1\\
        1980 & 8,0:1 & 5,6:1\\
    \end{tabular}
\end{document}

enter image description here

4
  • if it is always :1 a much nicer solution!
    – MaxNoe
    Commented Oct 24, 2014 at 10:00
  • @MaxNoe Just replace table-space-text-post = :1 to whatever you append. This works just fine. Only problem: When one value has more or less then 1 decimal digit, you will have to change the table-format accordingly and you will get a space in front of the colon.
    – LaRiFaRi
    Commented Oct 24, 2014 at 12:00
  • Is it always the same fir every row? How would i get something like 1,3:1 \\1,3:4
    – MaxNoe
    Commented Oct 24, 2014 at 12:04
  • @MaxNoe As 4 is wider than 1, I would use [table-format=1.1, table-space-text-post = :4] in this column.
    – LaRiFaRi
    Commented Oct 24, 2014 at 12:11
0

Add an additional column for the numbers after the : and connect them with the ::. Also you should use the package booktabs and its commands \toprule, \midrule and \bottomrule

\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{siunitx}
\sisetup{locale = DE}

\usepackage{booktabs}

\begin{document}
    \begin{tabular}{
            l %
            S[table-format=2.1, table-alignment=right] %
            @{:}
            S[table-format=1.0, table-alignment=left] %
            S[table-format=2.1, table-alignment=right] %
            @{:}
            S[table-format=1.0, table-alignment=left] %
            }
        \toprule
        Jahr & \multicolumn{2}{c}{\begin{tabular}[l]{@{}l@{}}Unkomplizierte\\ Leistenhernie\end{tabular}} & \multicolumn{2}{c}{\begin{tabular}[l]{@{}l@{}}Inkarzerierte\\ Leistenhernie\end{tabular}}\\ 
        \midrule
        1976 & 10,0 & 1 & 6,3 & 1\\
        1977 & 8,7  & 1 & 5,6 & 1\\
        1978 & 8,8  & 1 & 7,4 & 1\\
        1979 & 8,4  & 1 & 7,0 & 1\\
        1980 & 8,0  & 1 & 5,6 & 1\\
        \bottomrule
    \end{tabular}
\end{document}

As you are writing german, you should have a look at the KomaScript Classes, which aare more suitable for european standards.

You must log in to answer this question.

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