如何将文本置于多列环境的中央

如何将文本置于多列环境的中央

我该如何修复我的桌子?我想将\(\%\)和两个居中\(\msec\)

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{adjustbox}
\usepackage{booktabs}

\begin{document}
\begin{table}[!h]
\centering
\begin{adjustbox}{max width=\textwidth}
\begin{tabular}{c|cc|cc|cc}
    \toprule
    \(J\) & \multicolumn{2}{c|}{Sovraelongazione} & \multicolumn{2}{c|}{\shortstack{Tempo di \\ salita}} &  \multicolumn{2}{c}{\shortstack{Tempo di \\ assestamento}} \\
    \midrule
    \(Kg\cdot m^{2}\) & &\(\%\) & &\(msec\) & & \(msec\) \\
    \midrule
    & \(PI-diff_{\omega_{bv},J_{var}}\) & \(PI-diff_{\omega_{bv},J_{mid}}\) & \(PI-diff_{\omega_{bv},J_{var}}\) & \(PI-diff_{\omega_{bv},J_{mid}}\) & \(PI-diff_{\omega_{bv},J_{var}}\) & \(PI-diff_{\omega_{bv},J_{mid}}\)\\
    \midrule
    \(0.225\) &\(0\) &\(0\) & \(27\)&\(28\) & \(69\)&\(71\)\\
    \(1.390\) &\(0.3\) &\(0.3\) &\(29\) &\(29\) &\(72\) &\(72\)\\
    \(8.406\) & \(0.4\)&\(0.4\) & \(33\)&\(29\) & \(107\)&\(89\)\\
    \bottomrule
\end{tabular}
\end{adjustbox}
\end{table}
\end{document}

答案1

您必须将第二行的元素再次放入\multicolumn

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{adjustbox}
\usepackage{booktabs}

\begin{document}
\begin{table}[!h]
\centering
\begin{adjustbox}{max width=\textwidth}
\begin{tabular}{c|cc|cc|cc}
    \toprule
    \(J\) & \multicolumn{2}{c|}{Sovraelongazione} & \multicolumn{2}{c|}{\shortstack{Tempo di \\ salita}} &  \multicolumn{2}{c}{\shortstack{Tempo di \\ assestamento}} \\
    \midrule
    \(Kg\cdot m^{2}\) & \multicolumn{2}{c|}{\(\%\)} & \multicolumn{2}{c|}{\(msec\)} & \multicolumn{2}{c}{\(msec\)} \\
    \midrule
    & \(PI-diff_{\omega_{bv},J_{var}}\) & \(PI-diff_{\omega_{bv},J_{mid}}\) & \(PI-diff_{\omega_{bv},J_{var}}\) & \(PI-diff_{\omega_{bv},J_{mid}}\) & \(PI-diff_{\omega_{bv},J_{var}}\) & \(PI-diff_{\omega_{bv},J_{mid}}\)\\
    \midrule
    \(0.225\) &\(0\) &\(0\) & \(27\)&\(28\) & \(69\)&\(71\)\\
    \(1.390\) &\(0.3\) &\(0.3\) &\(29\) &\(29\) &\(72\) &\(72\)\\
    \(8.406\) & \(0.4\)&\(0.4\) & \(33\)&\(29\) & \(107\)&\(89\)\\
    \bottomrule
\end{tabular}
\end{adjustbox}
\end{table}
\end{document}

在此处输入图片描述

答案2

一些意见和建议:

  • 如果您使用包的线条绘制命令booktabs来生成间距适当的水平规则,则不应该使用垂直规则。

  • 使用\cmidrule指令为标题单元格提供更多视觉分组。

  • 使用包\si的宏siunitx来排版格式良好的科学单位。

  • 对于包含(大部分)数值数据的表,使用S列类型(也由siunitx包提供)而不是基本c列类型。

  • 标题单元格中似乎没有必要换行。

在此处输入图片描述

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{adjustbox}
\usepackage{booktabs,siunitx}
\newcommand{\mc}[1]{\multicolumn{2}{@{}c@{}}{#1}} % handy shortcut macro

\begin{document}

\begin{table}[!h]
\sisetup{table-format=3.0} % default
\begin{adjustbox}{max width=\textwidth}
\begin{tabular}{@{}c *{2}{S[table-format=1.1]} *{4}{S} @{}}
    \toprule
    \(J\) 
    & \mc{Sovraelongazione} & \mc{Tempo di salita} & \mc{Tempo di assestamento} \\
    (\si{\kilogram\meter\squared}) & \mc{(\%)} & \mc{(msec)} & \mc{(msec)} \\
    \cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-7} 
    & \(PI-\mathit{diff}_{\omega_{\mathrm{bv}},J_{\mathrm{var}}}\)
    & \(PI-\mathit{diff}_{\omega_{\mathrm{bv}},J_{\mathrm{mid}}}\)
    & \(PI-\mathit{diff}_{\omega_{\mathrm{bv}},J_{\mathrm{var}}}\)
    & \(PI-\mathit{diff}_{\omega_{\mathrm{bv}},J_{\mathrm{mid}}}\)
    & \(PI-\mathit{diff}_{\omega_{\mathrm{bv}},J_{\mathrm{var}}}\)
    & \(PI-\mathit{diff}_{\omega_{\mathrm{bv}},J_{\mathrm{mid}}}\)\\
    \midrule
    0.225 & 0   & 0   & 27 & 28 &  69 & 71\\
    1.390 & 0.3 & 0.3 & 29 & 29 &  72 & 72\\
    8.406 & 0.4 & 0.4 & 33 & 29 & 107 & 89\\
    \bottomrule
\end{tabular}
\end{adjustbox}
\end{table}
\end{document}

相关内容