我尝试创建一个长表,但它不起作用。我有两个问题:
- 表格在以下页面中创建(我尝试使用 longtable 包来解决这个问题但似乎不起作用)。
- 长表的标题出现在一个奇怪的位置。
附件是我的代码和结果。如果有人能帮助我,我将不胜感激!
\begin{longtable}[h]
\centering
\begin{adjustbox}{width=1\textwidth}
\begin{tabular}{cccccccc}
\hline
\multicolumn{1}{p{3.5em}}{Scenario} & \multicolumn{1}{l}{Deterministic T. Costs (\euro M)} & \multicolumn{1}{l}{Stochastic T. Costs (\euro M)} & \multicolumn{1}{l}{\textbf{Difference (\euro M)}} & \multicolumn{1}{p{3.5em}}{Scenario} & \multicolumn{1}{l}{Deterministic T. Costs (\euro M)} & \multicolumn{1}{l}{Stochastic T. Costs (\euro M)} & \multicolumn{1}{l}{\textbf{Difference (\euro M)}} \\
\hline
\textit{1} & 436,05 & 433,99 & \textbf{-2,06} & \textit{51} & 435,59 & 433,18 & \textbf{-2,41} \\
\textit{2} & 437,30 & 437,71 & \textbf{0,40} & \textit{52} & 431,33 & 430,24 & \textbf{-1,10} \\
\textit{3} & 429,85 & 430,49 & \textbf{0,65} & \textit{53} & 440,37 & 437,46 & \textbf{-2,91} \\
\textit{4} & 426,31 & 426,69 & \textbf{0,38} & \textit{54} & 430,01 & 426,55 & \textbf{-3,46} \\
\textit{5} & 432,58 & 432,10 & \textbf{-0,47} & \textit{55} & 431,33 & 429,88 & \textbf{-1,45} \\
\textit{6} & 439,02 & 436,87 & \textbf{-2,15} & \textit{56} & 429,63 & 427,40 & \textbf{-2,23} \\
\textit{7} & 418,62 & 420,74 & \textbf{2,12} & \textit{57} & 432,96 & 430,70 & \textbf{-2,26} \\
\textit{8} & 443,74 & 441,88 & \textbf{-1,85} & \textit{58} & 431,46 & 431,27 & \textbf{-0,19} \\
\textit{9} & 430,93 & 429,14 & \textbf{-1,79} & \textit{59} & 421,42 & 422,11 & \textbf{0,69} \\
\textit{10} & 425,81 & 424,64 & \textbf{-1,16} & \textit{60} & 417,78 & 419,35 & \textbf{1,57} \\
\textit{11} & 420,18 & 422,59 & \textbf{2,41} & \textit{61} & 437,42 & 434,38 & \textbf{-3,04} \\
\textit{12} & 426,06 & 424,63 & \textbf{-1,43} & \textit{62} & 420,53 & 419,86 & \textbf{-0,67} \\
\textit{13} & 427,58 & 424,70 & \textbf{-2,88} & \textit{63} & 435,26 & 431,60 & \textbf{-3,67} \\
\textit{14} & 437,01 & 434,66 & \textbf{-2,35} & \textit{64} & 437,91 & 435,22 & \textbf{-2,69} \\
\textit{15} & 448,93 & 444,94 & \textbf{-3,98} & \textit{65} & 435,76 & 436,06 & \textbf{0,30} \\
\textit{16} & 427,27 & 428,27 & \textbf{1,00} & \textit{66} & 427,52 & 427,39 & \textbf{-0,13} \\
\textit{17} & 425,86 & 426,53 & \textbf{0,67} & \textit{67} & 437,93 & 436,82 & \textbf{-1,11} \\
\textit{18} & 433,07 & 431,37 & \textbf{-1,70} & \textit{68} & 420,70 & 422,55 & \textbf{1,86} \\
\textit{19} & 429,31 & 428,34 & \textbf{-0,97} & \textit{69} & 433,03 & 429,61 & \textbf{-3,42} \\
\textit{20} & 436,43 & 434,95 & \textbf{-1,48} & \textit{70} & 428,46 & 426,78 & \textbf{-1,68} \\
\textit{21} & 443,86 & 439,46 & \textbf{-4,40} & \textit{71} & 436,85 & 435,91 & \textbf{-0,94} \\
\textit{22} & 427,17 & 427,07 & \textbf{-0,10} & \textit{72} & 425,31 & 424,70 & \textbf{-0,61} \\
\textit{23} & 437,70 & 435,29 & \textbf{-2,41} & \textit{73} & 426,79 & 425,98 & \textbf{-0,81} \\
\textit{24} & 436,80 & 433,14 & \textbf{-3,66} & \textit{74} & 422,78 & 422,17 & \textbf{-0,62} \\
\textit{25} & 428,35 & 427,11 & \textbf{-1,24} & \textit{75} & 437,71 & 438,09 & \textbf{0,38} \\
\textit{26} & 434,41 & 431,14 & \textbf{-3,28} & \textit{76} & 423,19 & 421,06 & \textbf{-2,13} \\
\textit{27} & 433,90 & 431,63 & \textbf{-2,27} & \textit{77} & 420,99 & 422,58 & \textbf{1,59} \\
\textit{28} & 437,66 & 435,95 & \textbf{-1,70} & \textit{78} & 428,32 & 428,03 & \textbf{-0,29} \\
\textit{29} & 443,21 & 440,68 & \textbf{-2,53} & \textit{79} & 439,62 & 436,70 & \textbf{-2,92} \\
\textit{30} & 428,11 & 428,32 & \textbf{0,21} & \textit{80} & 425,97 & 425,76 & \textbf{-0,21} \\
\textit{31} & 430,32 & 427,18 & \textbf{-3,14} & \textit{81} & 434,96 & 431,97 & \textbf{-2,99} \\
\textit{32} & 427,81 & 427,33 & \textbf{-0,48} & \textit{82} & 427,47 & 425,60 & \textbf{-1,87} \\
\textit{33} & 422,23 & 423,61 & \textbf{1,37} & \textit{83} & 433,79 & 432,71 & \textbf{-1,08} \\
\textit{34} & 432,01 & 429,60 & \textbf{-2,42} & \textit{84} & 434,06 & 433,11 & \textbf{-0,95} \\
\textit{35} & 423,96 & 425,35 & \textbf{1,39} & \textit{85} & 431,33 & 429,13 & \textbf{-2,20} \\
\textit{36} & 435,51 & 434,16 & \textbf{-1,35} & \textit{86} & 426,43 & 423,94 & \textbf{-2,50} \\
\textit{37} & 428,09 & 426,42 & \textbf{-1,67} & \textit{87} & 437,98 & 436,18 & \textbf{-1,80} \\
\textit{38} & 423,34 & 423,57 & \textbf{0,23} & \textit{88} & 423,79 & 423,54 & \textbf{-0,25} \\
\textit{39} & 444,15 & 440,84 & \textbf{-3,31} & \textit{89} & 435,79 & 434,89 & \textbf{-0,90} \\
\textit{40} & 426,60 & 426,23 & \textbf{-0,37} & \textit{90} & 428,35 & 427,99 & \textbf{-0,36} \\
\textit{41} & 436,68 & 435,84 & \textbf{-0,84} & \textit{91} & 425,43 & 424,45 & \textbf{-0,99} \\
\textit{42} & 430,62 & 431,93 & \textbf{1,31} & \textit{92} & 437,60 & 436,80 & \textbf{-0,80} \\
\textit{43} & 430,20 & 431,12 & \textbf{0,92} & \textit{93} & 434,81 & 433,76 & \textbf{-1,04} \\
\textit{44} & 427,36 & 425,39 & \textbf{-1,97} & \textit{94} & 428,55 & 428,63 & \textbf{0,08} \\
\textit{45} & 423,67 & 423,06 & \textbf{-0,61} & \textit{95} & 426,21 & 426,96 & \textbf{0,75} \\
\textit{46} & 422,44 & 424,13 & \textbf{1,69} & \textit{96} & 434,48 & 431,91 & \textbf{-2,56} \\
\textit{47} & 433,50 & 433,18 & \textbf{-0,32} & \textit{97} & 435,90 & 434,97 & \textbf{-0,93} \\
\textit{48} & 433,44 & 430,13 & \textbf{-3,31} & \textit{98} & 417,66 & 420,48 & \textbf{2,82} \\
\textit{49} & 425,09 & 425,83 & \textbf{0,74} & \textit{99} & 433,27 & 430,45 & \textbf{-2,81} \\
\textit{50} & 433,02 & 430,48 & \textbf{-2,54} & \textit{100} & 431,51 & 431,51 & \textbf{0,01} \\
\hline
\end{tabular}%
\end{adjustbox}
\caption{Total costs attributed to the 100 demand scenarios for both the deterministic and the stochastic model.}
\label{tab:addlabel}%
\end{longtable}%
答案1
正如@DavidCarlisle 在评论中已经指出的那样,首先要摆脱\centering
、adjustbox
和tabular
。
为了使表格适合文本块的宽度,您应该允许所有 8 列自动换行。我还会删除粗体显示第 4 列和第 8 列中的数字,并将它们与各自的小数点对齐。(不要过度使用粗体,除非你故意想给人留下喜欢冲人大喊大叫的印象……)并且,为了给标题材料提供更多的视觉结构,请考虑将单位声明放在单独的行上。
下面的截图只显示了结果表的前几行。
\documentclass[a4paper]{article}
\usepackage{longtable,eurosym}
\usepackage[margin=2.5cm]{geometry} % set page parameters suitably
\usepackage{array,ragged2e}
\newcolumntype{C}{>{\Centering\hspace{0pt}}p{0.1\textwidth}}
\usepackage[output-decimal-marker={,}]{siunitx}
\begin{document}
\setlength\tabcolsep{4pt}
\setlength\LTcapwidth{0.9\textwidth}
\begin{longtable}{@{} >{\itshape}C *{2}{C} S[table-format=-1.2] |
>{\itshape}C *{2}{C} S[table-format=-1.2] @{}}
%% headers and footers:
\hline
Scenario &
Deterministic T. Costs &
Stochastic T. Costs &
\multicolumn{1}{C|}{\textbf{Difference} } &
Scenario &
Deterministic T. Costs &
Stochastic T. Costs &
\multicolumn{1}{C@{}}{\textbf{Difference} } \\
\cline{2-4} \cline{6-8}
& (\euro M) & (\euro M) & {(\euro M)} &
& (\euro M) & (\euro M) & {(\euro M)} \\
\hline
\endhead
\hline
\endfoot
\hline
\caption{Total costs attributed to the 100 demand scenarios for both the deterministic and the stochastic model.}
\label{tab:addlabel}
\endlastfoot
%% body of table
1 & 436,05 & 433,99 & -2,06 & 51 & 435,59 & 433,18 & -2,41 \\
2 & 437,30 & 437,71 & 0,40 & 52 & 431,33 & 430,24 & -1,10 \\
3 & 429,85 & 430,49 & 0,65 & 53 & 440,37 & 437,46 & -2,91 \\
4 & 426,31 & 426,69 & 0,38 & 54 & 430,01 & 426,55 & -3,46 \\
5 & 432,58 & 432,10 & -0,47 & 55 & 431,33 & 429,88 & -1,45 \\
6 & 439,02 & 436,87 & -2,15 & 56 & 429,63 & 427,40 & -2,23 \\
7 & 418,62 & 420,74 & 2,12 & 57 & 432,96 & 430,70 & -2,26 \\
8 & 443,74 & 441,88 & -1,85 & 58 & 431,46 & 431,27 & -0,19 \\
9 & 430,93 & 429,14 & -1,79 & 59 & 421,42 & 422,11 & 0,69 \\
10 & 425,81 & 424,64 & -1,16 & 60 & 417,78 & 419,35 & 1,57 \\
11 & 420,18 & 422,59 & 2,41 & 61 & 437,42 & 434,38 & -3,04 \\
12 & 426,06 & 424,63 & -1,43 & 62 & 420,53 & 419,86 & -0,67 \\
13 & 427,58 & 424,70 & -2,88 & 63 & 435,26 & 431,60 & -3,67 \\
14 & 437,01 & 434,66 & -2,35 & 64 & 437,91 & 435,22 & -2,69 \\
15 & 448,93 & 444,94 & -3,98 & 65 & 435,76 & 436,06 & 0,30 \\
16 & 427,27 & 428,27 & 1,00 & 66 & 427,52 & 427,39 & -0,13 \\
17 & 425,86 & 426,53 & 0,67 & 67 & 437,93 & 436,82 & -1,11 \\
18 & 433,07 & 431,37 & -1,70 & 68 & 420,70 & 422,55 & 1,86 \\
19 & 429,31 & 428,34 & -0,97 & 69 & 433,03 & 429,61 & -3,42 \\
20 & 436,43 & 434,95 & -1,48 & 70 & 428,46 & 426,78 & -1,68 \\
21 & 443,86 & 439,46 & -4,40 & 71 & 436,85 & 435,91 & -0,94 \\
22 & 427,17 & 427,07 & -0,10 & 72 & 425,31 & 424,70 & -0,61 \\
23 & 437,70 & 435,29 & -2,41 & 73 & 426,79 & 425,98 & -0,81 \\
24 & 436,80 & 433,14 & -3,66 & 74 & 422,78 & 422,17 & -0,62 \\
25 & 428,35 & 427,11 & -1,24 & 75 & 437,71 & 438,09 & 0,38 \\
26 & 434,41 & 431,14 & -3,28 & 76 & 423,19 & 421,06 & -2,13 \\
27 & 433,90 & 431,63 & -2,27 & 77 & 420,99 & 422,58 & 1,59 \\
28 & 437,66 & 435,95 & -1,70 & 78 & 428,32 & 428,03 & -0,29 \\
29 & 443,21 & 440,68 & -2,53 & 79 & 439,62 & 436,70 & -2,92 \\
30 & 428,11 & 428,32 & 0,21 & 80 & 425,97 & 425,76 & -0,21 \\
31 & 430,32 & 427,18 & -3,14 & 81 & 434,96 & 431,97 & -2,99 \\
32 & 427,81 & 427,33 & -0,48 & 82 & 427,47 & 425,60 & -1,87 \\
33 & 422,23 & 423,61 & 1,37 & 83 & 433,79 & 432,71 & -1,08 \\
34 & 432,01 & 429,60 & -2,42 & 84 & 434,06 & 433,11 & -0,95 \\
35 & 423,96 & 425,35 & 1,39 & 85 & 431,33 & 429,13 & -2,20 \\
36 & 435,51 & 434,16 & -1,35 & 86 & 426,43 & 423,94 & -2,50 \\
37 & 428,09 & 426,42 & -1,67 & 87 & 437,98 & 436,18 & -1,80 \\
38 & 423,34 & 423,57 & 0,23 & 88 & 423,79 & 423,54 & -0,25 \\
39 & 444,15 & 440,84 & -3,31 & 89 & 435,79 & 434,89 & -0,90 \\
40 & 426,60 & 426,23 & -0,37 & 90 & 428,35 & 427,99 & -0,36 \\
41 & 436,68 & 435,84 & -0,84 & 91 & 425,43 & 424,45 & -0,99 \\
42 & 430,62 & 431,93 & 1,31 & 92 & 437,60 & 436,80 & -0,80 \\
43 & 430,20 & 431,12 & 0,92 & 93 & 434,81 & 433,76 & -1,04 \\
44 & 427,36 & 425,39 & -1,97 & 94 & 428,55 & 428,63 & 0,08 \\
45 & 423,67 & 423,06 & -0,61 & 95 & 426,21 & 426,96 & 0,75 \\
46 & 422,44 & 424,13 & 1,69 & 96 & 434,48 & 431,91 & -2,56 \\
47 & 433,50 & 433,18 & -0,32 & 97 & 435,90 & 434,97 & -0,93 \\
48 & 433,44 & 430,13 & -3,31 & 98 & 417,66 & 420,48 & 2,82 \\
49 & 425,09 & 425,83 & 0,74 & 99 & 433,27 & 430,45 & -2,81 \\
50 & 433,02 & 430,48 & -2,54 & 100 & 431,51 & 431,51 & 0,01 \\
\end{longtable}
\end{document}