How to make this particular table better looking?

  \documentclass[twoside,12pt,a4paper]{mwrep} % dwustronnie

\usepackage[inner=4cm,outer=2cm]{geometry}  % Marginesy (dwustronnie)
\usepackage[utf8]{inputenc}                 % język polski
\usepackage{polski}
\usepackage[polish]{babel, varioref}
\usepackage{graphicx}                       % wstawianie zdjęć
\usepackage{siunitx}                        % jednostki SI
\usepackage{booktabs}                       % linie poziome w tab.
\usepackage{float}                          % zafiksowanie wstawek w danym miejscu
\usepackage{array, multirow}                % pomoc do tabel
\usepackage{tabulary}                       % tabele
\usepackage{placeins}                       % FloatBarrier
\usepackage{chngcntr}                       % odmienne numerowanie tabel, obrazków itd.
\counterwithout{table}{chapter}             % numerowanie tabel po kolei 1,2,3,...

\begin{document}

\begin{tabulary}{13cm \tymax=0.4\linewidth}{CCm{2.5cm}CCC}
\toprule
Lp. & Miejscowość & \multicolumn{2}{c}{Zapotrzebowanie na wodę, $\si{m^3/\day}$} & \multicolumn{2}{c}{Odpływ ścieków, $\si{m^3/\day}$} \\
\hphantom & \hphantom & $Q_{\text{ś}rd}$ & $Q_{maxd}$ & $Q_{\text{ś}rd}$ & $Q_{maxd}$ \\
\midrule
1.    & X1 & 57,2  & 74,4  & 54,3  & 70,7 \\
2.    & X2 & 82,5  & 107,3 & 78,4  & 101,9 \\
3.    & X3 & 47,3  & 61,5  & 44,9  & 58,4 \\
4.    & X4 & 24,2  & 31,5  & 23,0  & 29,9 \\
5.    & X5 & 211,2 & 274,7 & 200,6 & 260,9 \\
\bottomrule
\end{tabulary}

\end{document}


The outcome:

I tried many things (like changing 3rd column from C to m{}, playing with \tymax and length etc.), but didn't get great effect.

• please always post full documents not just fragments, why make people guess the needed packages? – David Carlisle Mar 22 '17 at 14:16
• Why don't you use the S[table-format=3.1] column type for the last four columns? – Bernard Mar 22 '17 at 14:16
• does this syntax really work \begin{tabulary}{13cm \tymax=0.4\linewidth}{CCCCCC} with the length set inside the argument? – David Carlisle Mar 22 '17 at 14:17
• Of course it is necessary why make everyone type out a preamble to make your example work? why assume that people know booktabs (which you didn't mention) is needed. How on earth did you come up with the {13cm \tymax=0.4\linewidth} syntax!!! I wrote that package and I have never seen that (and whatever it does it does by accident!) – David Carlisle Mar 22 '17 at 14:40
• hmm I tried \usepackage{tabulary, SI, array, booktabs} that didn't work, so I tried \usepackage{tabulary, siunitx, array, booktabs} and got ! Too many }'s. \@endfloatbox . at which point I gave up, please fix your example so it produces the image shown. – David Carlisle Mar 22 '17 at 14:47

I'm afraid I can't parse your tabulary code. Here's a solution that makes use of tabularx as well as of the siunitx package to align the numbers in the four numeric columns on the decimal markers.

\documentclass{article}
\usepackage[polish]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[inner=4cm,outer=2cm]{geometry}
\usepackage{siunitx,tabularx,booktabs}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcommand\mC[1]{\multicolumn{1}{C}{#1}}
\begin{document}

\begin{table}
\centering
\begin{tabularx}{13cm}{@{}cc
*{4}{S[table-format=3.1,output-decimal-marker={,}]}@{}}
\toprule
Lp. & Miejscowość
& \multicolumn{2}{c}{Zapotrzebowanie na wodę, \si{m^3/\day}}
& \multicolumn{2}{c}{Odpływ ścieków, \si{m^3/\day}} \\
& & \mC{$Q_{\text{ś}rd}$} & \mC{$Q_{maxd}$} &
\mC{$Q_{\text{ś}rd}$} & \mC{$Q_{maxd}$} \\
\midrule
1.    & X1 & 57,2  & 74,4  & 54,3  & 70,7 \\
2.    & X2 & 82,5  & 107,3 & 78,4  & 101,9 \\
3.    & X3 & 47,3  & 61,5  & 44,9  & 58,4 \\
4.    & X4 & 24,2  & 31,5  & 23,0  & 29,9 \\
5.    & X5 & 211,2 & 274,7 & 200,6 & 260,9 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}

• Thank you, sir, it works, but now I don't fully understand the code ;p. – devloon Mar 22 '17 at 15:28
• @devloon - The tabularx-code works as follows: Even though the main column type of column 3 thru 6 is of type S, the column types for the 4 subheader cells is of type C, which is a centered version of the X type. This is what guarantees that the overall width of the table will be 13cm. – Mico Mar 22 '17 at 15:32

I would never use tabularx or tabulary for data tables such as this (even though I wrote both those packages). They are designed to affect the total table width by controlling line breaking within the cells and (apart from the heading row) you never want line breaking in such a table. You could use tabular* but forcing the table to be wider than its natural width mostly just makes the table harder to read as your eye has to scan over the gaps, so I'd use tabular.

Also never use math italic for multi-letter identifiers so not _{maxd} and certainly not \text{ś}rd changing font mid-word.

I used Mico's example as a base as it was more realistically minimal than the one in the question.

\documentclass{article}
\usepackage[polish]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[inner=4cm,outer=2cm]{geometry}
\usepackage{siunitx,tabularx,booktabs}
\newcommand\mC[1]{\multicolumn{1}{c}{#1}}
\begin{document}

\begin{table}
\centering

\begin{tabular}{@{}cc
*{4}{S[table-format=6.3,output-decimal-marker={,}]}
@{}}
\toprule
Lp. & Miejscowość
& \multicolumn{2}{@{}c}{Zapotrzebowanie na wodę, \si{m^3/\day}}
& \multicolumn{2}{c@{}}{Odpływ ścieków, \si{m^3/\day}} \\
& & \mC{$Q_{\text{śrd}}$} & \mC{$Q_{\text{maxd}}$} &
\mC{$Q_{\text{rdś}}$} & \mC{$Q_{\text{maxd}}$} \\
\midrule
1.    & X1 & 57,2  & 74,4  & 54,3  & 70,7 \\
2.    & X2 & 82,5  & 107,3 & 78,4  & 101,9 \\
3.    & X3 & 47,3  & 61,5  & 44,9  & 58,4 \\
4.    & X4 & 24,2  & 31,5  & 23,0  & 29,9 \\
5.    & X5 & 211,2 & 274,7 & 200,6 & 260,9 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

• I find it hard to tell if the top cells in the middle columns are one line or two -- I probably can't parse it because I don't know the language. I think centering the Q subcolumns under the top labels, like in @Mico 's answer would make it look better. – Scott Seidman Mar 22 '17 at 16:51
• @ScottSeidman yes I suppose so, usual issue with multicolumn being wider than the things it spans, all the width goes into the second column. I may adjust it later. – David Carlisle Mar 22 '17 at 16:53
• @ScottSeidman I adjusted the widths a bit:-) – David Carlisle Mar 22 '17 at 17:12
• Thanks! I also got a q about \newcommand\mC[1]{\multicolumn{1}{c}{#1}} . It's also used in Mico's table. What does it actually do? – devloon Mar 22 '17 at 17:29
• @Mico yes I agree that this particular table isn't really over-spread (and anyway I ended up forcing larger column separation to make the spanning headings work:-) so I wasn't positing to criticise your answer, just as I say on principle post a non tabular[xy] answer to this type of question. – David Carlisle Mar 23 '17 at 8:58