如果我将 table 改为 longtable,需要更改什么?

如果我将 table 改为 longtable,需要更改什么?

我刚刚用 excel2latex 导入了一个表格,但是表格太长而且跨页。我试了几次,但发现表格缩小了,我不知道如何将单元格的所有内容居中。非常感谢!这是我的代码。

\documentclass[12pt,a4paper]{article}
\usepackage[pdftex]{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{booktabs}
\usepackage{geometry}
\usepackage{longtable}
\begin{document}
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\
\begin{longtable}{c *6{p{1.5cm}}}
    \hline
    {\bf Order} & {\bf Analytical} & {\bf Numerical} &{\bf Order} & {\bf Analytical} & {\bf Numerical}\\ \hline
    1     & 0.363636 & 0.363636 & 26    & 1.64E-07 & 1.64E-07 \\
    2     & 0.299465 & 0.299465 & 27    & 9.07E-08 & 9.07E-08 \\
    3     & 0.155492 & 0.155492 & 28    & 5.02E-08 & 5.02E-08 \\
    4     & 0.082929 & 0.082929 & 29    & 2.78E-08 & 2.78E-08 \\
    5     & 0.044763 & 0.044763 & 30    & 1.54E-08 & 1.54E-08 \\
    6     & 0.024324 & 0.024324 & 31    & 8.52E-09 & 8.52E-09 \\
    7     & 0.013274 & 0.013274 & 32    & 4.72E-09 & 4.72E-09 \\
    8     & 0.007264 & 0.007264 & 33    & 2.62E-09 & 2.62E-09 \\
    9     & 0.003984 & 0.003984 & 34    & 1.45E-09 & 1.45E-09 \\
    10    & 0.002188 & 0.002188 & 35    & 8.03E-10 & 8.03E-10 \\
    11    & 0.001204 & 0.001204 & 36    & 4.45E-10 & 4.45E-10 \\
    12    & 0.000663 & 0.000663 & 37    & 2.47E-10 & 2.47E-10 \\
    13    & 0.000365 & 0.000365 & 38    & 1.37E-10 & 1.37E-10 \\
    14    & 0.000201 & 0.000201 & 39    & 7.57E-11 & 7.57E-11 \\
    15    & 0.000111 & 0.000111 & 40    & 4.20E-11 & 4.20E-11 \\
    16    & 6.13E-05 & 6.13E-05 & 41    & 2.33E-11 & 2.33E-11 \\
    17    & 3.39E-05 & 3.39E-05 & 42    & 1.29E-11 & 1.29E-11 \\
    18    & 1.87E-05 & 1.87E-05 & 43    & 7.15E-12 & 7.15E-12 \\
    19    & 1.03E-05 & 1.03E-05 & 44    & 3.96E-12 & 3.96E-12 \\
    20    & 5.71E-06 & 5.71E-06 & 45    & 2.20E-12 & 2.20E-12 \\
    21    & 3.16E-06 & 3.16E-06 & 46    & 1.22E-12 & 1.22E-12 \\
    22    & 1.75E-06 & 1.75E-06 & 47    & 6.75E-13 & 6.75E-13 \\
    23    & 9.67E-07 & 9.67E-07 & 48    & 3.74E-13 & 3.74E-13 \\
    24    & 5.35E-07 & 5.35E-07 & 49    & 2.08E-13 & 2.08E-13 \\
    25    & 2.96E-07 & 2.96E-07 & 50    & 1.15E-13 & 2.58E-13 \\ \hline    
    \end{longtable}
\end{document}

下面的代码是从excel2latex获取的。

\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{tabular}{cccccc}
\toprule
Order & Analytical & Numerical & Order & Analytical & Numerical \\
\midrule
1     & 0.363636 & 0.363636 & 26    & 1.64E-07 & 1.64E-07 \\
2     & 0.299465 & 0.299465 & 27    & 9.07E-08 & 9.07E-08 \\
3     & 0.155492 & 0.155492 & 28    & 5.02E-08 & 5.02E-08 \\
4     & 0.082929 & 0.082929 & 29    & 2.78E-08 & 2.78E-08 \\
5     & 0.044763 & 0.044763 & 30    & 1.54E-08 & 1.54E-08 \\
6     & 0.024324 & 0.024324 & 31    & 8.52E-09 & 8.52E-09 \\
7     & 0.013274 & 0.013274 & 32    & 4.72E-09 & 4.72E-09 \\
8     & 0.007264 & 0.007264 & 33    & 2.62E-09 & 2.62E-09 \\
9     & 0.003984 & 0.003984 & 34    & 1.45E-09 & 1.45E-09 \\
10    & 0.002188 & 0.002188 & 35    & 8.03E-10 & 8.03E-10 \\
11    & 0.001204 & 0.001204 & 36    & 4.45E-10 & 4.45E-10 \\
12    & 0.000663 & 0.000663 & 37    & 2.47E-10 & 2.47E-10 \\
13    & 0.000365 & 0.000365 & 38    & 1.37E-10 & 1.37E-10 \\
14    & 0.000201 & 0.000201 & 39    & 7.57E-11 & 7.57E-11 \\
15    & 0.000111 & 0.000111 & 40    & 4.20E-11 & 4.20E-11 \\
16    & 6.13E-05 & 6.13E-05 & 41    & 2.33E-11 & 2.33E-11 \\
17    & 3.39E-05 & 3.39E-05 & 42    & 1.29E-11 & 1.29E-11 \\
18    & 1.87E-05 & 1.87E-05 & 43    & 7.15E-12 & 7.15E-12 \\
19    & 1.03E-05 & 1.03E-05 & 44    & 3.96E-12 & 3.96E-12 \\
20    & 5.71E-06 & 5.71E-06 & 45    & 2.20E-12 & 2.20E-12 \\
21    & 3.16E-06 & 3.16E-06 & 46    & 1.22E-12 & 1.22E-12 \\
22    & 1.75E-06 & 1.75E-06 & 47    & 6.75E-13 & 6.75E-13 \\
23    & 9.67E-07 & 9.67E-07 & 48    & 3.74E-13 & 3.74E-13 \\
24    & 5.35E-07 & 5.35E-07 & 49    & 2.08E-13 & 2.08E-13 \\
25    & 2.96E-07 & 2.96E-07 & 50    & 1.15E-13 & 2.58E-13 \\
\bottomrule
\end{tabular}%
\label{tab:addlabel}%
\end{table}%

在此处输入图片描述

答案1

不要减小字体大小,而是选择适当的列宽,使得每列可以容纳最宽的内容(如果不能,则允许换行),并且所有列的总宽度不超过\textwidth

\begin{longtable}{C{\dimexpr0.12\textwidth-2\tabcolsep\relax}
     *2{C{\dimexpr0.19\textwidth-2\tabcolsep\relax}}
     C{\dimexpr0.12\textwidth-2\tabcolsep\relax}
     *2{C{\dimexpr0.19\textwidth-2\tabcolsep\relax}}}
    \toprule

其中,C是在包的帮助下定义的具有居中内容的新列类型array

\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

代码:

\documentclass[12pt,a4paper,draft]{article}
\usepackage{kantlipsum}
\usepackage{booktabs,array}
\usepackage{longtable}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\kant[1]
\begin{longtable}{C{\dimexpr0.12\textwidth-2\tabcolsep\relax}
     *2{C{\dimexpr0.19\textwidth-2\tabcolsep\relax}}
     C{\dimexpr0.12\textwidth-2\tabcolsep\relax}
     *2{C{\dimexpr0.19\textwidth-2\tabcolsep\relax}}}
    \toprule
    \textbf{Order} & \textbf{Analytical} & \textbf{Numerical} &\textbf{Order} & \textbf{Analytical} & \textbf{Numerical}\\ \midrule
    1     & 0.363636 & 0.363636 & 26    & 1.64E-07 & 1.64E-07 \\
    2     & 0.299465 & 0.299465 & 27    & 9.07E-08 & 9.07E-08 \\
    3     & 0.155492 & 0.155492 & 28    & 5.02E-08 & 5.02E-08 \\
    4     & 0.082929 & 0.082929 & 29    & 2.78E-08 & 2.78E-08 \\
    5     & 0.044763 & 0.044763 & 30    & 1.54E-08 & 1.54E-08 \\
    6     & 0.024324 & 0.024324 & 31    & 8.52E-09 & 8.52E-09 \\
    7     & 0.013274 & 0.013274 & 32    & 4.72E-09 & 4.72E-09 \\
    8     & 0.007264 & 0.007264 & 33    & 2.62E-09 & 2.62E-09 \\
    9     & 0.003984 & 0.003984 & 34    & 1.45E-09 & 1.45E-09 \\
    10    & 0.002188 & 0.002188 & 35    & 8.03E-10 & 8.03E-10 \\
    11    & 0.001204 & 0.001204 & 36    & 4.45E-10 & 4.45E-10 \\
    12    & 0.000663 & 0.000663 & 37    & 2.47E-10 & 2.47E-10 \\
    13    & 0.000365 & 0.000365 & 38    & 1.37E-10 & 1.37E-10 \\
    14    & 0.000201 & 0.000201 & 39    & 7.57E-11 & 7.57E-11 \\
    15    & 0.000111 & 0.000111 & 40    & 4.20E-11 & 4.20E-11 \\
    16    & 6.13E-05 & 6.13E-05 & 41    & 2.33E-11 & 2.33E-11 \\
    17    & 3.39E-05 & 3.39E-05 & 42    & 1.29E-11 & 1.29E-11 \\
    18    & 1.87E-05 & 1.87E-05 & 43    & 7.15E-12 & 7.15E-12 \\
    19    & 1.03E-05 & 1.03E-05 & 44    & 3.96E-12 & 3.96E-12 \\
    20    & 5.71E-06 & 5.71E-06 & 45    & 2.20E-12 & 2.20E-12 \\
    21    & 3.16E-06 & 3.16E-06 & 46    & 1.22E-12 & 1.22E-12 \\
    22    & 1.75E-06 & 1.75E-06 & 47    & 6.75E-13 & 6.75E-13 \\
    23    & 9.67E-07 & 9.67E-07 & 48    & 3.74E-13 & 3.74E-13 \\
    24    & 5.35E-07 & 5.35E-07 & 49    & 2.08E-13 & 2.08E-13 \\
    25    & 2.96E-07 & 2.96E-07 & 50    & 1.15E-13 & 2.58E-13 \\ \bottomrule
    \end{longtable}
\end{document}

在此处输入图片描述

如果您希望页眉和页脚等在每一页上重复,请使用以下命令:

\documentclass[12pt,a4paper,draft]{article}
\usepackage{kantlipsum}
\usepackage{booktabs,array}
\usepackage{longtable}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\kant[1]
\begin{longtable}{C{\dimexpr0.12\textwidth-2\tabcolsep\relax}
     *2{C{\dimexpr0.19\textwidth-2\tabcolsep\relax}}
     C{\dimexpr0.12\textwidth-2\tabcolsep\relax}
     *2{C{\dimexpr0.19\textwidth-2\tabcolsep\relax}}}
    \toprule
    \textbf{Order} & \textbf{Analytical} & \textbf{Numerical} &\textbf{Order} &
      \textbf{Analytical} & \textbf{Numerical}\\ \midrule
    \endfirsthead%
    \multicolumn{6}{c}%
    {{\bfseries  Continued from previous page}} \\
    \toprule
    \textbf{Order} & \textbf{Analytical} & \textbf{Numerical} &\textbf{Order} &
    \textbf{Analytical} & \textbf{Numerical}\\ \midrule
    \endhead
    \midrule \multicolumn{6}{r}{{Continued on next page}} \\ \midrule
    \endfoot
    \midrule
    \multicolumn{6}{r}{{Concluded}} \\ \bottomrule
    \endlastfoot
%    \textbf{Order} & \textbf{Analytical} & \textbf{Numerical} &\textbf{Order} & \textbf{Analytical} & \textbf{Numerical}\\ \midrule
    1     & 0.363636 & 0.363636 & 26    & 1.64E-07 & 1.64E-07 \\
    2     & 0.299465 & 0.299465 & 27    & 9.07E-08 & 9.07E-08 \\
    3     & 0.155492 & 0.155492 & 28    & 5.02E-08 & 5.02E-08 \\
    4     & 0.082929 & 0.082929 & 29    & 2.78E-08 & 2.78E-08 \\
    5     & 0.044763 & 0.044763 & 30    & 1.54E-08 & 1.54E-08 \\
    6     & 0.024324 & 0.024324 & 31    & 8.52E-09 & 8.52E-09 \\
    7     & 0.013274 & 0.013274 & 32    & 4.72E-09 & 4.72E-09 \\
    8     & 0.007264 & 0.007264 & 33    & 2.62E-09 & 2.62E-09 \\
    9     & 0.003984 & 0.003984 & 34    & 1.45E-09 & 1.45E-09 \\
    10    & 0.002188 & 0.002188 & 35    & 8.03E-10 & 8.03E-10 \\
    11    & 0.001204 & 0.001204 & 36    & 4.45E-10 & 4.45E-10 \\
    12    & 0.000663 & 0.000663 & 37    & 2.47E-10 & 2.47E-10 \\
    13    & 0.000365 & 0.000365 & 38    & 1.37E-10 & 1.37E-10 \\
    14    & 0.000201 & 0.000201 & 39    & 7.57E-11 & 7.57E-11 \\
    15    & 0.000111 & 0.000111 & 40    & 4.20E-11 & 4.20E-11 \\
    16    & 6.13E-05 & 6.13E-05 & 41    & 2.33E-11 & 2.33E-11 \\
    17    & 3.39E-05 & 3.39E-05 & 42    & 1.29E-11 & 1.29E-11 \\
    18    & 1.87E-05 & 1.87E-05 & 43    & 7.15E-12 & 7.15E-12 \\
    19    & 1.03E-05 & 1.03E-05 & 44    & 3.96E-12 & 3.96E-12 \\
    20    & 5.71E-06 & 5.71E-06 & 45    & 2.20E-12 & 2.20E-12 \\
    21    & 3.16E-06 & 3.16E-06 & 46    & 1.22E-12 & 1.22E-12 \\
    22    & 1.75E-06 & 1.75E-06 & 47    & 6.75E-13 & 6.75E-13 \\
    23    & 9.67E-07 & 9.67E-07 & 48    & 3.74E-13 & 3.74E-13 \\
    24    & 5.35E-07 & 5.35E-07 & 49    & 2.08E-13 & 2.08E-13 \\
    25    & 2.96E-07 & 2.96E-07 & 50    & 1.15E-13 & 2.58E-13 \\
    16    & 6.13E-05 & 6.13E-05 & 41    & 2.33E-11 & 2.33E-11 \\
    17    & 3.39E-05 & 3.39E-05 & 42    & 1.29E-11 & 1.29E-11 \\
    18    & 1.87E-05 & 1.87E-05 & 43    & 7.15E-12 & 7.15E-12 \\
    19    & 1.03E-05 & 1.03E-05 & 44    & 3.96E-12 & 3.96E-12 \\
    20    & 5.71E-06 & 5.71E-06 & 45    & 2.20E-12 & 2.20E-12 \\
    21    & 3.16E-06 & 3.16E-06 & 46    & 1.22E-12 & 1.22E-12 \\
    22    & 1.75E-06 & 1.75E-06 & 47    & 6.75E-13 & 6.75E-13 \\
    23    & 9.67E-07 & 9.67E-07 & 48    & 3.74E-13 & 3.74E-13 \\
    24    & 5.35E-07 & 5.35E-07 & 49    & 2.08E-13 & 2.08E-13 \\
    25    & 2.96E-07 & 2.96E-07 & 50    & 1.15E-13 & 2.58E-13 \\ 
    \end{longtable}
\end{document}

在此处输入图片描述

答案2

您可以使用包S中的列类型siunitx来自动格式化数字。以下是代码:

   \documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{array, longtable}
\usepackage{booktabs}
\usepackage[table-format = 1.2,table-number-alignment = center, table-figures-exponent = 1, table-sign-exponent = true]{siunitx}

\begin{document}

\centering
\begin{longtable}{cSScS[table-figures-exponent=2]S[table-figures-exponent=2]}
\caption{Add caption}\label{tab:addlabel}\\
\toprule
Order & {\scshape Analytical} & {\scshape Numerical} & Order & {\scshape Analytical} & {\scshape Numerical} \\
\cmidrule(lr){1-3}\cmidrule(lr){4-6}
\endfirsthead
\multicolumn{6}{r}{\small\itshape\tablename~\thetable~(continued)\makebox[1em]{}}\\
\addlinespace
\toprule
Order & {\scshape Analytical} & {\scshape Numerical} & Order & {\scshape Analytical} & {\scshape Numerical} \\
\cmidrule(r){1-3}\cmidrule(l){4-6}
\endhead
\cmidrule(r){1-3}\cmidrule(l){4-6}
\endfoot
\bottomrule
\endlastfoot
1 & 0.363636 & 0.363636 & 26 & 1.64E-07 & 1.64E-07 \\
2 & 0.299465 & 0.299465 & 27 & 9.07E-08 & 9.07E-08 \\
3 & 0.155492 & 0.155492 & 28 & 5.02E-08 & 5.02E-08 \\
4 & 0.082929 & 0.082929 & 29 & 2.78E-08 & 2.78E-08 \\
5 & 0.044763 & 0.044763 & 30 & 1.54E-08 & 1.54E-08 \\
6 & 0.024324 & 0.024324 & 31 & 8.52E-09 & 8.52E-09 \\
7 & 0.013274 & 0.013274 & 32 & 4.72E-09 & 4.72E-09 \\
8 & 0.007264 & 0.007264 & 33 & 2.62E-09 & 2.62E-09 \\
9 & 0.003984 & 0.003984 & 34 & 1.45E-09 & 1.45E-09 \\
10 & 0.002188 & 0.002188 & 35 & 8.03E-10 & 8.03E-10 \\
11 & 0.001204 & 0.001204 & 36 & 4.45E-10 & 4.45E-10 \\
12 & 0.000663 & 0.000663 & 37 & 2.47E-10 & 2.47E-10 \\
13 & 0.000365 & 0.000365 & 38 & 1.37E-10 & 1.37E-10 \\
14 & 0.000201 & 0.000201 & 39 & 7.57E-11 & 7.57E-11 \\
15 & 0.000111 & 0.000111 & 40 & 4.20E-11 & 4.20E-11 \\
16 & 6.13E-05 & 6.13E-05 & 41 & 2.33E-11 & 2.33E-11 \\
17 & 3.39E-05 & 3.39E-05 & 42 & 1.29E-11 & 1.29E-11 \\
18 & 1.87E-05 & 1.87E-05 & 43 & 7.15E-12 & 7.15E-12 \\
19 & 1.03E-05 & 1.03E-05 & 44 & 3.96E-12 & 3.96E-12 \\
20 & 5.71E-06 & 5.71E-06 & 45 & 2.20E-12 & 2.20E-12 \\
21 & 3.16E-06 & 3.16E-06 & 46 & 1.22E-12 & 1.22E-12 \\
22 & 1.75E-06 & 1.75E-06 & 47 & 6.75E-13 & 6.75E-13 \\
23 & 9.67E-07 & 9.67E-07 & 48 & 3.74E-13 & 3.74E-13 \\
24 & 5.35E-07 & 5.35E-07 & 49 & 2.08E-13 & 2.08E-13 \\
25 & 2.96E-07 & 2.96E-07 & 50 & 1.15E-13 & 2.58E-13 \\
1 & 0.363636 & 0.363636 & 26 & 1.64E-07 & 1.64E-07 \\
2 & 0.299465 & 0.299465 & 27 & 9.07E-08 & 9.07E-08 \\
3 & 0.155492 & 0.155492 & 28 & 5.02E-08 & 5.02E-08 \\
4 & 0.082929 & 0.082929 & 29 & 2.78E-08 & 2.78E-08 \\
5 & 0.044763 & 0.044763 & 30 & 1.54E-08 & 1.54E-08 \\
6 & 0.024324 & 0.024324 & 31 & 8.52E-09 & 8.52E-09 \\
7 & 0.013274 & 0.013274 & 32 & 4.72E-09 & 4.72E-09 \\
8 & 0.007264 & 0.007264 & 33 & 2.62E-09 & 2.62E-09 \\
9 & 0.003984 & 0.003984 & 34 & 1.45E-09 & 1.45E-09 \\
10 & 0.002188 & 0.002188 & 35 & 8.03E-10 & 8.03E-10 \\
11 & 0.001204 & 0.001204 & 36 & 4.45E-10 & 4.45E-10 \\
12 & 0.000663 & 0.000663 & 37 & 2.47E-10 & 2.47E-10 \\
13 & 0.000365 & 0.000365 & 38 & 1.37E-10 & 1.37E-10 \\
14 & 0.000201 & 0.000201 & 39 & 7.57E-11 & 7.57E-11 \\
15 & 0.000111 & 0.000111 & 40 & 4.20E-11 & 4.20E-11 \\
16 & 6.13E-05 & 6.13E-05 & 41 & 2.33E-11 & 2.33E-11 \\
17 & 3.39E-05 & 3.39E-05 & 42 & 1.29E-11 & 1.29E-11 \\
18 & 1.87E-05 & 1.87E-05 & 43 & 7.15E-12 & 7.15E-12 \\
19 & 1.03E-05 & 1.03E-05 & 44 & 3.96E-12 & 3.96E-12 \\
20 & 5.71E-06 & 5.71E-06 & 45 & 2.20E-12 & 2.20E-12 \\
21 & 3.16E-06 & 3.16E-06 & 46 & 1.22E-12 & 1.22E-12 \\
22 & 1.75E-06 & 1.75E-06 & 47 & 6.75E-13 & 6.75E-13 \\
23 & 9.67E-07 & 9.67E-07 & 48 & 3.74E-13 & 3.74E-13 \\
24 & 5.35E-07 & 5.35E-07 & 49 & 2.08E-13 & 2.08E-13 \\
25 & 2.96E-07 & 2.96E-07 & 50 & 1.15E-13 & 2.58E-13 \\
\end{longtable}%

\end{document} 

在此处输入图片描述

在此处输入图片描述

相关内容