2

How can I draw a diagonal that on one side, says Ratings and on the other, books?

This is an example made by @Marmot:

\documentclass{article}
\usepackage{amsmath,blkarray}

\begin{document}

\[
\begin{blockarray}{lccc}
\text{Ratings} & \text{book}_1 & \text{book}_2 & \text{book}_3  \\
\begin{block}{l(ccc)}
\text{user}_1 & - & 1 & -  \smash[b]{\vphantom{\Big|}}\\
\text{user}_2 & - & 5 & -  \\
\text{user}_3 & 4 & - & -  \\
\text{user}_4 & - & - & 2\smash[t]{\vphantom{\Big|}}\\
\end{block}
\end{blockarray}
\]
\end{document}

Desired output:

enter image description here

  • Could you please add a sketch of the desired output to your question? Aslo how is the question related to tikz-pgf (which you chose as a tag for your question)? Lastly, you might be interested in Diagonally divided table cell or Diagonal lines in table cell – leandriis Jul 6 at 9:47
  • I was told that it could be done with tikz so that it looks nicer. I have updated the OP. Nevermind the “movies’” label, Actually, what goes there is the word “books” – user192311 Jul 6 at 9:52
1

You can achieve the desired output using for example the slashbox package. In the following MWE I have aso included an alternative that might also be interesting:

enter image description here

\documentclass{article}
\usepackage{amsmath,blkarray}

%%%%% Only for the second example %%%%%
\usepackage{slashbox}
\usepackage{array,multirow,graphicx}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\[
\begin{blockarray}{lccc}
\text{\backslashbox{Ratings}{Books}} & \text{book}_1 & \text{book}_2 & \text{book}_3  \\
\begin{block}{l(ccc)}
\text{user}_1 & - & 1 & -  \smash[b]{\vphantom{\Big|}}\\
\text{user}_2 & - & 5 & -  \\
\text{user}_3 & 4 & - & -  \\
\text{user}_4 & - & - & 2\smash[t]{\vphantom{\Big|}}\\
\end{block}
\end{blockarray}
\]


\[
\begin{blockarray}{llccc}
 & & \multicolumn{3}{c}{Books} \\
 & & \text{book}_1 & \text{book}_2 & \text{book}_3  \\
\begin{block}{ll(ccc)}
\parbox[t]{2mm}{\multirow{4}{*}{\rotatebox[origin=c]{90}{Rating}}} & \text{user}_1 & - & 1 & -  \smash[b]{\vphantom{\Big|}}\\
 & \text{user}_2 & - & 5 & -  \\
 & \text{user}_3 & 4 & - & -  \\
 & \text{user}_4 & - & - & 2\smash[t]{\vphantom{\Big|}}\\
\end{block}
\end{blockarray}
\]


\end{document}
  • Both look great. It’s gonna be hard to choose between them! – user192311 Jul 6 at 9:56

Your Answer

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