6

How do I split a cell diagonally, when I'm using tabularx with X column, i.e. \begin{tabularx}{\textwidth}{X}?

I've seen many answers on this topic on TeX.SE, but none of them are applicable to cells with a fluid width (X column).

I've currently solved my problem by using the diagbox package with a hard-coded width (found through trial-and-error). However, I would like to know how to solve it properly, i.e. a way to achieve the diagonal split without knowing the dimensions of the cell in advance.

This is my current code, demonstrating the visually desired result, achieved by hard-coding the width of the backslashbox.

\documentclass{standalone}
\usepackage{tabularx}
\usepackage{diagbox}
\begin{document}
  \begin{tabularx}{\textwidth}{|X|c|c|c|}
  \hline
    \backslashbox[92mm]{Task}{Question} & 1 & 2 & 3\\
  \hline
    What? & Yes & Yes & Yes \\
  \hline
  \end{tabularx}
\end{document}

Result:

Moriambar
  • 11,466
Rob W
  • 540

1 Answers1

6
\documentclass{standalone}
\usepackage{tabularx}
\usepackage{diagbox}
\begin{document}
  \begin{tabularx}{\textwidth}{|X|c|c|c|}
  \hline
    \backslashbox[\dimexpr\linewidth+2\tabcolsep]{Task}{Question} & 1 & 2 & 3\\
  \hline
    What? & Yes & Yes & Yes \\
  \hline
  \end{tabularx}
\end{document}

enter image description here

Moriambar
  • 11,466
  • 1
    Thanks, it works! Can you explain the \dimexpr\linewidth+2\tabcolsep part, preferably with references to documentation? – Rob W May 22 '13 at 16:15
  • 1
    Instead of \linewidth you can also use \hsize. – cacamailg May 22 '13 at 16:19
  • 2
    @RobW: every cell has on the left and right an additional width of \tabcolsep which is by default set to 6pt –  May 22 '13 at 16:28