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

1 Answers1

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}
leandriis
  • 62,593