1

I want to create a table that looks like this:

enter image description here

So this is what I already got:

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{graphicx}


\begin{document}
\begin{table}[H]
    \centering

    \begin{footnotesize}    
    \begin{tabular}{p{0.5cm}p{3cm}p{1.5cm}p{1.5cm}p{1.5cm}p{1.5cm}p{1.5cm}}
        \toprule
          \multicolumn{2}{c}{}
        & \textbf{A}
        & \textbf{B}
        & \textbf{C}
        & \textbf{D}
        & \textbf{E} \\
        \midrule
        \midrule
        \multirow{2}{*}{\rotatebox{90}{Texttexttext}}
        & 1 & 2 & 3 & 4 \\
        & 2 & 3 & 4 & 5\\
        \bottomrule
    \end{tabular}
    \end{footnotesize}

    \caption{Übersicht über die verfügbaren Trainings- und Testdaten}
    \label{tab:6_tabelle}
\end{table}
\end{document}

The problem now is that I

  1. want to have the rows sizes relative to the height of the first cell
  2. all cells should have a vertical alignment
  3. cells for A, B and C should have a horizontal alignment

Can anyone give me some hints?

Greets!

2
  • You first requirement is not quite clear to me. What are ‘sizes relative to the height of the first cell’?
    – Bernard
    Nov 6, 2015 at 13:58
  • When you compile my code of above then Texttexttext doesnt fit the size of the table. Moreover the table doesnt grow according to the largest cell. Nov 6, 2015 at 14:43

2 Answers 2

1

You can try this (using pdftex):

\newdimen\tstrutdim
\def\tstrut{\lower.3\tstrutdim\vbox to\tstrutdim{}}
\def\crl{\cr\noalign{\hrule}}
\def\rotitem#1{\noalign{\setbox0=\hbox{ #1 }\global\tstrutdim=.5\wd0}
  \ \pdfsave\pdfsetmatrix{0 1 -1 0}\llap{ #1 \kern-.7\tstrutdim}\pdfrestore
}
\vbox{\offinterlineskip \tstrutdim=16pt
\halign{\vrule\quad\hfil#\unskip\hfil\quad\vrule&&%
        \tstrut\quad\hfil#\unskip\hfil\quad\vrule
        \span\crl
 \omit\vrule &        &  A  &  B  &  C  \crl \rotitem{text text text}
             &  X     & 12  & 11  &  1  \cr
             & \multispan4\hrulefill    \cr
             &  Y     &  3  &  5  &  4  \crl
}}
1

Here are two possibilities, usng the makecell package, which allows line breaks for the \rotcell command:

\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{booktabs}
\usepackage{array, multirow}
\usepackage{rotating, graphicx}
\usepackage{makecell}
\setcellgapes{4pt}

\begin{document}

\begin{table}[!h]
    \centering
    \footnotesize\settowidth\rotheadsize{Texttexttext}
\makegapedcells
    \footnotesize
    \begin{tabular}{p{0.5cm}p{3cm}*{5}{p{1.5cm}}}
        \toprule
          \multicolumn{2}{c}{}
        & \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} & \textbf{E} \\
        \midrule
        \midrule
        & 1 & 2 & 3 & 4 \\[4.5ex]
         \multirow{-2}{*}[7.5ex]{\rotatebox{90}{Texttexttext}}
         & 2 & 3 & 4 & 5\\
        \bottomrule
    \end{tabular}
    \caption{Übersicht über die verfügbaren Trainings- und Testdaten}
    \label{tab:6_tabelle}
\end{table}

\begin{table}[!h]
    \centering
    \footnotesize\settowidth\rotheadsize{Text text}
\renewcommand\cellalign{rt}
\makegapedcells
    \footnotesize
    \begin{tabular}{ >{\raggedleft}p{0.5cm}p{3cm}*{5}{p{1.5cm}}}
        \toprule
          \multicolumn{2}{c}{}
        & \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} & \textbf{E} \\
        \midrule
        \midrule
        & 1 & 2 & 3 & 4 \\[2ex]
         \multirowcell{-2}[2.5ex]{\hspace{4ex}\rotcell[c]{\\Text text\\text}}
         & 2 & 3 & 4 & 5\\%[-3ex]
        \bottomrule
    \end{tabular}
    \caption{Übersicht über die verfügbaren Trainings- und Testdaten}
    \label{tab:6_tabelleA}
\end{table}

\end{document} 

enter image description here

2
  • In Table 2, how can we vertically align the "text text text" text of the first column to be centered?
    – Urko
    May 19, 2016 at 6:17
  • 1
    @Urko: I had forgotten this point. Just add [c] as an optional argument to \rotcell. Please see my updated answer.
    – Bernard
    May 19, 2016 at 8:45

You must log in to answer this question.

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