ResizeBox Tabular 给出未定义的控制序列

ResizeBox Tabular 给出未定义的控制序列

我正在使用调整大小框来将表格调整到适合页面宽度,但它给了我一个奇怪的错误:未定义控制序列。}在 resizebox 的末尾。我发现它可能与需要转义的 & 符号有关,但我不知道该怎么做。有什么想法可以解决这个问题吗?

这是我的桌子:

\begin{table}[ht]
    \caption{Cars Database} % title of Table
    \label{tab:carsDB}
    \centering % used for centering table
    \resizebox{\textwidth}{!}{
        \begin{tabular}{@{\makebox[0em][r]{\rownumber\space}}|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
            \cline{1-14}
            \rowcolor{LightGray}
            Make & Model & Price & Location & Year & \thead{Start\\ Production\\ Year} & Color & Mileage & \thead{Length\\ (mm)} & \thead{Power\\ (kw)} & EngineCC & \thead{Torque\\ (Nm)} & \thead{Consumption (US mpg)\\ Urban/Extra Urban/Combined} & Fuel
            \gdef\rownumber{\stepcounter{magicrownumbers}\arabic{magicrownumbers}}
            \\
            \cline{1-14}
            Ford & Focus 1.6tdci & 6500 & Pittsburgh (PA) & 2007 & 2004 & Red & 60000 & 4342 & 80 & 1560 & 260 & 37.97/58.78/49.04 & Diesel\\
            \cline{1-14}
            Mazda & 3 td & 8000 & Denver (CO) & 2009 & 2009 & Gray & 45000 & 4580 & 80 & 1560 & 240 & 44.38/60.28/53.45 & Diesel\\
            \cline{1-14}
            Ford & Focus 1.3tdci & 11000 & San Diego(CA) & 2010 & 2010 & Blue & 15000 & 4337 & 85 & 1560 & 270 & 52.29/69.19/61.86 & Diesel\\
            \cline{1-14}
            Ford & Focus 1.6i 16V & 3000 & Austin(TX) & 2005 & 2004 & Blue & 48000 & 4342 & 73.8 & 1596 & 150 & 21.56/38.55/30.14 & Gasoline\\
            \cline{1-14}
            Volkswagen & Golf 1.6tdi & 12000 & Las Vegas(NV) & 2008 & 2008 & Black & 70000 & 4199 & 77 & 1598 & 250 & 41.30/60.28/52.29 & Diesel\\
            \cline{1-14}
            Ford & Focus 1.6tdci & 12300 & Seattle(WA) & 2011 & 2010 & Gray & 8000 & 4337 & 85 & 1560 & 270 & 52.29/69.19/61.86 & Diesel\\
            \cline{1-14}
            Volkswagen & Golf 1.6tdi & 14000 & Miami(FL) & 2009 & 2008 & Gray & 50000 & 4199 & 77 & 1598 & 250 & 41.30/60.28/52.29 & Diesel\\
            \cline{1-14}
            Toyota & Avensis 1.8 16V SW & 6000 & New Orleans(LU) & 2005 & 2003 & Red & 38000 & 4700 & 95 & 1794 & 170 & 25.06/40.55/32.64 & Gasoline\\
            \cline{1-14}
            Ford & Focus 1.6tdci & 5000 & Chicago(IL) & 2006 & 2004 & White & 66000 & 4342 & 80 & 1560 & 260 & 37.97/58.78/49.04 & Diesel\\
            \cline{1-14}
            Ford & Fiesta 1.4 16V & 7000 & Charleston(SC) & 2009 & 2008 & Black & 27000 & 3950 & 71 & 1388 & 125 & 31.39/51.12/41.30 & Gasoline\\
            \cline{1-14}
        \end{tabular}
    }
\end{table}

更新

\usepackage{makecell}
\usepackage{array,etoolbox}
\preto\tabular{\setcounter{magicrownumbers}{0}}
\newcounter{magicrownumbers}

答案1

对于如此宽的桌子,您应该sidewaystablerotating包装中考虑。

无论如何,你需要定义\rownumber无论如何,你还外部供企业工作的桌子。

\documentclass{article}
\usepackage{graphicx} % <- for \resizebox
\usepackage[table,svgnames]{xcolor} % <- for \rowcolor
\usepackage{makecell}
\usepackage{array,etoolbox}

\preto\tabular{\setcounter{magicrownumbers}{0}}
\newcounter{magicrownumbers}

\begin{document}

\begin{table}[ht]

    \caption{Cars Database} % title of Table
    \label{tab:carsDB}

\gdef\rownumber{}

    \resizebox{\textwidth}{!}{% <- important %
        \begin{tabular}{@{\makebox[0em][r]{\rownumber\space}}|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
            \cline{1-14}
            \rowcolor{LightGray}
            Make & Model & Price & Location & Year & \thead{Start\\ Production\\ Year} & Color & Mileage & \thead{Length\\ (mm)} & \thead{Power\\ (kw)} & EngineCC & \thead{Torque\\ (Nm)} & \thead{Consumption (US mpg)\\ Urban/Extra Urban/Combined} & Fuel%
            \gdef\rownumber{\stepcounter{magicrownumbers}\arabic{magicrownumbers}}
            \\
            \cline{1-14}
            Ford & Focus 1.6tdci & 6500 & Pittsburgh (PA) & 2007 & 2004 & Red & 60000 & 4342 & 80 & 1560 & 260 & 37.97/58.78/49.04 & Diesel\\
            \cline{1-14}
            Mazda & 3 td & 8000 & Denver (CO) & 2009 & 2009 & Gray & 45000 & 4580 & 80 & 1560 & 240 & 44.38/60.28/53.45 & Diesel\\
            \cline{1-14}
            Ford & Focus 1.3tdci & 11000 & San Diego(CA) & 2010 & 2010 & Blue & 15000 & 4337 & 85 & 1560 & 270 & 52.29/69.19/61.86 & Diesel\\
            \cline{1-14}
            Ford & Focus 1.6i 16V & 3000 & Austin(TX) & 2005 & 2004 & Blue & 48000 & 4342 & 73.8 & 1596 & 150 & 21.56/38.55/30.14 & Gasoline\\
            \cline{1-14}
            Volkswagen & Golf 1.6tdi & 12000 & Las Vegas(NV) & 2008 & 2008 & Black & 70000 & 4199 & 77 & 1598 & 250 & 41.30/60.28/52.29 & Diesel\\
            \cline{1-14}
            Ford & Focus 1.6tdci & 12300 & Seattle(WA) & 2011 & 2010 & Gray & 8000 & 4337 & 85 & 1560 & 270 & 52.29/69.19/61.86 & Diesel\\
            \cline{1-14}
            Volkswagen & Golf 1.6tdi & 14000 & Miami(FL) & 2009 & 2008 & Gray & 50000 & 4199 & 77 & 1598 & 250 & 41.30/60.28/52.29 & Diesel\\
            \cline{1-14}
            Toyota & Avensis 1.8 16V SW & 6000 & New Orleans(LU) & 2005 & 2003 & Red & 38000 & 4700 & 95 & 1794 & 170 & 25.06/40.55/32.64 & Gasoline\\
            \cline{1-14}
            Ford & Focus 1.6tdci & 5000 & Chicago(IL) & 2006 & 2004 & White & 66000 & 4342 & 80 & 1560 & 260 & 37.97/58.78/49.04 & Diesel\\
            \cline{1-14}
            Ford & Fiesta 1.4 16V & 7000 & Charleston(SC) & 2009 & 2008 & Black & 27000 & 3950 & 71 & 1388 & 125 & 31.39/51.12/41.30 & Gasoline\\
            \cline{1-14}
        \end{tabular}% <- important %
    }
\end{table}

\end{document}

检查<-我所做的修复。

在此处输入图片描述

相关内容