4

how can i fix my table? I would like to center the \(\%\) and the two \(\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}
  • Off-topic: If you use the line-drawing commands of the booktabs package to generate well-spaced horizontal rules, you shouldn't be using vertical rules. – Mico Aug 28 '17 at 7:51
3

You have to put the elements of the second row again in a \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}

enter image description here

4

Some comments and suggestions:

  • If you use the line-drawing commands of the booktabs package to generate well-spaced horizontal rules, you shouldn't be using vertical rules.

  • Use \cmidrule directives to provide more visual grouping for the header cells.

  • Use the \si macro of the siunitx package to typeset well-formatted scientific units.

  • For table with (mostly) numerical data, use the S column type (also by the siunitx package) instead of the basic c column type.

  • There doesn't seem to be any need for line breaks in the header cells.

enter image description here

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.