2

I have a very simple template of a table

enter image description here

I would like to add a slashbox at the top left corner (entry|item), similar to this post LaTeX table cell with a diagonal line and 2 sub cells

However, I have tried to add their code on top of the code below, yet I was not able to make it work.

Can someone provide a simple solution that creates a slashbox / diagonal line for this table?

\documentclass{article}
\usepackage{xcolor}
\usepackage{bbding}
\usepackage{amsthm, thmtools}
\usepackage{mathtools}
\usepackage{steinmetz}                           
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{graphics}                 
\usepackage{cancel}
\usepackage{subcaption} 
\usepackage{sidecap}                              
\usepackage{setspace}
\usepackage{verbatim}
\everymath{\displaystyle}
\setlength\parindent{0pt} 
\setlength{\footskip}{40pt}

\begin{document}
\begin{center}
    \centering\begin{tabular}{ |p{3cm}||p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
        \hline
          & entry 1 &  entry 2 & entry 3 &  entry 4 \\
        \hline
        item 1 & $\%$ & $\%$  & $\%$ & $\%$\\
        \hline
        item 2 & $\%$  & $\%$  & $\%$ & $\%$\\
        \hline
        item 3  & $\%$ & $\%$  & $\%$ & $\%$\\
        \hline
        item 4 & $\%$ & $\%$  & $\%$ & $\%$\\
        \hline
    \end{tabular}\\
\end{center}
 \end{document}
Fraïssé
  • 3,139
  • are you sure you want to globally do \everymath{\displaystyle} ?(it makes inline math essentially unusable as inline math, although it can be useful for some special situations where you need to use inline math for technical reasons but want it to look like display – David Carlisle Nov 28 '17 at 22:55
  • @DavidCarlisle I might have added that line as a quick fix for something a long time ago. I am not sure what this line does anymore. it makes inline math essentially unusable? Oh that sounds bad – Fraïssé Nov 28 '17 at 22:59
  • Do you need text to appear in the slashbox as in your linked example? Or just the diagonal line? – Sandy G Nov 28 '17 at 23:35

2 Answers2

4

You can do that with the diagbox package:

\documentclass{article}
 \usepackage{array, diagbox}
\setlength\parindent{0pt}

\begin{document}

\begin{center}\setlength{\extrarowheight}{2pt}
    \begin{tabular}{ |p{3cm}||*{4}{p{2cm}|}}
        \hline
        \diagbox[innerwidth = 3cm, height = 4ex]{}{} & entry 1 & entry 2 & entry 3 & entry 4 \\
        \hline
        item 1 & $\%$ & $\%$ & $\%$ & $\%$\\
        \hline
        item 2 & $\%$ & $\%$ & $\%$ & $\%$\\
        \hline
        item 3 & $\%$ & $\%$ & $\%$ & $\%$\\
        \hline
        item 4 & $\%$ & $\%$ & $\%$ & $\%$\\
        \hline
    \end{tabular}
\end{center}

 \end{document} 

enter image description here

Bernard
  • 271,350
0

With {NiceTabualar} of nicematrix, you do need adjustment to the command \diagbox (in fact, it's a command \diagbox provided by nicematrix).

\documentclass{article}
 \usepackage{nicematrix}

\begin{document}

\begin{center}\setlength{\extrarowheight}{2pt} \begin{NiceTabular}{ |p{3cm}||*{4}{p{2cm}|}}[hvlines] \diagbox{}{} & entry 1 & entry 2 & entry 3 & entry 4 \ item 1 & $%$ & $%$ & $%$ & $%$\ item 2 & $%$ & $%$ & $%$ & $%$\ item 3 & $%$ & $%$ & $%$ & $%$\ item 4 & $%$ & $%$ & $%$ & $%$\ \end{NiceTabular} \end{center}

\end{document}

Output of the above code

F. Pantigny
  • 40,250