4

I want to add a diagonal line in a the top line of a table where the other entries on the first row are written sideways. I've tried \backslashbox and \diagbox and \diag but no matter how I change the values the topmost position of the line does not increase without lifting all the other entries.

\usepackage{slashbox}

\begin{table}[ht]
\centering
\caption{Pugh matrix}
\begin{tabular}{|l|c|c|c|}
\hline\hline
\backslashbox[130pt]{Property}{Concept} & \begin{sideways} Concept 1 \end{sideways} &  \begin{sideways} Next concept \end{sideways} & 
\begin{sideways} Next concept/increase line{\ }  \end{sideways} \\
\hline
Do this                & 0 & 0 & - \\
Do that     & 0 & 0 & 0 \\
Do it quickly   & 0 & + & + \\
Do the task quickly         & 0 & 0 & - \\ 
\hline 
SUM:                        & 0 & +1 & +2 \\
\hline
Ranking                     & 2 & 2 & 1  \\
\hline
Keep                        & NO & NO & YES \\
\hline\hline
\end{tabular}
\label{tab:Pugh_matrix2}
\end{table}

example

0

3 Answers 3

3

I used diagbox instead of slashbox and the rotatebox macro from graphicx instead of the rotating package:

\documentclass{article}
\usepackage{diagbox}
\usepackage{rotating}
\usepackage{graphicx}
\begin{document}
\begin{table}[ht]
\centering
\caption{Pugh matrix}
\begin{tabular}{|l|c|c|c|}
\hline\hline
\diagbox[dir=NW]{\rule{0mm}{4cm}Property}{Concept} & \rotatebox[x=2cm]{90}{Concept 1} & \rotatebox[x=2cm]{90}{Next concept} & 
\rotatebox[x=2cm]{90}{Next concept/increase line\ } \\
\hline
Do this                & 0 & 0 & - \\
Do that     & 0 & 0 & 0 \\
Do it quickly   & 0 & + & + \\
Do the task quickly         & 0 & 0 & - \\ 
\hline 
SUM:                        & 0 & +1 & +2 \\
\hline
Ranking                     & 2 & 2 & 1  \\
\hline
Keep                        & NO & NO & YES \\
\hline\hline
\end{tabular}
\label{tab:Pugh_matrix2}
\end{table}
\end{document}

enter image description here

1

I propose another solution, based on the \rotcell command from makecell, which allows for line breaks in cells. Also various improvements to the table, in particular vertical padding between caption and table thanks to the caption package.

\documentclass{article}
\usepackage{diagbox}
\usepackage{rotating}
\usepackage{graphicx}
\usepackage{makecell, caption, booktabs}

\begin{document}

\begin{table}[ht]
  \centering\settowidth\rotheadsize{Next concept/}
  \renewcommand\cellalign{cl}
  \renewcommand\arraystretch{1.25}
  \caption{Pugh matrix}
  \begin{tabular}{|l|c|c|c|c}
    \toprule\noalign{\vskip-1pt}\hline
    \diagbox[height=1.25\rotheadsize]{\raisebox{3ex}{Property}}{\raisebox{-4ex}{Concept}} & \rotcell{Concept 1} & \rotcell{Next concept} & \rotcell{Next concept/ \\increase line} \\
    \hline
    Do this & 0 & 0 & $ - $ \\
    Do that & 0 & 0 & 0 \\
    Do it quickly & 0 & + & + \\
    Do the task quickly & 0 & 0 & $ - $ \\
    \hline
    SUM: & 0 & +1 & +2 \\
    \hline
    Ranking & 2 & 2 & 1 \\
    \hline
    Keep & NO & NO & YES \\
    \hline\bottomrule
  \end{tabular}
  \label{tab:Pugh_matrix2}
\end{table}

\end{document} 

enter image description here

1

The environment {NiceTabular} of nicematrix has a built-in command \diagbox. With that tool, you have directly the expected output.

\documentclass{article}
\usepackage{nicematrix,caption}

\begin{document}

\begin{table}[ht]
\centering
\caption{Pugh matrix}
\begin{NiceTabular}{lccc}[vlines]
\hline
\diagbox{Property}{Concept} & 
\RowStyle[cell-space-top-limit=3pt]{\rotate}
Concept 1 & Next concept & Next concept/increase line  \\
\hline
Do this                & $0$ & $0$  & $-$ \\
Do that                & $0$ & $0$  & $0$ \\
Do it quickly          & $0$ & $+$  & $+$ \\
Do the task quickly    & $0$ & $0$  & $-$ \\ 
\hline 
SUM:                   & $0$ & $+1$ & $+2$ \\
\hline
Ranking                & $2$ & $2$  & $1$  \\
\hline
Keep                   & NO  & NO   & YES \\
\hline
\end{NiceTabular}
\label{tab:Pugh_matrix2}
\end{table}

\end{document}

Output of the first code

If you actually want to put double rules above and below the tabular, there will be a small issue. If you use \hline\hline for the double rule above the table, the top-left position of the diagonal rule won't be correct. That's why, in the following code, I have drawn the first rule above the tabular with Tikz (using PGF/Tikz nodes created by nicematrix).

\documentclass{article}
\usepackage{nicematrix,caption,tikz}

\begin{document}

\begin{table}[ht]
\centering
\caption{Pugh matrix}
\begin{NiceTabular}{lccc}[vlines]
\Hline
\diagbox{Property}{Concept} & 
\RowStyle[cell-space-top-limit=3pt]{\rotate}
Concept 1 & Next concept & Next concept/increase line  \\
\Hline
Do this                & $0$ & $0$  & $-$ \\
Do that                & $0$ & $0$  & $0$ \\
Do it quickly          & $0$ & $+$  & $+$ \\
Do the task quickly    & $0$ & $0$  & $-$ \\ 
\Hline 
SUM:                   & $0$ & $+1$ & $+2$ \\
\Hline
Ranking                & $2$ & $2$  & $1$  \\
\Hline
Keep                   & NO  & NO   & YES \\
\Hline
\Hline
\CodeAfter
   \tikz \draw ([yshift=\doublerulesep]1-|1) -- ([yshift=\doublerulesep]1-|last)  ; 
\end{NiceTabular}
\label{tab:Pugh_matrix2}
\end{table}

\end{document}

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .