4

I have this table that I want to include in my document:

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc} % kodovani
\usepackage[english,czech]{babel}  % cestina
\usepackage{siunitx,booktabs}
\sisetup{output-decimal-marker = {,}}
\begin{document}
\begin{tabular}{S[table-format = 1.1] *{5}{S[table-format=1.1]} S[table-format = 1.1] *{5}{S[table-format=1.1]} }
&\multicolumn{5}{c}{Amatérské}& & \multicolumn{5}{c}{Profesionální} \\
CPS & {0\,\si{\percent}} & {1\,\si{\percent}} & {2\,\si{\percent}} & {5\,\si{\percent}} & {10\,\si{\percent}} & &    {0\,\si{\percent}} & {1\,\si{\percent}} & {2\,\si{\percent}} & {5\,\si{\percent}} & {10\,\si{\percent}} \\
\midrule
    12 &  0   &  0   &  0   &   0   &   0   &    &  0   &   0   &   0   &   0   &   0   \\
    13 &  0   &  0   &  0   &   0   &   0   &    &  0   &   0   &   0   &   0   &   3.9 \\
    14 &  0   &  0   &  0   &   0   &   2.3 &    &  0   &   0   &   1   &   5.9 &  18.6 \\
    15 &  0   &  0   &  0   &   2.3 &   4.5 &    &  0   &   5.9 &  15.7 &  23.5 &  39.2 \\
    16 &  0   &  0   &  1.5 &   3   &  12   &    &  4.9 &  19.6 &  25.5 &  38.2 &  49   \\
    17 &  0   &  2.3 &  3   &   5.3 &  22.6 &    &  9.8 &  26.5 &  34.3 &  45.1 &  62.7 \\
    18 &  0.8 &  3   &  3.8 &  15   &  39.8 &    & 16.7 &  34.3 &  40.2 &  53.9 &  74.5 \\
    19 &  1.5 &  3.8 &  5.3 &  25.6 &  54.1 &    & 21.6 &  40.2 &  47.1 &  65.7 &  89.2 \\
    20 &  1.5 &  5.3 & 15   &  35.3 &  71.4 &    & 23.5 &  46.1 &  51   &  76.5 &  98   \\
    21 &  2.3 &  8.3 & 23.3 &  51.1 &  81.2 &    & 28.4 &  48   &  63.7 &  89.2 & 100   \\
    22 &  3.8 & 17.3 & 32.3 &  65.4 &  87.2 &    & 31.4 &  57.8 &  73.5 &  96.1 & 100   \\
    23 &  7.5 & 27.1 & 42.1 &  75.9 &  95.5 &    & 37.3 &  66.7 &  86.3 &  99   & 100   \\
    24 &  7.5 & 35.3 & 54.1 &  85.7 &  96.2 &    & 40.2 &  77.5 &  94.1 & 100   & 100   \\
    25 & 13.5 & 45.1 & 66.9 &  91.7 &  97.7 &    & 42.2 &  85.3 &  97.1 & 100   & 100   \\
    26 & 15.8 & 53.4 & 74.4 &  94.7 &  98.5 &    & 44.1 &  91.2 &  98   & 100   & 100   \\
    27 & 22.6 & 60.2 & 82.7 &  96.2 &  98.5 &    & 51   &  96.1 & 100   & 100   & 100   \\
    28 & 27.1 & 71.4 & 88   &  97   &  98.5 &    & 55.9 &  98   & 100   & 100   & 100   \\
    29 & 30.8 & 78.2 & 91   &  98.5 &  99.2 &    & 62.7 &  98   & 100   & 100   & 100   \\
    30 & 36.1 & 85   & 94   &  98.5 &  99.2 &    & 68.6 & 100   & 100   & 100   & 100   \\
    31 & 42.1 & 88.7 & 94.7 &  98.5 & 100   &    & 73.5 & 100   & 100   & 100   & 100   \\
    32 & 49.6 & 92.5 & 97.7 &  98.5 & 100   &    & 76.5 & 100   & 100   & 100   & 100   \\
    33 & 52.6 & 94.7 & 97.7 &  98.5 & 100   &    & 80.4 & 100   & 100   & 100   & 100   \\
    34 & 54.9 & 95.5 & 98.5 &  98.5 & 100   &    & 81.4 & 100   & 100   & 100   & 100   \\
    35 & 60.2 & 96.2 & 98.5 &  98.5 & 100   &    & 84.3 & 100   & 100   & 100   & 100   \\
    36 & 63.9 & 97   & 98.5 &  98.5 & 100   &    & 85.3 & 100   & 100   & 100   & 100   \\
    37 & 66.9 & 97   & 98.5 &  99.2 & 100   &    & 87.3 & 100   & 100   & 100   & 100   \\
    38 & 69.2 & 97.7 & 98.5 & 100   & 100   &    & 90.2 & 100   & 100   & 100   & 100   \\
    39 & 75.2 & 98.5 & 98.5 & 100   & 100   &    & 90.2 & 100   & 100   & 100   & 100   \\
    40 & 75.9 & 98.5 & 98.5 & 100   & 100   &    & 91.2 & 100   & 100   & 100   & 100   \\
\end{tabular}
\end{document}

It slows down the compile time of my 50-page document from under one second to about 10 seconds. Is there a way to somehow have the table precompiled so that I would not have to recompile it every time I compile the document? Or can I somehow speed it up?

  • 2
    I guess the content of the table does not change every two hours? ;-) How about using standalone class to get the table in its own pdf, nicely cropped. You can then input it using \includegraphics. – Johannes_B Jun 18 '15 at 15:47
  • I had something like that in mind, but how exactly do I do that? I have never used anything but article class, how would I crop the table suitably? Will I be able to input it into a table environment so it gets inculded in listoftables? By the way, any idea why it keeps complaining Overfull \hbox (5.87498pt too wide) detected at line 14 for avery line in the table? – sup Jun 18 '15 at 16:02
  • @sup It's complaining as you've not set the column widths correct for the content: see my answer for example – Joseph Wright Jun 18 '15 at 16:07
  • See tex.stackexchange.com/questions/111999 if you want to use \cmidrule in your tables – egreg Jun 18 '15 at 16:13
  • Just nitpicking, but instead of {1\,si{\percent}} it should be \SI{1}{\percent} - the second command exists specifically to typeset numbers with units "properly". - Edit and to me it look identical to 1\,\% without the siunitx package... (Maybe not the case if you use a different typeset) – DetlevCM Jun 18 '15 at 17:17
8

The siunitx code works by parsing numbers into separate parts then reconstructing them. This allows a lot of flexibility but is pretty inefficient for the common case of simple numerical input. You can get much faster performance by turning off the parser

\sisetup{parse-numbers = false}

This can be done globally or just inside your tables.

When the parser is off, siunitx uses the same strategy as dcolumn for centring numbers: forced math mode and some box trickery. Alignment will still take place. Importantly, this faster method will show up that your table has not got enough space reserved for the numbers! Fixing that as well gives something like

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc} % kodovani
\usepackage[english,czech]{babel}  % cestina
\usepackage{siunitx,booktabs}
\sisetup{output-decimal-marker = {,}}
\begin{document}
\sisetup{parse-numbers = false}
\begin{tabular}{
  l
  *{5}{S[table-format=3.1]} 
  S[table-format = 2]
  *{5}{S[table-format=3.1]} 
  }
&\multicolumn{5}{c}{Amatérské}& & \multicolumn{5}{c}{Profesionální} \\
CPS & {0\,\si{\percent}} & {1\,\si{\percent}} & {2\,\si{\percent}} & {5\,\si{\percent}} & {10\,\si{\percent}} & &    {0\,\si{\percent}} & {1\,\si{\percent}} & {2\,\si{\percent}} & {5\,\si{\percent}} & {10\,\si{\percent}} \\
\midrule
    12 &  0   &  0   &  0   &   0   &   0   &    &  0   &   0   &   0   &   0   &   0   \\
    13 &  0   &  0   &  0   &   0   &   0   &    &  0   &   0   &   0   &   0   &   3.9 \\
    14 &  0   &  0   &  0   &   0   &   2.3 &    &  0   &   0   &   1   &   5.9 &  18.6 \\
    15 &  0   &  0   &  0   &   2.3 &   4.5 &    &  0   &   5.9 &  15.7 &  23.5 &  39.2 \\
    16 &  0   &  0   &  1.5 &   3   &  12   &    &  4.9 &  19.6 &  25.5 &  38.2 &  49   \\
    17 &  0   &  2.3 &  3   &   5.3 &  22.6 &    &  9.8 &  26.5 &  34.3 &  45.1 &  62.7 \\
    18 &  0.8 &  3   &  3.8 &  15   &  39.8 &    & 16.7 &  34.3 &  40.2 &  53.9 &  74.5 \\
    19 &  1.5 &  3.8 &  5.3 &  25.6 &  54.1 &    & 21.6 &  40.2 &  47.1 &  65.7 &  89.2 \\
    20 &  1.5 &  5.3 & 15   &  35.3 &  71.4 &    & 23.5 &  46.1 &  51   &  76.5 &  98   \\
    21 &  2.3 &  8.3 & 23.3 &  51.1 &  81.2 &    & 28.4 &  48   &  63.7 &  89.2 & 100   \\
    22 &  3.8 & 17.3 & 32.3 &  65.4 &  87.2 &    & 31.4 &  57.8 &  73.5 &  96.1 & 100   \\
    23 &  7.5 & 27.1 & 42.1 &  75.9 &  95.5 &    & 37.3 &  66.7 &  86.3 &  99   & 100   \\
    24 &  7.5 & 35.3 & 54.1 &  85.7 &  96.2 &    & 40.2 &  77.5 &  94.1 & 100   & 100   \\
    25 & 13.5 & 45.1 & 66.9 &  91.7 &  97.7 &    & 42.2 &  85.3 &  97.1 & 100   & 100   \\
    26 & 15.8 & 53.4 & 74.4 &  94.7 &  98.5 &    & 44.1 &  91.2 &  98   & 100   & 100   \\
    27 & 22.6 & 60.2 & 82.7 &  96.2 &  98.5 &    & 51   &  96.1 & 100   & 100   & 100   \\
    28 & 27.1 & 71.4 & 88   &  97   &  98.5 &    & 55.9 &  98   & 100   & 100   & 100   \\
    29 & 30.8 & 78.2 & 91   &  98.5 &  99.2 &    & 62.7 &  98   & 100   & 100   & 100   \\
    30 & 36.1 & 85   & 94   &  98.5 &  99.2 &    & 68.6 & 100   & 100   & 100   & 100   \\
    31 & 42.1 & 88.7 & 94.7 &  98.5 & 100   &    & 73.5 & 100   & 100   & 100   & 100   \\
    32 & 49.6 & 92.5 & 97.7 &  98.5 & 100   &    & 76.5 & 100   & 100   & 100   & 100   \\
    33 & 52.6 & 94.7 & 97.7 &  98.5 & 100   &    & 80.4 & 100   & 100   & 100   & 100   \\
    34 & 54.9 & 95.5 & 98.5 &  98.5 & 100   &    & 81.4 & 100   & 100   & 100   & 100   \\
    35 & 60.2 & 96.2 & 98.5 &  98.5 & 100   &    & 84.3 & 100   & 100   & 100   & 100   \\
    36 & 63.9 & 97   & 98.5 &  98.5 & 100   &    & 85.3 & 100   & 100   & 100   & 100   \\
    37 & 66.9 & 97   & 98.5 &  99.2 & 100   &    & 87.3 & 100   & 100   & 100   & 100   \\
    38 & 69.2 & 97.7 & 98.5 & 100   & 100   &    & 90.2 & 100   & 100   & 100   & 100   \\
    39 & 75.2 & 98.5 & 98.5 & 100   & 100   &    & 90.2 & 100   & 100   & 100   & 100   \\
    40 & 75.9 & 98.5 & 98.5 & 100   & 100   &    & 91.2 & 100   & 100   & 100   & 100   \\
\end{tabular}
\end{document}
  • That works, but it is still slow (there is some speedup, but not neraly enough). I think I will go with the suggestion by @Johannes_B once I figure out how to do it:-). – sup Jun 18 '15 at 16:51
  • Could you redefine the S column type in the preamble to be a simple 'c' type during editing, and then comment it out for the final mode? – cmhughes Jun 18 '15 at 21:16
  • Well, I could do that but I am sure I would forget to change it back before printing it out afterwards:-). – sup Jun 19 '15 at 14:41
4

For simple alignments like this you can use dcolumn, but I also had to adjust the spacing to make your table fit in the page width.

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc} % kodovani
\usepackage[english,czech]{babel}  % cestina
\usepackage{siunitx,booktabs,dcolumn}
\sisetup{output-decimal-marker = {,}}
\begin{document}

\setlength\tabcolsep{3pt}
\noindent
\begin{tabular}{
D.,{2}
 *{5}{D.,{3.1}}
 p{.3em}
 *{5}{D.,{3.1}}
}
&\multicolumn{5}{c}{Amatérské}& & \multicolumn{5}{c}{Profesionální} \\
CPS & {0\,\si{\percent}} & {1\,\si{\percent}} & {2\,\si{\percent}} & {5\,\si{\percent}} & {10\,\si{\percent}} & &    {0\,\si{\percent}} & {1\,\si{\percent}} & {2\,\si{\percent}} & {5\,\si{\percent}} & {10\,\si{\percent}} \\
\midrule
    12 &  0   &  0   &  0   &   0   &   0   &    &  0   &   0   &   0   &   0   &   0   \\
    13 &  0   &  0   &  0   &   0   &   0   &    &  0   &   0   &   0   &   0   &   3.9 \\
    14 &  0   &  0   &  0   &   0   &   2.3 &    &  0   &   0   &   1   &   5.9 &  18.6 \\
    15 &  0   &  0   &  0   &   2.3 &   4.5 &    &  0   &   5.9 &  15.7 &  23.5 &  39.2 \\
    16 &  0   &  0   &  1.5 &   3   &  12   &    &  4.9 &  19.6 &  25.5 &  38.2 &  49   \\
    17 &  0   &  2.3 &  3   &   5.3 &  22.6 &    &  9.8 &  26.5 &  34.3 &  45.1 &  62.7 \\
    18 &  0.8 &  3   &  3.8 &  15   &  39.8 &    & 16.7 &  34.3 &  40.2 &  53.9 &  74.5 \\
    19 &  1.5 &  3.8 &  5.3 &  25.6 &  54.1 &    & 21.6 &  40.2 &  47.1 &  65.7 &  89.2 \\
    20 &  1.5 &  5.3 & 15   &  35.3 &  71.4 &    & 23.5 &  46.1 &  51   &  76.5 &  98   \\
    21 &  2.3 &  8.3 & 23.3 &  51.1 &  81.2 &    & 28.4 &  48   &  63.7 &  89.2 & 100   \\
    22 &  3.8 & 17.3 & 32.3 &  65.4 &  87.2 &    & 31.4 &  57.8 &  73.5 &  96.1 & 100   \\
    23 &  7.5 & 27.1 & 42.1 &  75.9 &  95.5 &    & 37.3 &  66.7 &  86.3 &  99   & 100   \\
    24 &  7.5 & 35.3 & 54.1 &  85.7 &  96.2 &    & 40.2 &  77.5 &  94.1 & 100   & 100   \\
    25 & 13.5 & 45.1 & 66.9 &  91.7 &  97.7 &    & 42.2 &  85.3 &  97.1 & 100   & 100   \\
    26 & 15.8 & 53.4 & 74.4 &  94.7 &  98.5 &    & 44.1 &  91.2 &  98   & 100   & 100   \\
    27 & 22.6 & 60.2 & 82.7 &  96.2 &  98.5 &    & 51   &  96.1 & 100   & 100   & 100   \\
    28 & 27.1 & 71.4 & 88   &  97   &  98.5 &    & 55.9 &  98   & 100   & 100   & 100   \\
    29 & 30.8 & 78.2 & 91   &  98.5 &  99.2 &    & 62.7 &  98   & 100   & 100   & 100   \\
    30 & 36.1 & 85   & 94   &  98.5 &  99.2 &    & 68.6 & 100   & 100   & 100   & 100   \\
    31 & 42.1 & 88.7 & 94.7 &  98.5 & 100   &    & 73.5 & 100   & 100   & 100   & 100   \\
    32 & 49.6 & 92.5 & 97.7 &  98.5 & 100   &    & 76.5 & 100   & 100   & 100   & 100   \\
    33 & 52.6 & 94.7 & 97.7 &  98.5 & 100   &    & 80.4 & 100   & 100   & 100   & 100   \\
    34 & 54.9 & 95.5 & 98.5 &  98.5 & 100   &    & 81.4 & 100   & 100   & 100   & 100   \\
    35 & 60.2 & 96.2 & 98.5 &  98.5 & 100   &    & 84.3 & 100   & 100   & 100   & 100   \\
    36 & 63.9 & 97   & 98.5 &  98.5 & 100   &    & 85.3 & 100   & 100   & 100   & 100   \\
    37 & 66.9 & 97   & 98.5 &  99.2 & 100   &    & 87.3 & 100   & 100   & 100   & 100   \\
    38 & 69.2 & 97.7 & 98.5 & 100   & 100   &    & 90.2 & 100   & 100   & 100   & 100   \\
    39 & 75.2 & 98.5 & 98.5 & 100   & 100   &    & 90.2 & 100   & 100   & 100   & 100   \\
    40 & 75.9 & 98.5 & 98.5 & 100   & 100   &    & 91.2 & 100   & 100   & 100   & 100   \\
\end{tabular}
\end{document}
  • I was using dcolumn before, but I dislike the way percents in the second row align with the column (I would imagine the heading to be centered above the decimal point separator) - that is the reason I used siunitx. – sup Jun 18 '15 at 16:42
0

Alright, so I went @Johannes_B's suggestion and compiled the table in a separate document and then included it as a graphics. So, the side document that generates the table goes like this (data slightly changed, but thta sohuld not matter - I use smaller font to make the table fit into the page):

\documentclass[12pt]{article}
\usepackage[active,tightpage]{preview}
\usepackage{varwidth}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[english,czech]{babel}
\usepackage{siunitx,booktabs}
\sisetup{output-decimal-marker = {,}}
\begin{document}
\begin{preview}
\begin{varwidth}{\linewidth}
\scriptsize
\begin{tabular}{S[table-format = 3] *{5}{S[table-format=3.1]} S[table-format = 1] *{5}{S[table-format=3.1]} }
&\multicolumn{5}{c}{Amatérské}& & \multicolumn{5}{c}{Profesionální} \\
CPS & {\SI{0}{\percent}} & {\SI{1}{\percent}} &{\SI{2}{\percent}} &{\SI{5}{\percent}} &{\SI{10}{\percent}} & &    {\SI{0}{\percent}} & {\SI{1}{\percent}} &{\SI{2}{\percent}} &{\SI{5}{\percent}} &{\SI{10}{\percent}} \\
\midrule
 12 &  0   &  0   &  0   &   0   &   0   &  &  0   &   0   &   0   &   0   &   0   \\
 13 &  0   &  0   &  0   &   0   &   0   &  &  0   &   0   &   0   &   0   &   3.9 \\
 14 &  0   &  0   &  0   &   0   &   2.3 &  &  0   &   0   &   1   &   5.9 &  18.6 \\
 15 &  0   &  0   &  0   &   2.3 &   4.5 &  &  0   &   5.9 &  15.7 &  23.5 &  39.2 \\
 16 &  0   &  0   &  1.5 &   3   &  12   &  &  4.9 &  19.6 &  25.5 &  38.2 &  49   \\
 17 &  0   &  2.3 &  3   &   5.3 &  22.6 &  &  9.8 &  26.5 &  34.3 &  45.1 &  62.7 \\
 18 &  0.8 &  3   &  3.8 &  15   &  39.8 &  & 16.7 &  34.3 &  40.2 &  53.9 &  74.5 \\
 19 &  1.5 &  3.8 &  5.3 &  25.6 &  54.1 &  & 21.6 &  40.2 &  47.1 &  65.7 &  89.2 \\
 20 &  1.5 &  5.3 & 15   &  35.3 &  71.4 &  & 23.5 &  46.1 &  51   &  76.5 &  98   \\
 21 &  2.3 &  8.3 & 23.3 &  51.1 &  81.2 &  & 28.4 &  48   &  63.7 &  89.2 & 100   \\
 22 &  3.8 & 17.3 & 32.3 &  65.4 &  87.2 &  & 31.4 &  57.8 &  73.5 &  96.1 & 100   \\
 23 &  7.5 & 27.1 & 42.1 &  75.9 &  95.5 &  & 37.3 &  66.7 &  86.3 &  99   & 100   \\
 24 &  7.5 & 35.3 & 54.1 &  85.7 &  96.2 &  & 40.2 &  77.5 &  94.1 & 100   & 100   \\
 25 & 13.5 & 45.1 & 66.9 &  91.7 &  97.7 &  & 42.2 &  85.3 &  97.1 & 100   & 100   \\
 26 & 15.8 & 53.4 & 74.4 &  94.7 &  98.5 &  & 44.1 &  91.2 &  98   & 100   & 100   \\
 27 & 22.6 & 60.2 & 82.7 &  96.2 &  98.5 &  & 51   &  96.1 & 100   & 100   & 100   \\
 28 & 27.1 & 71.4 & 88   &  97   &  98.5 &  & 55.9 &  98   & 100   & 100   & 100   \\
 29 & 30.8 & 78.2 & 91   &  98.5 &  99.2 &  & 62.7 &  98   & 100   & 100   & 100   \\
 30 & 36.1 & 85   & 94   &  98.5 &  99.2 &  & 68.6 & 100   & 100   & 100   & 100   \\
 31 & 42.1 & 88.7 & 94.7 &  98.5 & 100   &  & 73.5 & 100   & 100   & 100   & 100   \\
 32 & 49.6 & 92.5 & 97.7 &  98.5 & 100   &  & 76.5 & 100   & 100   & 100   & 100   \\
 33 & 52.6 & 94.7 & 97.7 &  98.5 & 100   &  & 80.4 & 100   & 100   & 100   & 100   \\
 34 & 54.9 & 95.5 & 98.5 &  98.5 & 100   &  & 81.4 & 100   & 100   & 100   & 100   \\
 35 & 60.2 & 96.2 & 98.5 &  98.5 & 100   &  & 84.3 & 100   & 100   & 100   & 100   \\
 36 & 63.9 & 97   & 98.5 &  98.5 & 100   &  & 85.3 & 100   & 100   & 100   & 100   \\
 37 & 66.9 & 97   & 98.5 &  99.2 & 100   &  & 87.3 & 100   & 100   & 100   & 100   \\
 38 & 69.2 & 97.7 & 98.5 & 100   & 100   &  & 90.2 & 100   & 100   & 100   & 100   \\
 39 & 75.2 & 98.5 & 98.5 & 100   & 100   &  & 90.2 & 100   & 100   & 100   & 100   \\
 40 & 75.9 & 98.5 & 98.5 & 100   & 100   &  & 91.2 & 100   & 100   & 100   & 100   \\
\end{tabular}
\normalsize
\end{varwidth}
\end{preview}
\end{document}

(Credits for the above solution go here: Minimize automatically the page size of the PDF outputs ) And then I include it in the master document like this (the resulting pdf from the above source file resides in ./tab/tab.pdf relative to the master document):

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{siunitx,booktabs}
\sisetup{output-decimal-marker = {,}}
\begin{document}
\begin{table}[htb]
\includegraphics{tab/tab.pdf}
\caption{\label{some_text}some more caption text}
\end{table}
\end{document}

This seems to erase the slowndown from using siunitx completely.

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.