使用 siunitx 创建的表格来加速文档的编译

使用 siunitx 创建的表格来加速文档的编译

我有一张想要包含在我的文档中的表格:

\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}

它将我 50 页文档的编译时间从不到一秒减慢到大约 10 秒。有没有办法以某种方式预编译表格,这样我就不必每次编译文档时都重新编译它?或者我可以以某种方式加快速度吗?

答案1

代码siunitx的工作原理是将数字解析成单独的部分,然后重建它们。这提供了很大的灵活性,但对于简单的数字输入的常见情况来说效率很低。您可以通过关闭解析器来获得更快的性能

\sisetup{parse-numbers = false}

这可以在全局完成或者仅在表内完成。

当解析器关闭时,siunitx使用与居中数字相同的策略dcolumn:强制数学模式和一些框技巧。对齐仍将发生。重要的是,这种更快的方法将显示您的表格没有足够的空间保留给数字!修复这个问题也会产生类似

\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}

答案2

对于像这样的简单对齐,您可以使用dcolumn,但我还必须调整间距以使您的表格适合页面宽度。

\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}

答案3

好吧,所以我采纳了@Johannes_B 的建议,将表格编译成一个单独的文档,然后将其作为图形包含在内。因此,生成表格的附加文档如下所示(数据略有变化,但那应该没关系 - 我使用较小的字体使表格适合页面):

\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}

(上述解决方案的来源如下:自动最小化 PDF 输出的页面尺寸)然后我将它包含在主文档中,如下所示(上述源文件生成的 pdf 位于./tab/tab.pdf主文档中):

\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}

这似乎完全消除了使用过程中的减速siunitx

相关内容