I am trying to create a table which contains (multiple) multirow cells with a certain width, automatically wrapping the text. However, when the text is too long, it spills over to the next cell.
I know I can use the \\[1cm]
to manually solve this problem (also see Auto resize tabular row height) but I want to do this automatically. Is this possible?
Here is a MWE:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\begin{document}
\noindent\begin{tabular}{p{4cm}|c}
A & B \\\hline
\multirow{2}{4cm}{My long text here is ok, not long enough to spill} & 1 \\\cline{2-2}
& 2 \\\hline
\multirow{2}{4cm}{Other text here} & 3 \\\cline{2-2}
& 4 \\\hline
\end{tabular}
\vspace{3cm}
\noindent\begin{tabular}{p{4cm}|c}
A & B \\\hline
\multirow{2}{4cm}{My super long text here will spill over to the next line. How do I avoid this?} & 1 \\\cline{2-2}
& 2 \\\hline
\multirow{2}{4cm}{Other text here} & 3 \\\cline{2-2}
& 4 \\\hline
\end{tabular}
\end{document}
Output:
I will accept answers using other environments/packages.
\multirow
.