[Tex/LaTex] How to avoid text overlap when using `multirow` in `longtable`

longtablememoirmultirow

I have a two column table. The first column contains (for eg) name and designation and second column has lots of text. I want the name and designation to stay close but on separate lines. For this I enter them on separate rows. However when I use multirow on second column, the text from one row starts overlapping text from subsequent rows. How can I avoid text from different rows from overlapping? The following code show some things I have been trying. I was trying to get to the contents formatted as on second page (last 2-3 rows) but want to avoid the text overlap.

\documentclass[oneside]{memoir}

% \usepackage[cm]{fullpage}
% \usepackage{showframe}
% showframe does not show proper frame
\usepackage[margin=0.5in, showframe]{geometry}

\usepackage{lipsum}
\usepackage{longtable}
\usepackage{calc}
\usepackage{multirow}

\begin{document}

\newlength{\tablecolwidth}
\setlength{\tablecolwidth}{0.6\textwidth-2\tabcolsep}

\begin{longtable}{@{}lp{\tablecolwidth}@{}}
    \caption{Contents}\\
    \textbf{Col 1} & \textbf{Col 2} \\
    \midrule[0.25ex]
\endfirsthead
    \multicolumn{2}{c}{\tablename\ \thetable{}: continued}\\[1ex]
    \textbf{Col 1} & \textbf{Col 2} \\
    \midrule[0.25ex]
\endhead
    \midrule
    \multicolumn{2}{r}{Continued \ldots}\\
\endfoot
    \bottomrule[0.25ex]
\endlastfoot

Name       & \lipsum[2] \\
Designation & \lipsum[1] \\
\midrule

% Contents overflow on right
Name       & \multirow{2}{*}{\lipsum[2]} \\
Designation \\
           & \lipsum[1] \\
\midrule

% Contents of next row overlap subsequent rows and over flow page boundary
Name       & \multirow{2}{\tablecolwidth}{\lipsum[1-2]} \\
Designation \\
           & \lipsum[1] \\
\midrule

% Another way of limiting column width but overlap remains
Name       & \multirow{2}{*}{\parbox{\tablecolwidth}{\lipsum[2]}} \\
Designation \\
           & \lipsum[1] \\

\end{longtable}
\end{document}

Also when I use fullpage and showframe, I get incorrect frame. I was able to fix it using geometry package, but still wondering what the reason for the wrong frame is?

Edit, I was able to get the right formatting this way,

Name       & \multirow{1}{*}{\parbox{\tablecolwidth}{\lipsum[2]}} \\
Designation \\ \\ \\ \\ \\ \\ \\
           & \lipsum[1] \

However I am still trying to find a better way to do this.

Best Answer

Margins, showframe

Package fullpage does not support memoir. The class memoir is more complicate than the standard classes regarding the page layout. It provides additional length \stockwidth, \stockheight and another stuff like crop marks, …

The additional length \spinemargin, \foremargin, \uppermargin, \lowermargin are not supported by package geometry. After the new margins are set, these length have the wrong values. But package showframe/eso-pic supports memoir and uses some of these length.

They can manually be fixed:

\usepackage[margin=0.5in]{geometry}
\spinemargin=\dimexpr\oddsidemargin+1in\relax
\foremargin=\dimexpr\evensidemargin+1in\relax
\uppermargin=\dimexpr\topmargin+1in+\headheight+\headsep\relax
\checkandfixthelayout
\usepackage{showframe}

But I do not recommend using geometry with memoir, because the class has its own methods for setting the page layout, e.g.:

\setlrmarginsandblock{.5in}{.5in}{*}
\setulmarginsandblock{.5in}{.5in}{*}
\checkandfixthelayout
\usepackage{showframe}

Tabular

Perhaps you just want to have two p-columns, but without the width specification for the first? Then you can use a tabular inside the longtable to put the two entries in two lines in the first column:

\documentclass[oneside]{memoir}

\setlrmarginsandblock{.5in}{.5in}{*}
\setulmarginsandblock{.5in}{.5in}{*}
\checkandfixthelayout
\usepackage{showframe}

\usepackage{lipsum}
\usepackage{longtable}
\usepackage{calc}

\newcommand*{\namedes}[2]{%
  \begin{tabular}[t]{@{}l@{}}%
    #1\tabularnewline
    #2%
  \end{tabular}%
}

\begin{document}

\newlength{\tablecolwidth}
\setlength{\tablecolwidth}{0.6\textwidth-2\tabcolsep}

\begin{longtable}{@{}lp{\tablecolwidth}@{}}
    \caption{Contents}\\
    \textbf{Col 1} & \textbf{Col 2} \\
    \midrule[0.25ex]
\endfirsthead
    \multicolumn{2}{c}{\tablename\ \thetable{}: continued}\\[1ex]
    \textbf{Col 1} & \textbf{Col 2} \\
    \midrule[0.25ex]
\endhead
    \multicolumn{2}{r}{Continued \ldots}\\
\endfoot
    \bottomrule[0.25ex]
\endlastfoot
\namedes{Name}{Designation} & \lipsum[2] \lipsum*[1]\\
\midrule
\namedes{Name}{Designation} & \lipsum[2] \lipsum*[1]\\
\end{longtable}
\end{document}

Result

Related Question