使用独立包创建表时出错

使用独立包创建表时出错

我正在学习使用独立包。我尝试创建一个包含表格的页面,但出现错误:

错误

Something's wrong--perhaps a missing \item. \begin{table}
Something's wrong--perhaps a missing \item. \begin{table}
Something's wrong--perhaps a missing \item. \begin{table}
Missing \endgroup inserted ...l mese per dispositivo in \si{\tera\byte}}
Missing \endgroup inserted ...l mese per dispositivo in \si{\tera\byte}}
Missing } inserted ...l mese per dispositivo in \si{\tera\byte}}
Undefined control sequence ...l mese per dispositivo in \si{\tera\byte}}
Extra \endgroup ...l mese per dispositivo in \si{\tera\byte}}
Something's wrong--perhaps a missing \item. \end{table}
\begin{document} ended by \end{table}. \end{table}
Extra \endgroup \end{table}
Too many }'s \end{document}

代码

\documentclass[12pt,a4paper]{standalone}

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{siunitx}
\sisetup{
    binary-units = true
}

\begin{document}

    \begin{table}[htp]
        \centering
        \sisetup{table-format=7.0}
        \addtolength{\tabcolsep}{-1.0pt}
        \begin{tabular}{lS[table-format=6.0]
                         S[table-format=6.0]
                         S[table-format=6.0]
                         SSS}
            \toprule
            Device & 2011 & 2012 & 2013 & 2014 & 2015 & 2016 \\
            \midrule
            Non-smarthphones & 22686 & 55813 & 108750 & 196262 & 357797 & 615679 \\
            Smarthphones & 104759 & 365550 & 933373 & 1915173 & 3257030 & 5221497 \\
            Laptops e Netbooks & 373831 & 612217 & 917486 & 1340062 & 1963950 & 2617770\\
            Tablets & 17393 & 63181 & 141153 & 300519 & 554326 & 1083895\\
            Home gateways & 55064 & 108073 & 180562 & 267545 & 376494 & 514777 \\
            M2M & 23009 & 47144 & 92150 & 172719 & 302279 & 508022 \\
            Altri devices & 525 & 1460 & 5429 & 22966 & 84204 & 242681\\
            \bottomrule
        \end{tabular}
        \caption{Traffico mobile globale al mese per dispositivo in \si{\tera\byte}}
    \end{table}

\end{document}

我是不是忘了什么包裹?错误可能出在哪里?

答案1

在浮动环境中使用该类毫无意义standalone。使用简单的 minipage 和\captionof命令:

\documentclass[12pt,a4paper]{standalone}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{siunitx}
\sisetup{binary-units = true,table-format=7.0}
\begin{document}

\minipage{1.08\textwidth}
\addtolength{\tabcolsep}{-1.0pt}
\begin{tabular}{lS[table-format=6.0]
                 S[table-format=6.0]
                 S[table-format=6.0]
                 SSS} \toprule
Device & 2011 & 2012 & 2013 & 2014 & 2015 & 2016 \\\midrule
Non-smarthphones & 22686 & 55813 & 108750 & 196262 & 357797 & 615679 \\
Smarthphones & 104759 & 365550 & 933373 & 1915173 & 3257030 & 5221497 \\
Laptops e Netbooks & 373831 & 612217 & 917486 & 1340062 & 1963950 & 2617770\\
Tablets & 17393 & 63181 & 141153 & 300519 & 554326 & 1083895\\
Home gateways & 55064 & 108073 & 180562 & 267545 & 376494 & 514777 \\
M2M & 23009 & 47144 & 92150 & 172719 & 302279 & 508022 \\
Altri devices & 525 & 1460 & 5429 & 22966 & 84204 & 242681\\ \bottomrule
\end{tabular}
\captionof{table}{Traffico mobile globale al mese per dispositivo in \si{\tera\byte}}
\endminipage

\end{document}

为什么要使用这个课程?

答案2

我认为这里的关键是将[varwidth=\maxdimen]class 选项添加到序言中。它类似于使用minipage。我删除了所有不必要的杂乱内容以保持其清晰和简单,但您可以添加您喜欢的内容。

这里其实也不需要使用\caption{TEXT},因为这是一个单独的表;没有什么可枚举的。你可以直接使用\centering TEXT,它看起来是一样的——但删除表格1:字首。

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[varwidth=\maxdimen]{standalone}
\usepackage{booktabs}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
  \begin{table}
    \begin{tabular}{lrrrrrr}
      \toprule%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      Device             & 2011   & 2012   & 2013   & 2014    & 2015    & 2016    \\
      \midrule%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      Non-smarthphones   & 22686  & 55813  & 108750 & 196262  & 357797  & 615679  \\
      Smarthphones       & 104759 & 365550 & 933373 & 1915173 & 3257030 & 5221497 \\
      Laptops e Netbooks & 373831 & 612217 & 917486 & 1340062 & 1963950 & 2617770 \\
      Tablets            & 17393  & 63181  & 141153 & 300519  & 554326  & 1083895 \\
      Home gateways      & 55064  & 108073 & 180562 & 267545  & 376494  & 514777  \\
      M2M                & 23009  & 47144  & 92150  & 172719  & 302279  & 508022  \\
      Altri devices      & 525    & 1460   & 5429   & 22966   & 84204   & 242681  \\
      \bottomrule%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \end{tabular}\caption{Traffico mobile globale al mese per dispositivo in TB}
  \end{table}
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

相关内容