2

I am trying to make a table where the column label is rotated 90 degrees, I found some code online (see below) and almost got where I wanted. However the lines are not running up completely so column labels are not well separated, also some table "walls" are missing, I would like to fix this issues. Please note there should be a big blank cell (i.e. no walls) in the upper-left side of the table. Any help is very much appreciated.

\documentclass[12pt]{article}
\usepackage{answers}
\usepackage{multicol}
\usepackage{adjustbox}
\usepackage[table,x11names]{xcolor}
\usepackage{float}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\usepackage{array}
\newcolumntype{?}{!{\vrule width 2pt}}
\usepackage[spanish, es-tabla]{babel}
\makeatletter
\renewcommand{\@seccntformat}[1]{}
\makeatother
\setlength\parindent{24pt}

\newcolumntype{R}[2]{%
    >{\adjustbox{angle=#1,lap=\width-(#2)}\bgroup}%
    l%
    <{\egroup}%
}
\newcommand*\rot{\multicolumn{1}{R{90}{1em}}}% no optional argument here, please!
 
\begin{document}
 

\begin{tabular}{r|c|c|c|c|c|}
& \rot{Hello} & 
\rot{Hello} &
\rot{Hello} &
\rot{Hello} &
\rot{Hello} \\
\hline
Hello   & 0 & 0 & 0 & 0 & 0 \\
\hline
Hello   & 0 & 0 & 0 & 0 & 0 \\
\hline
Hello   & 0 & 0 & 0 & 0 & 0 \\ 
\hline
Hello   & 0 & 0 & 0 & 0 & 0 \\
\hline
Hello   & 0 & 0 & 0 & 0 & 0 \\ 
\hline
\end{tabular}


\end{document}

enter image description here

3
  • R{90}{1em}| would put the | back Nov 28, 2022 at 19:40
  • Try this definition: of \rot: \newcommand*\rot[2][90]{\adjustbox{rotate=#1}{#2}}. The first argument between [] is optional and = 90 by default, and the second argument is mandatory, e.g. \rot[45]{Hello}. If it's working, remove the definition of R{}.
    – Celdor
    Nov 28, 2022 at 20:11
  • Please see the updated answer, now including the requested lines. Nov 28, 2022 at 21:28

1 Answer 1

4

This is a simpler approach (with package rotating).

\documentclass[12pt]{article}

\usepackage{rotating}
\newcommand{\rot}[1]{\begin{turn}{90}#1\enspace\end{turn}}
\newcommand{\mr}[1]{\multicolumn{1}{|c|}{#1}}

\begin{document}    
    
    \begin{tabular}{r|c|c|c|c|c|}
        \cline{2-6}
        & \rot{Hello} & 
        \rot{Hello} &
        \rot{Hello} &
        \rot{Hello} &
        \rot{Hello} \\
        \hline
        \mr{Hello}   & 0 & 0 & 0 & 0 & 0 \\
        \hline
        \mr{Hello}   & 0 & 0 & 0 & 0 & 0 \\
        \hline
        \mr{Hello}   & 0 & 0 & 0 & 0 & 0 \\ 
        \hline
        \mr{Hello}   & 0 & 0 & 0 & 0 & 0 \\
        \hline
        \mr{Hello}   & 0 & 0 & 0 & 0 & 0 \\ 
        \hline
    \end{tabular}   
\end{document}

b

2
  • Hello, thanks for your answer, is an improvement but it still has some issues I would like to fix. Every cell that contains the word "Hello" should be completely closed, so the upper wall and left wall are missing. Is there an easy way to fix this? Nov 28, 2022 at 19:51
  • 1
    @Miguel Garcia Please see the updated answer Nov 28, 2022 at 20:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .