[Tex/LaTex] Text in multirow overlaps the next row

multirowtables

Suppose, I want to create a table like this:

enter image description here

I decided to use \multirow with \newline. But the \multirow cell is not stretched vertically:

enter image description here

Code:

\documentclass{article}
\usepackage[a5paper]{geometry}
\usepackage{array}
\usepackage{multirow}
\usepackage{hhline}
\setlength{\parindent}{0cm}
\begin{document}
\begin{tabular}{|m{2cm}|m{2cm}|}
  \hline
  \multirow{2}{2cm}{line 1
      \newline
      line 2 line 2 line 2 line 2} &
  1\\
  \hhline{|~|-|}
  & 2\\
  \hline
  text & text\\
  \hline
\end{tabular}
\end{document}

How to fix?

Best Answer

It often works better to make the large entry a normal cell and then separately arrange the vertical stacking of the other material with a nested tabular or, here just as paragraphs.

enter image description here

\documentclass{article}
\usepackage[a5paper]{geometry}
\usepackage{array}

\usepackage{hhline}
\setlength{\parindent}{0cm}
\begin{document}
\begin{tabular}{|m{2cm}|m{2cm}|}
  \hline
  line 1 line 1 line 2 line 2 line 2 line 2&
  1
  \medskip\hrule\medskip
   2\\
  \hline
  text & text\\
  \hline
\end{tabular}
\end{document}

You may need to adjust the vertical spacing to your needs. As suggested in chat, this produces a 2 closer to the line, and makes the line extend to touch the vertical rules.

\documentclass{article}
\usepackage[a5paper]{geometry}
\usepackage{array}

\usepackage{hhline}
\setlength{\parindent}{0cm}
\begin{document}
\begin{tabular}{|p{2cm}|p{2cm}|}
  \hline
  line 1 line 1 line 2 line 2 line 2 line 2&
  1
  \par\medskip\nointerlineskip\hbox to \hsize{\kern-\tabcolsep\hrulefill\kern-\tabcolsep}
  \vspace{-1mm}
  2\\
  \hline
  text & text\\
  \hline
\end{tabular}
\end{document}