如何在Latex表格中添加竖线

4

我有一张latex代码表格。

\begin{table}[c]

\caption{\textbf{the results of analysis of variance (One Way ANOVA) 
  for the differences in the responses of the study sample according
  to different classes.}}
\bigskip
\centering

\begin{tabular}  {|M{4.5cm}|M{1.5cm}|M{1.5cm}|M{1.5cm}|M{1.75cm}|M{1.5cm}|M{2.5cm}|}
\hline
 \textbf{} & \textbf{Variance}         
 &\textbf{Sum of the squares }  & \textbf{Degrees of Freedom } &
 \textbf{Average Squares} &\textbf{P Value} &\textbf{Statistical  significance } \\ 
\hline

\multirow{3}{*}{\makecell{Q11.2}} & UK &122 & 0.14 & 0.348 &
\multirow{3}{*}{\makecell{0.978}  }  &  \multirow{3}{*}
{\makecell{0.329}}\\  \cline{2-5}
             & SA  & 224 & 0.10 & 0.304
             \\  \cline{2-5}
             & SA  & 224 & 0.10 & 0.304
             &&    \\ \hline

\end{tabular}
\end{table}

我得到了这个输出 enter image description here
我不知道如何填充空的竖线!
我的代码有什么问题?
1个回答

10
在使用\multirow时,您必须在每一行中包含空单元格,以使多行跨度。这意味着该行应为:
    & SA  & 224 & 0.10 & 0.304 \\

实际上应该阅读为

    & SA  & 224 & 0.10 & 0.304 & & \\

这应该会得到所需的结果!

另外两点注意事项:

  • 您可能需要重新考虑使用\makecell命令,我认为这是不必要的。
  • 回答您的问题并不容易,因为您没有提供以下定义,您可能已经使用了:\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

这是我使用的整个代码

\documentclass[a4paper,11pt]{article}
\usepackage[a4paper,text={160mm,255mm},centering,headsep=5mm,footskip=10mm]{geometry}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{array}
\usepackage{multirow}

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}
\begin{table}[c]

\caption{\textbf{the results of analysis of variance (One Way ANOVA) 
  for the differences in the responses of the study sample according
  to different classes.}}
\bigskip
\centering

\begin{tabular}{|M{4.5cm}|M{1.5cm}|M{1.5cm}|M{1.5cm}|M{1.75cm}|M{1.5cm}|M{2.5cm}|}
\hline
    & \textbf{Variance} & \textbf{Sum of the squares} & 
        \textbf{Degrees of Freedom } & \textbf{Average Squares} &
        \textbf{P Value} & \textbf{Statistical  significance } \\ 
\hline
  \multirow{3}{*}{Q11.2} & UK &122 & 0.14 & 0.348 & 
        \multirow{3}{*}{0.978} & \multirow{3}{*}{0.329}\\  
\cline{2-5}
             & SA  & 224 & 0.10 & 0.304 & & \\
\cline{2-5}
             & SA  & 224 & 0.10 & 0.304 & & \\ 
\hline
\end{tabular}
\end{table}
\end{document}

生成此输出的方法是 在这里输入图片描述


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接