Wrong column spacing due to multicolumn in latex

孤人 提交于 2019-12-10 11:55:37

问题


in the LaTeX table below, the third column gets too way much spacing due to the long \multicolumn cell in the last line. Can anyone think of a way of getting LaTeX to distribute the additional spacing needed evenly across columns?

\documentclass[11pt]{article}
\usepackage{booktabs}

\begin{document}
\begin{table}[htbp]
\centering
\begin{tabular}{lrrr}
\toprule
 & ICE-GB & ICE-SING & ICE-EA \\ 
 \midrule
NP & 619 & 595 & 496 \\ 
\textbf{Arithmetic mean}& \textbf{1.36} & \textbf{1.33} & \textbf{1.22} \\ 
SD&0.73 & 0.71 & 0.53 \\ 
Variation coefficient& 0.54 & 0.52 & 0.44 \\ 
\midrule
Kruskal Wallis rank sum test&\multicolumn{3}{l}{$H = 16.3941, df = 2, p= 0.0002755123$} \\ 
\bottomrule
\end{tabular}
\end{table}
\end{document}

Thanks!


回答1:


Excess width \multicolumns end up assigning the excess to the last column. You can avoid this by either using a fixed-width \multicolumn - that is, use a p{<len>} column, or for even spreading of columns use a fixed-width column for the non-\multicolumn columns:

\documentclass[11pt]{article}
\usepackage{booktabs,array}

\begin{document}
\noindent
\begin{tabular}{l*{3}{>{\raggedleft\arraybackslash}p{5em}}}
  \toprule
  & ICE-GB & ICE-SING & ICE-EA \\ 
  \midrule
  NP & 619 & 595 & 496 \\
  \textbf{Arithmetic mean}     & \textbf{1.36} & \textbf{1.33} & \textbf{1.22} \\ 
  SD                           & 0.73          & 0.71          & 0.53 \\ 
  Variation coefficient        & 0.54          & 0.52          & 0.44 \\ 
  \midrule
  Kruskal Wallis rank sum test & \multicolumn{3}{r}{$H = 16.3941, df = 2, p= 0.0002755123$} \\ 
  \bottomrule
\end{tabular}
\end{document}

In the above example, the last three columns each have width 5em, and are \raggedleft (similar to an r-column specification).



来源:https://stackoverflow.com/questions/25688560/wrong-column-spacing-due-to-multicolumn-in-latex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!