3

Considering the answer of question, I used the slashbox package to draw a diagonal line. But the problem is I have multiple rows in my table and that makes the line not aligned well within the cell corners. It also gives wierd spaces between cells:

\documentclass{article}
\usepackage{slashbox}
\usepackage{adjustbox}

\begin{document}


\begin{table}[!htpc]
\begin{center}
  \centering
  \caption{some table.}
  \label{possibility}
  \begin{footnotesize}

   \adjustbox{max height=\dimexpr\textheight-5.5cm\relax,
           max width=\textwidth}{
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}

  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  &first  & first  & second  & second & both  & both  & &\\
  &key & key &  key &  key& key & key & none&all\\
\backslashbox{Room}{Date}  &at & at &  at &  at & at & at& & \\
   &d & p &  d & p & d & p & &\\ \hline
  $C_1$&Y & N & N & N & N & N & N &N \\ \hline

  \hline


\end{tabular}
}
\end{footnotesize}
\end{center}
\end{table}

\end{document} 

EDIT

I have used the answer presented by @bernard but it gives me ! Use of \line doesn't match its definition as an error. Not sure if it would happen for others as well.

lonesome
  • 565

2 Answers2

2

It's better to use diagbox, which is more powerful. I improved your table using makecell (allows for line breaks and vertical padding in cells). Also, don't use the center environment in tables, as it adds unwanted vertical spacing; use \centering instead. The placement of the diagonal line is adjusted through the optional argument of \multirow.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{diagbox}
\usepackage{adjustbox}
\usepackage{caption, multirow, makecell}
\setcellgapes{3pt}

\begin{document}

\begin{table}[!htp]
  \centering
  \caption{some table.}
  \label{possibility}
  \footnotesize\makegapedcells
   \adjustbox{max height=\dimexpr\textheight-5.5cm\relax,
   max width=\textwidth}{
  \begin{tabular}{|*{9}{c|}}
    \hline
    \multirowcell{5.2}[2.3ex]{\diagbox[height=5.17\line]{\rlap{\enspace\raisebox{2ex}{Room}}}{\raisebox{-3.5ex}{Date}}} &\makecell{first\\key} & \makecell{first\\key} & \makecell{second\\key} & \makecell{second\\key} & \makecell{both\\keys} & \makecell{both\\keys}& none&all\\
          & at & at & at & at & at & at & & \\
          & d & p & d & p & d & p & & \\ \hline
    $C₁$ & Y & N & N & N & N & N & N & N \\
    \hline
  \end{tabular}
  }
\end{table}

\end{document} 

enter image description here

Bernard
  • 271,350
0

Here is what you can do with {NiceTabular} of nicematrix.

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

\begin{document}

\begin{table}[!htp] \centering \caption{some table.} \label{possibility} \begin{NiceTabular}{w{c}{2cm}*{8}{c}}[vlines,cell-space-limits=3pt] \hline \Block{3-1}{\diagbox{\quad \rule[-5pt]{0pt}{5pt}Room}{\rule{0pt}{15pt}Date\quad}} & \Block{}{first\key} & \Block{}{first\key} & \Block{}{second\key} & \Block{}{second\key} & \Block{}{both\keys} & \Block{}{both\keys}& none&all\ & at & at & at & at & at & at & & \ & d & p & d & p & d & p & & \ \hline $C_1$ & Y & N & N & N & N & N & N & N \ \hline \end{NiceTabular} \end{table}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

F. Pantigny
  • 40,250