简体   繁体   中英

How to Add vertical line in table Latex

I have this sheet of latex code.

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

I get this output 在此输入图像描述 :

I don't know how to fill empty vertical lines!

What's wrong with my code?

When using \\multirow , you have to include empty cells in each row that you want the multirow to span. This means that the line

    & SA  & 224 & 0.10 & 0.304 \\

actually should read as

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

This should give the desired result!

Two additional remarks:

  • You might want to reconsider the usage of the \\makecell -command, which is in my opinion not necessary.
  • It was not easy to answer your question as you did not provide the following defintion, which you have probably used: \\newcolumntype{M}[1]{>{\\centering\\arraybackslash}m{#1}}

Here is the entire code i used

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

to generate this output 在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM