[Tex/LaTex] Multirow not working in tabular environment

multirow

I am using the multirow package to typeset a tabular where two rows should merge into one. I look very carefully at my code and compare it to the working example but it fails to work. An ugly horizontal line goes across the rows that are supposed to be merged.

\documentclass{article}
\usepackage{array, float, multirow}
\begin{document}

\begin{table}[H]
  \centering
  \caption{LLLL}
  \label{tab:location-xiagu}
  \begin{tabular}{|c|>{\centering}m{0.1\textwidth}|m{0.5\textwidth}|}
    \hline
    \multirow{2}{*}{A} & B & C\tabularnewline
    \hline
    & A & C \tabularnewline
    \hline
    \multirow{2}{*}{X} & W & E \tabularnewline
    \hline
    & O &  E \tabularnewline
    \hline
    \multirow{2}{*}{S} & M & N \tabularnewline
    \hline
    & P & W  \tabularnewline
    \hline
  \end{tabular}
\end{table}
\end{document}

What the above code did to me is:

But I want no line crossing the A, X, S letters. Thanks in advance!

Best Answer

\hline will draw a full line, you need to use \cline{2-3} for this:

\documentclass{article}
\usepackage{array, float, multirow}
\begin{document}

\begin{table}[H]
  \centering
  \caption{LLLL}
  \label{tab:location-xiagu}
  \begin{tabular}{|c|>{\centering}m{0.1\textwidth}|m{0.5\textwidth}|}
    \hline
    \multirow{2}{*}{A} & B & C\tabularnewline
    \cline{2-3}
    & A & C \tabularnewline
    \hline
    \multirow{2}{*}{X} & W & E \tabularnewline
    \cline{2-3}
    & O &  E \tabularnewline
    \hline
    \multirow{2}{*}{S} & M & N \tabularnewline
    \cline{2-3}
    & P & W  \tabularnewline
    \hline
  \end{tabular}
\end{table}
\end{document}

Alternatively, you can use booktabs and remove the vertical lines which, to me, gives a much more pleasing result:

\documentclass{article}
\usepackage{array, float, multirow}
\usepackage{booktabs,caption}
\begin{document}

\begin{table}[H]
  \centering
  \caption{LLLL}
  \label{tab:location-xiagu}
  \begin{tabular}{c >{\centering}m{0.1\textwidth} m{0.5\textwidth} }
    \toprule
    \multirow{2}{*}{A} & B & C\tabularnewline
    & A & C \tabularnewline
    \midrule
    \multirow{2}{*}{X} & W & E \tabularnewline
    & O &  E \tabularnewline
    \midrule
    \multirow{2}{*}{S} & M & N \tabularnewline
    & P & W  \tabularnewline
    \bottomrule
  \end{tabular}
\end{table}
\end{document}

as others have notes, the package caption will give you the proper spacing for your caption above the table.

enter image description here