[Tex/LaTex] Overlapping table entry

multirowtables

When using multirow, the entry overlaps to other columnn

enter image description here
Here is my code:

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{table}
\begin{tabular}{|L{3cm} | L{3cm} | L{3cm} | L{3cm} |} \hline
    Phases & Input & Process & Output \\ \hline
    Phase 1 Acquisition of DNS query logs & DNS queries from MSU-IIT campus network & Name resolution via an existing DNS server & DNS query logs \\ \hline
    \multirow{2}{*}{Phase 2 Development of the domain name recommendation engine} & DNS query logs & Co-occurrence transformation & Co-occurrence matrix \\ \cline{2-4}
    & Co-occurrence matrix & Self-organizing feature map training & Transaction clusters \\ \cline{2-4} \hline
\end{tabular}
\end{table}

Any help?

Best Answer

The text argument of \multirow is put into an \hbox, if used with * for the width. \parbox and friends can be used to get a multi line text entry:

\documentclass{article}
\usepackage{array}
\usepackage{multirow}
\usepackage{ragged2e}

\newcolumntype{L}[1]{%
  >{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}%
}

\begin{document}
\begin{table}
\begin{tabular}{|L{3cm} | L{3cm} | L{3cm} | L{3cm} |} \hline
    Phases & Input & Process & Output \\ \hline
    Phase 1 Acquisition of DNS query logs & DNS queries from MSU-IIT campus
    network & Name resolution via an existing DNS server & DNS query logs \\
\hline
    \multirow{2}{*}{%
      \parbox{3cm}{\RaggedRight
        Phase 2 Development of the domain name recommendation engine}%
    } & DNS query logs & Co-occurrence transformation & Co-occurrence
        matrix \\ \cline{2-4}
    & Co-occurrence matrix & Self-organizing feature map training &
Transaction clusters \\ \hline
\end{tabular}
\end{table}
\end{document}

Result

Without hyphenation the entry is one line too long, therefore the example uses \RaggedRight instead of \raggedright.

It is easier to use 3cm instead of * in the argument of \multirow. Then the text is automatically set as multi line entry. The <fixup> argument moves the entry, thus that five lines fit into the space and hyphenation is no longer necessary:

\documentclass{article}
\usepackage{array}
\usepackage{multirow}

\newcolumntype{L}[1]{%
  >{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}% 
}

\begin{document}
\begin{table}   
\begin{tabular}{|L{3cm} | L{3cm} | L{3cm} | L{3cm} |} \hline
    Phases & Input & Process & Output \\ \hline
    Phase 1 Acquisition of DNS query logs & DNS queries from MSU-IIT campus
    network & Name resolution via an existing DNS server & DNS query logs \\  
\hline
    \multirow{2}{3cm}[1.25ex]{%
       \raggedright
        Phase 2 Development of the domain name recommendation engine%
    }
    & DNS query logs & Co-occurrence transformation & Co-occurrence
        matrix \\ \cline{2-4}
    & Co-occurrence matrix & Self-organizing feature map training &
Transaction clusters \\ \hline
\end{tabular}
\end{table}  
\end{document}

Result

Variant with package booktabs

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}

\newcolumntype{L}[1]{%
  >{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}%
}

\begin{document}
\begin{table}
\begin{tabular}{L{3cm} L{3cm} L{3cm} L{3cm}}
    \toprule
    Phases & Input & Process & Output \\
    \midrule
    Phase 1 Acquisition of DNS query logs & DNS queries from MSU-IIT campus
    network & Name resolution via an existing DNS server & DNS query logs \\
    \midrule
    \smash{\begin{tabular}[t]{@{}L{3cm}@{}}
        Phase 2 Development of the domain name recommendation engine%
    \end{tabular}}
    & DNS query logs & Co-occurrence transformation & Co-occurrence
        matrix \\
    \cmidrule{2-4}
    & Co-occurrence matrix & Self-organizing feature map training &
      Transaction clusters \\
    \bottomrule
\end{tabular}
\end{table}
\end{document}

Result booktabs