# How to create a multirow latex table with line on main diagonal?

I would like to create a Latex table with a line on the main diagonal. My problem: diagbox does not calculate the height in the right way for multirow fields. A small example:

\documentclass[a4paper]{article}
\usepackage{calc}
\usepackage{diagbox}

\begin{document}
\begin{tabular}{p{\textwidth*1/7}*{3}{|p{\textwidth*1/7}}}
\diagbox[innerwidth=\textwidth*1/7]{from}{to} & item1 & item2 & item3 \\\hline
item1 & \diagbox[innerwidth=\textwidth*1/7]{~}{~} & --- this --- is --- a --- very --- long --- multirow --- text --- & \\\hline
item2 & & \diagbox[innerwidth=\textwidth*1/7]{~}{~} &   \\\hline
item3 & & & \diagbox[innerwidth=\textwidth*1/7]{~}{~}
\end{tabular}
\end{document}


How can I connect the diagonal lines?

Greeting, Patrick

• Is the diagonal to be straight all over the table or only on the single cells? – CarLaTeX Nov 4 '17 at 14:23
• The diagonal should be straigt only on the single cells. – PSaR Nov 4 '17 at 15:34

I don't know why if you use height=... option of \diagbox the text of the following multiline cell is shifted down, but you can work around it adding a \vspace{-...} to bring it up again.

However, I suggest to you to redesign your table with no vertical rules, no diagonal boxes, and em-dashes as text of the cells on the diagonal.

\documentclass[a4paper]{article}
\usepackage{booktabs}
\usepackage{diagbox}

\begin{document}
\noindent With a little workaround:
\begin{center}
\begin{tabular}{p{\textwidth*1/7}*{3}{|p{\textwidth*1/7}}}
\diagbox[innerwidth=\textwidth*1/7]{from}{to} & item1 & item2 & item3 \\\hline
item1 & \diagbox[innerwidth=\textwidth*1/7,height=7\line]{~}{~} & \vspace{-9ex}--- this --- is --- a --- very --- long --- multirow --- text --- & \\\hline
item2 & & \diagbox[innerwidth=\textwidth*1/7]{~}{~} &   \\\hline
item3 & & & \diagbox[innerwidth=\textwidth*1/7]{~}{~}
\end{tabular}
\end{center}
\noindent But I suggest to you to use something like this:
\begin{center}
\begin{tabular}{*{4}{p{\textwidth*1/7}}}
\toprule
& \multicolumn{3}{c}{To:}\\
\cmidrule{2-4}
From: & item1 & item2 & item3 \\
\midrule
item1 & \textemdash & --- this --- is --- a --- very --- long --- multirow --- text --- & \\
item2 & & \textemdash & \\
item3 & & & \textemdash \\
\bottomrule
\end{tabular}
\end{center}
\end{document}