2

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!

1
  • You need to remove three of the \hline.
    – AML
    May 10, 2018 at 15:34

2 Answers 2

3

\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

5
  • @cgsdfc please consider voting for the answer and marking it as the solution.
    – ArTourter
    May 10, 2018 at 15:56
  • 1
    I'd suggest some padding at the top of cells with \setlength[\extrarrowheight}{...}d a better spacing between caption table, just loading caption.
    – Bernard
    May 10, 2018 at 17:29
  • @Bernard I agree that the table design is not really optimal. I was also going to suggest use booktabs as an alternative but felt it was slightly at of scope and I got distracted before amending my answer.
    – ArTourter
    May 10, 2018 at 20:53
  • @ArTourter: I posted the improvements, because I thought you didn't have time, and I feel important to show LaTeX beginners different tools for taking care of the aesthetic aspect of tables.
    – Bernard
    May 10, 2018 at 21:04
  • @ArTourter sorry for the delay. Finding that green big tick takes some newby's time but it should be alright now. Great answer anyway.
    – cgsdfc
    May 11, 2018 at 16:30
2

Some improvements: I added some padding to cells, and variable width vertical and horizontal rules with boldline:

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

\begin{table}[H]
  \centering\setlength{\extrarowheight}{2pt}
  \caption{LLLL}
  \label{tab:location-xiagu}
  \begin{tabular}{V{2.5}cV{2.5}>{\centering}m{0.1\textwidth}| >{\arraybackslash}m{0.5\textwidth}V{2.5}}
    \hlineB{2.5}
    \multirow{2}{*}{A} & B & C \\
    \cline{2-3}
    & A & C \\
    \hlineB{2.5}
    \multirow{2}{*}{X} & W & E \\
    \cline{2-3}
    & O & E \\
    \hlineB{2.5}
    \multirow{2}{*}{S} & M & N \\
    \cline{2-3}
    & P & W \\
    \hlineB{2.5}
  \end{tabular}
\end{table}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .