将表格标题拆分为多行

将表格标题拆分为多行

假设我有以下内容;

\begin{table}
\centering
\begin{tabular}{|c|c|}
\hline
\multicolumn{2}{|c|}{Table1}  \\ \hline
A very long equation with k as input & Answer \\ \hline
1 & -19.0123  \\ \hline
2 & -16.4377 \\ \hline
3 & -13.3349 \\ \hline
4 & -11.7427  \\ \hline
5 & -10.1329 \\ \hline
6  & -9.0075 \\ \hline
7 & -6.0001 \\ \hline
\end{tabular}
\quad
\begin{tabular}{|c|c|}
\hline
\multicolumn{2}{|c|}{table2}  \\ \hline
A very long equation with k as input & Answer \\ \hline
1 & -16.0123  \\ \hline
2 & -12.4377 \\ \hline
3 & -9.5532 \\ \hline
4 & -5.7427  \\ \hline
5 & -4.1329 \\ \hline
6  & -3.0075 \\ \hline
7 & -3.0001 \\ \hline
\end{tabular}
\quad
\begin{tabular}{|c|c|}
\hline
\multicolumn{2}{|c|}{table3}  \\ \hline
A very long equation with k as input & Answer \\ \hline
1 & -5.0123  \\ \hline
2 & -2.4377 \\ \hline
3 & -3.3349 \\ \hline
4 & -1.7427  \\ \hline
5 & -1.1329 \\ \hline
6  & -1.0075 \\ \hline
7 & -1.0001 \\ \hline
\end{tabular}
\end{table}

请注意,第一列只有小条目(最多有 8 个数字),我想知道可以在其中插入什么,以便第 1 列的标题(以 k 作为输入的长方程)会分成多行 - 同时保持居中。

谢谢——如果这个问题已经得到回答,我很抱歉,Rob。

编辑:最终的想法是确保所有表都在同一行上彼此相邻。

答案1

您可以加载array包并声明新的列类型

\newcolumntype{C}{@{}>{\Centering\arraybackslash}m{0.14\linewidth}}

具有适合 0.14 英寸的值0.14\linewidth。我使用了列内包中\Centering 的命令。此外,您还需要ragged2e[t]tabular

 \begin{tabular}[t]{|C|c|}

平均能量损失

\documentclass{article}
\usepackage{amsmath,array,ragged2e}
\newcolumntype{C}{>{\Centering\arraybackslash}m{0.14\linewidth}}
\begin{document}
  \begin{table}
\centering
\begin{tabular}[t]{|C|c|}
\hline
\multicolumn{2}{|c|}{Table1}  \\ \hline
A very long equation with k as input & Answer \\ \hline
1 & -19.0123  \\ \hline
2 & -16.4377 \\ \hline
3 & -13.3349 \\ \hline
4 & -11.7427  \\ \hline
5 & -10.1329 \\ \hline
6  & -9.0075 \\ \hline
7 & -6.0001 \\ \hline
\end{tabular}
%\quad
\begin{tabular}[t]{|C|c|}
\hline
\multicolumn{2}{|c|}{table2}  \\ \hline
A very long equation with k as input & Answer \\ \hline
1 & -16.0123  \\ \hline
2 & -12.4377 \\ \hline
3 & -9.5532 \\ \hline
4 & -5.7427  \\ \hline
5 & -4.1329 \\ \hline
6  & -3.0075 \\ \hline
7 & -3.0001 \\ \hline
\end{tabular}
%\quad
\begin{tabular}[t]{|C|c|}
\hline
\multicolumn{2}{|c|}{table3}  \\ \hline
$a+b+f+c+d+g+t+r+e+y+u+h+g+b+u+y+u+r+t+y=Z$ & Answer \\ \hline
1 & -5.0123  \\ \hline
2 & -2.4377 \\ \hline
3 & -3.3349 \\ \hline
4 & -1.7427  \\ \hline
5 & -1.1329 \\ \hline
6  & -1.0075 \\ \hline
7 & -1.0001 \\ \hline
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

按照网站的传统,垂直线是邪恶的,使用表格booktabs是整洁的,这里有一个booktabs版本:

\documentclass{article}
\usepackage{amsmath,array,ragged2e,booktabs}
\newcolumntype{C}{>{\Centering\arraybackslash}m{0.17\linewidth}}
\begin{document}
\begin{table}
\centering
\begin{tabular}[t]{CcCcCc}
\toprule
\multicolumn{2}{c}{Table1} & \multicolumn{2}{c}{table2} & \multicolumn{2}{c}{table3}  \\ \midrule
A very long equation with k as input & Answer & A very long equation with k as input & Answer & A very long equation with k as input & Answer  \\ \cmidrule(lr){1-2}\cmidrule(lr){3-4}\cmidrule(lr){5-6}
1 & -19.0123 &  1 & -16.0123 & 1 & -5.0123  \\
2 & -16.4377 &  2 & -12.4377 & 2 & -2.4377 \\
3 & -13.3349 &  3 & -9.5532  & 3 & -3.3349 \\
4 & -11.7427 &  4 & -5.7427  & 4 & -1.7427  \\
5 & -10.1329 &  5 & -4.1329  & 5 & -1.1329 \\
6 & -9.0075  &  6 & -3.0075  & 6 & -1.0075 \\
7 & -6.0001  &  7 & -3.0001  & 7 & -1.0001 \\\bottomrule
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

在上表中,数字应该处于数学模式(参见减号)。为此,您可以定义另一个新列,例如

\newcolumntype{P}{>{$}c<{$}}

并将其用作

\begin{tabular}[t]{CPCPCP}

或者....使用siunitx及其S列类型:

\documentclass{article}
\usepackage{amsmath,array,ragged2e,booktabs,siunitx}
\newcolumntype{C}{>{\Centering\arraybackslash}m{0.17\linewidth}}
\newcolumntype{P}{S[table-format=3.4]}
\newcommand{\mc}[1]{\multicolumn{1}{c}{#1}}
\begin{document}
\begin{table}
\centering
\begin{tabular}[t]{CPCPCP}
\toprule
\multicolumn{2}{c}{Table1} & \multicolumn{2}{c}{table2} & \multicolumn{2}{c}{table3}  \\ \midrule
A very long equation with k as input & \mc{Answer} & A very long equation with k as input & \mc{Answer} & A very long equation with k as input & \mc{Answer}  \\ \cmidrule(lr){1-2}\cmidrule(lr){3-4}\cmidrule(lr){5-6}
1 & -19.0123 &  1 & -16.0123 & 1 & -5.0123  \\
2 & -16.4377 &  2 & -12.4377 & 2 & -2.4377 \\
3 & -13.3349 &  3 & -9.5532  & 3 & -3.3349 \\
4 & -11.7427 &  4 & -5.7427  & 4 & -1.7427  \\
5 & -10.1329 &  5 & -4.1329  & 5 & -1.1329 \\
6 & -9.0075  &  6 & -3.0075  & 6 & -1.0075 \\
7 & -6.0001  &  7 & -3.0001  & 7 & -1.0001 \\\bottomrule
\end{tabular}
\end{table}
\end{document}

在此处输入图片描述

答案2

您应该考虑使用 booktabs 并省略垂直线,如果您想分隔表格,则可以使用subtable以下环境subcaption

\documentclass{scrartcl}

\usepackage{booktabs}
\usepackage[width=0.9\linewidth,labelfont=bf]{caption}
\usepackage{subcaption}

\begin{document}

\begin{table}
  \centering
  \caption{Three equations evaluated at $k$}
  \begin{subtable}{0.33\textwidth}
    \centering
    \caption{Complicated function of $k$}
    \begin{tabular}{c c}
      \toprule
      $k$ & Result \\
      \midrule
      1 & -19.0123  \\
      2 & -16.4377 \\
      3 & -13.3349 \\
      4 & -11.7427  \\
      5 & -10.1329 \\
      6  & -9.0075 \\ 
      7 & -6.0001 \\ 
      \bottomrule
    \end{tabular}
  \end{subtable}%  
  \begin{subtable}{0.33\textwidth}
    \centering
    \caption{Complicated function of $k$}
    \begin{tabular}{c c}
      \toprule
      $k$ & Result \\
      \midrule
      1 & -19.0123  \\
      2 & -16.4377 \\
      3 & -13.3349 \\
      4 & -11.7427  \\
      5 & -10.1329 \\
      6  & -9.0075 \\ 
      7 & -6.0001 \\ 
      \bottomrule
    \end{tabular}
  \end{subtable}%  
  \begin{subtable}{0.33\textwidth}
    \centering
    \caption{Complicated function of $k$}
    \begin{tabular}{c c}
      \toprule
      $k$ & Result \\
      \midrule
      1 & -19.0123  \\
      2 & -16.4377 \\
      3 & -13.3349 \\
      4 & -11.7427  \\
      5 & -10.1329 \\
      6  & -9.0075 \\ 
      7 & -6.0001 \\ 
      \bottomrule
    \end{tabular}
  \end{subtable}%  
\end{table}

\end{document}

输出

我认为您还应该考虑一下这些数值,4 位数字是否有意义且有必要?您可以使用Ssiunitx 的列类型来使数字在小数点处正确对齐(请注意标题周围的括号):

\documentclass{scrartcl}

\usepackage{booktabs}
\usepackage[width=0.9\linewidth,labelfont=bf]{caption}
\usepackage{subcaption}

\usepackage{siunitx}

\begin{document}
\pagestyle{empty}

\begin{table}
  \centering
  \caption{Three equations evaluated at $k$}
  \begin{subtable}{0.33\textwidth}
    \centering
    \caption{Complicated function of $k$}
    \begin{tabular}{S[table-format=1.0] S[table-format=-2.4]}
      \toprule
      {$k$} & {Result} \\
      \midrule
      1 & -19.0123  \\
      2 & -16.4377 \\
      3 & -13.3349 \\
      4 & -11.7427  \\
      5 & -10.1329 \\
      6  & -9.0075 \\ 
      7 & -6.0001 \\ 
      \bottomrule
    \end{tabular}
  \end{subtable}%  
  \begin{subtable}{0.33\textwidth}
    \centering
    \caption{Complicated function of $k$}
    \begin{tabular}{S[table-format=1.0] S[table-format=-2.4]}
      \toprule
      {$k$} & {Result} \\
      \midrule
      1 & -19.0123  \\
      2 & -16.4377 \\
      3 & -13.3349 \\
      4 & -11.7427  \\
      5 & -10.1329 \\
      6  & -9.0075 \\ 
      7 & -6.0001 \\ 
      \bottomrule
    \end{tabular}
  \end{subtable}%  
  \begin{subtable}{0.33\textwidth}
    \centering
    \caption{Complicated function of $k$}
    \begin{tabular}{S[table-format=1.0] S[table-format=-2.4]}
      \toprule
      {$k$} & {Result} \\
      \midrule
      1 & -19.0123  \\
      2 & -16.4377 \\
      3 & -13.3349 \\
      4 & -11.7427  \\
      5 & -10.1329 \\
      6  & -9.0075 \\ 
      7 & -6.0001 \\ 
      \bottomrule
    \end{tabular}
  \end{subtable}%  
\end{table}
\end{document}

出局二

您还应该注意,siunitx 使用正确的减号而不是连字符,并且使用等宽数字。

相关内容