我正在尝试生成一个长表,看起来像附图中所示。出于某种原因,我得到了以下错误。我真的不知道错误可能出在哪里。有人遇到过这种问题吗?
\documentclass{article}
\usepackage{xltabular}
\usepackage{tabularx,booktabs,amsmath}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\newcolumntype{Z}{>{\raggedright\arraybackslash}X}
\newcolumntype{P}{>{\centering\arraybackslash}p{\hsize}}
\newcommand\mytab[1]{\smash[b]{%
\begin{tabular}[t]{@{} P @{}} #1 \end{tabular}}}
\newcommand\headdefpotential{% Added to avoid repeating parts
\toprule
\mytab{\textbf{Region area}} &
\mytab{\textbf{Quality class}} &
\mytab{\textbf{Distance-to-grid}} &
\mytab{\textbf{PV [km$^2$]}} &
\mytab{\textbf{PV [GW]}} &
\mytab{\textbf{Wind [km$^2$]}} &
\mytab{\textbf{Wind [GW]}} \\
\midrule}
\begin{document}
\section{Potential area analysis}
\begin{xltabular}{\linewidth}{@{}p{0.1\textwidth}p{0.13\textwidth}p{0.2\textwidth}YYYY@{}}
\caption{Potential area analysis results per technology, model region and applied categorisation}\label{potential analysis}
\headdefpotential\endfirsthead
\caption{Potential area analysis results per technology, model region and applied categorisation \textit{(Continued)}} \\[-2ex]
\headdefpotential\endhead
%%% The footer
\bottomrule\endfoot
CHL0 & Quality class 1 & EE/PtX: GD\_0-2km & 711.98 & 59.33 &4422.83 &110.57 \\
& & EE/PtX: GD\_2-4km &41.50 &3.46 & 354.36 & 8.86 \\
& & EE: GD\_0-2km & 0.00 &0.00 & 836.08 & 20.90 \\
& & EE: GD\_2-4km & 0.00 &0.00 & 71.58 & 1.79 \\
& & PtX: island & 1197.01 & 99.75 & 18815.82 &470.40 \\
\cmidrule{2-7}
& Quality class 2 & EE/PtX: GD\_0-2km & 6808.21 & 567.33 &4290.42 &107.26 \\
& & EE/PtX: GD\_2-4km & 498.66 & 41.55 & 294.84 & 7.37 \\
& & EE: GD\_0-2km &79.06 &6.59 &3203.33 & 80.08 \\
& & EE: GD\_2-4km & 637.75 & 53.14 & 257.49 & 6.44 \\
& & PtX: island &22140.51 &1844.97 & 16646.72 &416.17 \\
\cmidrule{2-7}
& Quality class 3 & EE/PtX: GD\_0-2km & 1905.41 & 158.78 & 713.39 & 17.83 \\
& & EE/PtX: GD\_2-4km & 164.78 & 13.73 & 55.86 & 1.40 \\
& & EE: GD\_0-2km & 404.59 & 33.71 & 797.14 & 19.93 \\
& & EE: GD\_2-4km & 3235.32 & 269.60 & 58.23 & 1.46 \\
& & PtX: island &17178.89 &1431.52 &5055.52 &126.39 \\
\midrule
CHL1 & Quality class 1 & EE/PtX: GD\_0-2km & 1238.04 & 103.17 &2638.44 & 65.96 \\
& & EE/PtX: GD\_2-4km &65.65 &5.47 & 166.51 & 4.16 \\
& & EE: GD\_0-2km & 107.67 &8.97 & 516.03 & 12.90 \\
& & EE: GD\_2-4km & 2.35 &0.20 & 26.71 & 0.67 \\
& & PtX: island & 1698.48 & 141.53 &7753.24 &193.83 \\
\cmidrule{2-7}
& Quality class 2 & EE/PtX: GD\_0-2km & 1669.85 & 139.15 & 901.26 & 22.53 \\
& & EE/PtX: GD\_2-4km &90.35 &7.53 & 51.99 & 1.30 \\
& & EE: GD\_0-2km & 427.50 & 35.62 & 136.97 & 3.42 \\
& & EE: GD\_2-4km &21.25 &1.77 & 9.43 & 0.24 \\
& & PtX: island & 3491.94 & 290.98 &2794.36 & 69.86 \\
\cmidrule{2-7}
& Quality class 3 & EE/PtX: GD\_0-2km & 1646.11 & 137.17 &1016.66 & 25.42 \\
& & EE/PtX: GD\_2-4km & 121.23 & 10.10 & 58.78 & 1.47 \\
& & EE: GD\_0-2km & 159.34 & 13.28 & 41.51 & 1.04 \\
& & EE: GD\_2-4km &17.56 &1.46 & 5.01 & 0.13 \\
& & PtX: island & 6448.14 & 537.32 &1094.38 & 27.36 \\
\midrule
CHL2 & Quality class 1 & EE/PtX: GD\_0-2km &19.72 &1.64 & 525.33 & 13.13 \\
& & EE/PtX: GD\_2-4km & 0.67 &0.06 & 29.59 & 0.74 \\
& & EE: GD\_0-2km & 0.00 &0.00 & 2.39 & 0.06 \\
& & EE: GD\_2-4km & 0.00 &0.00 & 0.87 & 0.02 \\
& & PtX: island & 123.64 & 10.30 &1225.14 & 30.63 \\
\cmidrule{2-7}
& Quality class 2 & EE/PtX: GD\_0-2km & 406.13 & 33.84 & 345.18 & 8.63 \\
& & EE/PtX: GD\_2-4km &22.65 &1.89 & 28.07 & 0.70 \\
& & EE: GD\_0-2km & 0.00 &0.00 & 30.51 & 0.76 \\
& & EE: GD\_2-4km & 0.00 &0.00 & 1.49 & 0.04 \\
& & PtX: island & 269.63 & 22.47 &3067.61 & 76.69 \\
\cmidrule{2-7}
& Quality class 3 & EE/PtX: GD\_0-2km & 0.00 &0.00 & 990.36 & 24.76 \\
& & EE/PtX: GD\_2-4km & 0.00 &0.00 & 76.24 & 1.91 \\
& & EE: GD\_0-2km & 0.00 &0.00 & 0.14 & 0.00 \\
& & EE: GD\_2-4km & 0.00 &0.00 & 0.00 & 0.00 \\
& & PtX: island & 390.59 & 32.55 &9541.80 &238.55 \\
\bottomrule
\end{xltabular}
\end{document}
答案1
楼主发布的代码并没有出现上面显示的错误消息。该消息确实表明存在问题,这是由于行末! Misplaced \noalign.
缺少指令造成的\\
\caption{Potential area analysis...}\label{potential analysis}
这里有一个解决方案可以解决这个问题,并对代码进行一些额外的调整,包括将四个数据列中的数字与小数点对齐,简化第 2 列中的材料,不允许第 3 列换行,以及\cmidrule
用\addlinespace
(以创建更开放和吸引人的“外观”)替换指令。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xltabular} % for 'xltabular' environment
\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{amsmath} % for \smash[b] macro
\usepackage[skip=0.333\baselineskip]{caption}
\usepackage{ragged2e} % \Centering & \RaggedRight macros
\newcolumntype{Y}{>{\Centering}X}
\newcolumntype{P}{>{\RaggedRight}p{\hsize}}
\newcolumntype{Q}{>{\Centering}p{\hsize}}
\newcommand\mytab[1]{\smash[b]{%
\begin{tabular}[t]{@{} Q @{}} #1 \end{tabular}}}
\usepackage{siunitx}
\newcolumntype{T}[1]{S[table-format=#1,group-digits=false]}
\newcommand\mY[1]{\multicolumn{1}{Y}{#1}}
\newcommand\headdefpotential{% Added to avoid repeating parts
\toprule
\mytab{{Region area}} &
\mytab{{Quality class}} &
{Distance to grid} &
\mY{{PV} [km\textsuperscript{2}]} &
\mY{{PV} [GW]} &
\mY{{Wind} [km\textsuperscript{2}]} &
\mY{{Wind} [GW]} \\
\midrule}
\begin{document}
\section{Potential area analysis}
\enlargethispage{0.5\baselineskip} % optional
\begingroup %localize scope of next 2 instructions
\setlength\tabcolsep{3pt} % default: 6pt
\setlength\LTcapwidth{\textwidth}
\begin{xltabular}{\linewidth}{@{}
p{0.1\textwidth}
>{\Centering}p{0.1\textwidth}
l T{5.2} T{4.2} T{5.2} T{3.2} @{}}
\caption{Potential area analysis results per technology,
model region and applied categorisation}
\label{potential analysis} \\ % <-- " \\" is new
\headdefpotential
\endfirsthead
\multicolumn{7}{@{}l@{}}{Table \thetable, continued} \\[0.5ex]
\headdefpotential
\endhead
%%% The footers
\multicolumn{7}{r@{}}{\itshape\small(cont'd on next page)} \\
\endfoot
\bottomrule
\endlastfoot
CHL0 & 1& EE/PtX: GD\_0--2km & 711.98 & 59.33 & 4422.83 & 110.57 \\
& & EE/PtX: GD\_2--4km & 41.50 & 3.46 & 354.36 & 8.86 \\
& & EE: GD\_0--2km & 0.00 & 0.00 & 836.08 & 20.90 \\
& & EE: GD\_2--4km & 0.00 & 0.00 & 71.58 & 1.79 \\
& & PtX: island & 1197.01 & 99.75 & 18815.82 & 470.40 \\
\addlinespace
& 2& EE/PtX: GD\_0--2km & 6808.21 & 567.33 & 4290.42 & 107.26 \\
& & EE/PtX: GD\_2--4km & 498.66 & 41.55 & 294.84 & 7.37 \\
& & EE: GD\_0--2km & 79.06 & 6.59 & 3203.33 & 80.08 \\
& & EE: GD\_2--4km & 637.75 & 53.14 & 257.49 & 6.44 \\
& & PtX: island & 22140.51 & 1844.97 & 16646.72 & 416.17 \\
\addlinespace
& 3& EE/PtX: GD\_0--2km & 1905.41 & 158.78 & 713.39 & 17.83 \\
& & EE/PtX: GD\_2--4km & 164.78 & 13.73 & 55.86 & 1.40 \\
& & EE: GD\_0--2km & 404.59 & 33.71 & 797.14 & 19.93 \\
& & EE: GD\_2--4km & 3235.32 & 269.60 & 58.23 & 1.46 \\
& & PtX: island & 17178.89 & 1431.52 & 5055.52 & 126.39 \\
\midrule
CHL1 & 1& EE/PtX: GD\_0--2km & 1238.04 & 103.17 & 2638.44 & 65.96 \\
& & EE/PtX: GD\_2--4km & 65.65 & 5.47 & 166.51 & 4.16 \\
& & EE: GD\_0--2km & 107.67 & 8.97 & 516.03 & 12.90 \\
& & EE: GD\_2--4km & 2.35 & 0.20 & 26.71 & 0.67 \\
& & PtX: island & 1698.48 & 141.53 & 7753.24 & 193.83 \\
\addlinespace
& 2& EE/PtX: GD\_0--2km & 1669.85 & 139.15 & 901.26 & 22.53 \\
& & EE/PtX: GD\_2--4km & 90.35 & 7.53 & 51.99 & 1.30 \\
& & EE: GD\_0--2km & 427.50 & 35.62 & 136.97 & 3.42 \\
& & EE: GD\_2--4km & 21.25 & 1.77 & 9.43 & 0.24 \\
& & PtX: island & 3491.94 & 290.98 & 2794.36 & 69.86 \\
\addlinespace
& 3& EE/PtX: GD\_0--2km & 1646.11 & 137.17 & 1016.66 & 25.42 \\
& & EE/PtX: GD\_2--4km & 121.23 & 10.10 & 58.78 & 1.47 \\
& & EE: GD\_0--2km & 159.34 & 13.28 & 41.51 & 1.04 \\
& & EE: GD\_2--4km & 17.56 & 1.46 & 5.01 & 0.13 \\
& & PtX: island & 6448.14 & 537.32 & 1094.38 & 27.36 \\
\midrule
CHL2 & 1& EE/PtX: GD\_0--2km & 19.72 & 1.64 & 525.33 & 13.13 \\
& & EE/PtX: GD\_2--4km & 0.67 & 0.06 & 29.59 & 0.74 \\
& & EE: GD\_0--2km & 0.00 & 0.00 & 2.39 & 0.06 \\
& & EE: GD\_2--4km & 0.00 & 0.00 & 0.87 & 0.02 \\
& & PtX: island & 123.64 & 10.30 & 1225.14 & 30.63 \\
% \addlinespace % occurs at page break
& 2& EE/PtX: GD\_0--2km & 406.13 & 33.84 & 345.18 & 8.63 \\
& & EE/PtX: GD\_2--4km & 22.65 & 1.89 & 28.07 & 0.70 \\
& & EE: GD\_0--2km & 0.00 & 0.00 & 30.51 & 0.76 \\
& & EE: GD\_2--4km & 0.00 & 0.00 & 1.49 & 0.04 \\
& & PtX: island & 269.63 & 22.47 & 3067.61 & 76.69 \\
\addlinespace
& 3& EE/PtX: GD\_0--2km & 0.00 & 0.00 & 990.36 & 24.76 \\
& & EE/PtX: GD\_2--4km & 0.00 & 0.00 & 76.24 & 1.91 \\
& & EE: GD\_0--2km & 0.00 & 0.00 & 0.14 & 0.00 \\
& & EE: GD\_2--4km & 0.00 & 0.00 & 0.00 & 0.00 \\
& & PtX: island & 390.59 & 32.55 & 9541.80 & 238.55 \\
\end{xltabular}
\endgroup
\end{document}