9

Following example:

\usepackage{multirow}

\begin{tabular}{cc|c|c|c|c|c|}
\cline{3-7}
& & \multicolumn{5}{c|}{something} \\ \cline{3-7}
& & AAA & BBB & CCC & DDD & EEE\\ \hline
\multicolumn{1}{|c|}{\multirow{3}{*}{\rotatebox[origin=c]{90}{sth}} } 
& line 1 & x & x & x & x & x \\ \cline{2-7}
& line 2 & x & x & x & x & x \\ \cline{2-7}
\end{tabular}
  1. Why is the border on the left side missing?

enter image description here

  1. Why can I not make the columns fixed width (like c{4cm})? this gives me an error message ' Illegal pream-token (2.0cm): `c' used.' but I am pretty sure it has worked for me like this...
2
  • Does each column have to be 4cm wide?
    – Bernard
    May 22 '15 at 10:54
  • The 5 right columns should be equally wide to fill the page width. May 22 '15 at 11:21
7

Here is a solution. I took the opportunity to improve the vertical padding of cells, and defined a \nocell command to have a number of empty cells; its argument is the number of consecutive empty cells.

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{multirow}
\usepackage{array, makecell, rotating}
\setcellgapes{2pt}
\newcommand\nocell[1]{\multicolumn{#1}{c|}{}}

\begin{document}

\makegapedcells
\begin{tabular}{|c*{6}{|p{2cm}}|}
  \cline{3-7}
  \nocell{2}& \multicolumn{5}{c|}{something} \\ \cline{3-7}
  \nocell{2} & AAA & BBB & CCC & DDD & EEE\\ \hline
  \multirowcell{2}[0.5ex]{\rotatebox[origin=c]{90}{sth}} & line 1 & x & x & x & x & x \\ \cline{2-7}
 & line 2 & x & x & x & x & x \\ \cline{1-7}
\end{tabular}

\end{document}  

enter image description here

2
  • Thanks, especially the new command is useful. However, do you maybe also have an idea what is wrong with my example, since it really puzzles me? May 26 '15 at 10:23
  • 3
    Yes: it seems to be the \multicolumn{…} command which makes latex think there's only one row. If at the beginning of the last line, you add an empty cell via \multicolumn{1}{|c|}{} as a workaround, you'll get a full vertical line. Btw, I've just added a small correction to \multirow{cell} for a better centring of the rotated text.
    – Bernard
    May 26 '15 at 10:37
0

You can easily draw such table with {NiceTabular} of nicematrix. In that environment, you use \Block to merge cells (both horizontally and vertically) and you use hvlines-except-corners=NW to draw all the rules excepted in the blocks and in the corner NW.

\documentclass{article}

\usepackage{nicematrix}

\begin{document}
\setlength{\extrarowheight}{2pt}
\begin{NiceTabular}{ccccccc}[hvlines-except-corners=NW]
& & \Block{1-5}{something} \\ 
& & AAA & BBB & CCC & DDD & EEE\\ 
\Block{2-1}<\rotate>{sth}
& line 1 & x & x & x & x & x \\ 
& line 2 & x & x & x & x & x \\ 
\end{NiceTabular}
\end{document}

You need several compilations (because nicematrix uses PGF/Tikz).

Output of the above code

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.