4

I need help with this table. Values ​​are aligned to 5 decimal places and I must use dcolumn enter image description here

\documentclass[10pt,a4paper,twoside]{article}
\usepackage{dcolumn} 
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}


\begin{table}[h!]
\begin{center}
\caption{Experimentální výsledky}
\label{tab:table1}
    \begin{tabular}{ l c c r r r }
\toprule
 & $\alpha$ & $\beta$ & $\gamma$ & $\delta$ & $\chi$ \\ \hline
 Pokus 1 & 9,03983 & 20,7265 & 70,905 & -31,83 & -75,2 \\ \hline
 \multirow{4}{*}{Pokus 2} & 84,99683 & -88,7 & 33,551 & 83,436 & -59,9\\ 
         & -67 & -81,46 & -98 & 54,0456 & -28\\ 
         & -23,8 & -63 & -9,47 & 58,03674 & -89,1\\ 
         & -61,4 & -68,19 & -13,2 & -80,2 & -47,3\\ \hline
 Pokus 6 & -87,94 & -52 & 68,548 & 17,0284 & -49,1 \\ \hline
 Pokus 7 & -72,55 & -66,06 & -50 & -66,3 & 92,27074\\ \hline
 Pokus 8 & 12,475 & 73,464 & 23,9323 & 52,959 & -87,71\\ \hline
 Pokus 9 & 99,24615 & -27,17 & 49,5099 & 88,7448 & 87,22619\\ \hline
 Pokus 10 & 99,268 & 83,8816 & -94,4 & -25,5 & 47,873\\
\bottomrule
    \end{tabular}
\end{center}
\end{table}
\end{document}

This is what I getenter image description here

  • 2
    Welcome to TeX.SE. I appreciate that you've formatted your code. To clarify, is the picture your desired output, but you're not quite there yet? And you want to use dcolumn to align on the decimal? (Also, instead of making each line code by itself, it's better to highlight the entire thing and click {} to make a block of code. And if you can start off with \documentclass{article}\begin{document}, then we can copy and paste this into a blank tex file.) – Teepeemm Apr 22 at 14:17
  • I can't really get the question. How would you like it to be? – antshar Apr 22 at 14:18
  • The first picture is as it should be. I have this ctrlv.cz/FlNX – Alfred Apr 22 at 14:24
  • Why should you use dcolumn and not siunitx? – egreg Apr 22 at 15:24
  • 1
    @Alfred: Can you use a better title for you question? Something that's more specific that "Help with table". – Werner Apr 22 at 15:47
5

The changes I made with respect to your MWE are the following:

  1. you can use \centering instead of \begin{center} ... \end{center} inside the table environment
  2. you need to embed the content of the first row (the heading) in a \multicolumn{1}{c}{} command to override the D column type
  3. the syntax *{n}{t} allows you to define n columns of type t
  4. I added the \otoprule separator so that you can have the same line thickness of \toprule but equal spacing between the rows for the headings
  5. the extra spacing between the columns (which appears in your reference image) can be achieved with \setlength{\tabcolsep}{10pt}. Instead of 10pt you can put the length you prefer. If you want to stick with the default column spacing, just comment out the line.
  6. Even though in your reference image the caption is at the bottom of the table, it is better to keep it on top, as you already did.

So you have:

\documentclass[10pt,a4paper,twoside]{article}
\usepackage{dcolumn}
\usepackage{booktabs}
\usepackage{multirow}

\newcommand{\otoprule}{\midrule[\heavyrulewidth]} % vertically centered with respect to the row above and below, but same thickness as \{top,bottom}rule

\begin{document}

\begin{table}[h!]
    \centering
    \caption{Experimentální výsledky}
    \label{tab:table1}
    \setlength{\tabcolsep}{10pt}
    \begin{tabular}{l *{5}{D{,}{,}{3.5}}}
        \toprule
        & \multicolumn{1}{c}{$\alpha$} & \multicolumn{1}{c}{$\beta$} & \multicolumn{1}{c}{$\gamma$} & \multicolumn{1}{c}{$\delta$} & \multicolumn{1}{c}{$\chi$} \\ \otoprule
        Pokus 1                  & 9,03983  & 20,7265 & 70,905  & -31,83   & -75,2      \\ \midrule
        \multirow{4}{*}{Pokus 2} & 84,99683 & -88,7   & 33,551  & 83,436   & -59,9      \\
                                 & -67      & -81,46  & -98     & 54,0456  & -28        \\
                                 & -23,8    & -63     & -9,47   & 58,03674 & -89,1      \\
                                 & -61,4    & -68,19  & -13,2   & -80,2    & -47,3      \\ \midrule
        Pokus 6                  & -87,94   & -52     & 68,548  & 17,0284  & -49,1      \\ \midrule
        Pokus 7                  & -72,55   & -66,06  & -50     & -66,3    & 92,27074   \\ \midrule
        Pokus 8                  & 12,475   & 73,464  & 23,9323 & 52,959   & -87,71     \\ \midrule
        Pokus 9                  & 99,24615 & -27,17  & 49,5099 & 88,7448  & 87,22619   \\ \midrule
        Pokus 10                 & 99,268   & 83,8816 & -94,4   & -25,5    & 47,873     \\
        \bottomrule
    \end{tabular}
\end{table}

\end{document}

enter image description here

| improve this answer | |
  • Thank you guys you are awesome! – Alfred Apr 22 at 15:12
  • 1
    Thanks! consider upvoting/accepting the answer ;) – Alessandro Cuttin Apr 22 at 15:18
  • 2
    +1. Do change D{,}{,}{2.5} to D{,}{,}{3.5}, though, in order to leave space for the - ("minus") symbols. – Mico Apr 22 at 15:23
  • Indeed better, thanks! – Alessandro Cuttin Apr 22 at 15:38
  • 1
    I'm pretty sure that you not need to load the dcolumn package twice :-) – Zarko Apr 22 at 21:08
4

With siunitx and correct defined numbers format the MWE is:

\documentclass[10pt,a4paper,twoside]{article}
\usepackage{booktabs, multirow}
\usepackage{siunitx}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{table}[h!]
    \centering
    \sisetup{output-decimal-marker={,}}
\caption{Experimentální výsledky}
\label{tab:table1}
\begin{tabular}{ l S[table-format=-2.5]
              *{2}{S[table-format=-2.4]}
              *{2}{S[table-format=-2.5]}
               }
        \toprule
        & {$\alpha$} & {$\beta$} & {$\gamma$} & {$\delta$} & {$\chi$} \\ 
        \midrule
Pokus 1     & 9,03983  & 20,7265 & 70,905  & -31,83   & -75,2 \\ 
        \midrule
Pokus 1     & 9,03983  & 20,7265 & 70,905  & -31,83   & -75,2 \\ \hline
\multirow{4}{*}{Pokus 2}
            & 84,99683 & -88,7   & 33,551  & 83,436   & -59,9       \\
            & -67      & -81,46  & -98     & 54,0456  & -28         \\
            & -23,8    & -63     & -9,47   & 58,03674 & -89,1       \\
            & -61,4    & -68,19  & -13,2   & -80,2    & -47,3       \\
    \midrule
Pokus 6     & -87,94   & -52     & 68,548  & 17,0284  & -49,1       \\
Pokus 7     & -72,55   & -66,06  & -50     & -66,3    & 92,27074    \\
Pokus 8     & 12,475   & 73,464  & 23,9323 & 52,959   & -87,71      \\
Pokus 9     & 99,24615 & -27,17  & 49,5099 & 88,7448  & 87,22619    \\
Pokus 10    & 99,268   & 83,8816 & -94,4   & -25,5    & 47,873      \\
    \bottomrule
\end{tabular}
    \end{table}
\end{document}

enter image description here

(red lines indicate text borders)

siunitx enable simple rounding all number for example to three decimal digits:

\documentclass[a4paper,twoside]{article}
\usepackage{booktabs, multirow}
\usepackage{siunitx}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{table}[h!]
    \centering
    \sisetup{output-decimal-marker={,},
             round-mode=places,
             round-precision=3,
             round-integer-to-decimal,
             table-format=-2.3            
             }          
\caption{Experimentální výsledky}
\label{tab:table1}
\begin{tabular}{ l *{5}{S} }
        \toprule
        & {$\alpha$} & {$\beta$} & {$\gamma$} & {$\delta$} & {$\chi$} \\ 
        \midrule
Pokus 1     & 9,03983  & 20,7265 & 70,905  & -31,83   & -75,2 \\ 
        \midrule
\multirow{4}{*}{Pokus 2}
            & 84,99683 & -88,7   & 33,551  & 83,436   & -59,9       \\
            & -67      & -81,46  & -98     & 54,0456  & -28         \\
            & -23,8    & -63     & -9,47   & 58,03674 & -89,1       \\
            & -61,4    & -68,19  & -13,2   & -80,2    & -47,3       \\
    \midrule
Pokus 6     & -87,94   & -52     & 68,548  & 17,0284  & -49,1       \\
Pokus 7     & -72,55   & -66,06  & -50     & -66,3    & 92,27074    \\
Pokus 8     & 12,475   & 73,464  & 23,9323 & 52,959   & -87,71      \\
Pokus 9     & 99,24615 & -27,17  & 49,5099 & 88,7448  & 87,22619    \\
Pokus 10    & 99,268   & 83,8816 & -94,4   & -25,5    & 47,873      \\
    \bottomrule
\end{tabular}
    \end{table}
\end{document}

enter image description here

| improve this answer | |
  • @Mico, you are right. I will add option for them asap. – Zarko Apr 22 at 15:34
  • +1. At first, I went for siunitx on istinct myself ;) – Alessandro Cuttin Apr 22 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.