4

I've been trying to get a diagonally-split table header using the diagbox package, but I have a problem.

Here's a working sample that shows the problem:

    \documentclass[12pt, a4paper, twoside]{article}


\usepackage{diagbox} %table split headers
\usepackage{longtable} 
\usepackage{array}
\usepackage{rotating}

\newcommand{\tabred}{-4pt}
\newcommand*\rot{\rotatebox{90}}

\begin{document}

\begin{longtable}{
    | l<{\hspace{\tabred}} 
    | >{\hspace{\tabred}}c<{\hspace{\tabred}} 
    | >{\hspace{\tabred}}c<{\hspace{\tabred}} 
    | >{\hspace{\tabred}}c<{\hspace{\tabred}} 
    | >{\hspace{\tabred}}c<{\hspace{\tabred}} 
    | >{\hspace{\tabred}}c<{\hspace{\tabred}} 
    | >{\hspace{\tabred}}c<{\hspace{\tabred}}
    |}

\hline

\diagbox[dir=NW]{Feature}{Tool}  & %THIS IS THE PROBLEM!

\rot{Tool Alpha}    & 
\rot{Tool Delta}    & 
\rot{Tool Gamma}    & 
\rot{Tool Theta} & 
\rot{Tool Upsilon} & 
\rot{\textbf{Tool X (our proposal) }}\\

%\midrule
\hline

Feature A - Fooing the Bar  & NO    & NO    & NO    & NO    & OK    & OK\\
Feature B - Barring the Foo & OK    & NO    & OK    & NO    & NO    & OK\\
\hline
\end{longtable}

\end{document}

The problem is that, since I rotate the headers, they are very tall. As you can see from the image below, this ruins the alignment of the diagonal line:

enter image description here

As you can see, there are two problems: the north-west end of the diagonal line doesn't touch the north-west corner of the box, and the south-east end of the diagonal line doesn't touch the south-east corner.

With the answer posted here: https://tex.stackexchange.com/a/215370/45766 I've been able to use \rule to fix one of the angles, but never both. No matter what I try, the spacing screws up.

Any ideas?

5

I propose to make the last rotated header two-lined. This is possible with the \rothead and \rotcell commands from makecell * also use the keys height= and width= from diagbox. The width is set with the help of te eqparbox package, with eqboxwidth length. Finally I replaced your \tabred command with changing the value off \tabcolsep.

\documentclass[12pt, a4paper, twoside]{article}
\usepackage[utf8]{inputenc}
\usepackage{diagbox} %table split headers
\usepackage{longtable}
\usepackage{array}
\usepackage{rotating}
\usepackage{eqparbox}
\usepackage{makecell, caption, booktabs}

\begin{document}

\centering\settowidth\rotheadsize{\bfseries(our proposal)}
\renewcommand\theadalign{cl}\renewcommand\cellalign{cl}
\renewcommand\theadfont{\bfseries}
\renewcommand\tabcolsep{4pt}\renewcommand\arraystretch{1.25}
\begin{longtable}{
    |l |*{6}{c |} }%
    \hline
    \diagbox[height=1.2\rotheadsize, width=\dimexpr\eqboxwidth{AB}+2\tabcolsep\relax]%
    {\raisebox{1.5ex}{Feature}}{\raisebox{-5ex}{Tool}} & %THIS IS THE PROBLEM!
    \rotcell{Tool Alpha} &
    \rotcell{Tool Delta} &
    \rotcell{Tool Gamma} &
    \rotcell{Tool Theta} &
    \rotcell{Tool Upsilon} &
    \rothead{Tool X\\\mbox{(our proposal)}}\\
    \hline
    \eqmakebox[AB][l]{Feature A – Fooing the Bar} & NO & NO & NO & NO & OK & OK \\
    \eqmakebox[AB]{Feature B – Barring the Foo} & OK & NO & OK & NO & NO & OK \\
    \hline
  \end{longtable}

\end{document} 

enter image description here

3

enter image description here

I would totally get rid of that diagonal rule. I think there is no need for it or it will not increase readability as one may wish. Here is a simple design with the same data.

\documentclass[12pt, a4paper, twoside]{article}
\usepackage{longtable} 
\usepackage{booktabs}
\begin{document}

\begin{longtable}{lcc}\toprule
             & \multicolumn{2}{c}{Feature}\\ \cmidrule{2-3}
Tool         & A - Fooing the Bar & B - Barring the Foo \\ \midrule
Tool Alpha   & NO & OK \\
Tool Delta   & NO & NO \\
Tool Gamma   & NO & OK \\
Tool Theta   & NO & NO \\
Tool Upsilon & OK & NO \\
\textbf{Tool X (our proposal)} & OK &   OK \\ \bottomrule
\end{longtable}

\end{document}
  • Thanks for your reply. However, it doesn't really answer my question. What I posted is just a sample. The real table is much bigger, with more than 50 Features, plus the feature descriptions are long. And the table must fill half the width of an A4 page. Which means: tools must be on the X-axis and with vertical headings, and features must be on the Y-axis. Your solution is inapplicable in my case, there's not enough space to do it like you did. – Master_T Sep 24 '15 at 12:05
0

Well, I solved it "manually" by trial and error while waiting for answers. Here's my solution:

    \documentclass[12pt, a4paper, twoside]{article}


\usepackage{diagbox} %table split headers
\usepackage{longtable} %multi-page tables
\usepackage{array}
\usepackage{rotating}

\newcommand{\tabred}{-4pt}
\newcommand*\rot{\rotatebox[x=2.32cm]{90}}

\begin{document}

\begin{longtable}{
    | l<{\hspace{\tabred}} 
    | >{\hspace{\tabred}}c<{\hspace{\tabred}} 
    | >{\hspace{\tabred}}c<{\hspace{\tabred}} 
    | >{\hspace{\tabred}}c<{\hspace{\tabred}} 
    | >{\hspace{\tabred}}c<{\hspace{\tabred}} 
    | >{\hspace{\tabred}}c<{\hspace{\tabred}} 
    | >{\hspace{\tabred}}c<{\hspace{\tabred}}
    |}

\hline

\diagbox[dir=NW]{\rule{0mm}{4.2cm}\rule{0.9cm}{0cm}Feature}{Tool}  &

\rot{Tool Alpha}    & 
\rot{Tool Delta}    & 
\rot{Tool Gamma}    & 
\rot{Tool Theta} & 
\rot{Tool Upsilon} & 
\rot{\textbf{Tool X (our proposal) }}\\

%\midrule
\hline

Feature A - Fooing the Bar  & NO    & NO    & NO    & NO    & OK    & OK\\
Feature B - Barring the Foo & OK    & NO    & OK    & NO    & NO    & OK\\
\hline
\end{longtable}

\end{document}

Basically the idea is this:

  1. Assign a [x=XXcm] option to \rotatebox
  2. Put two \rules in the first parameter of \diagbox, one with only horizontal size and the other with only vertical size
  3. Play around with the XX value and the size of the \rules until the alignment is correct. Might take some time. The values in the above code are correct for my sample, but you'll have to find what's good for yours by trying.

Here's the result:
enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.