Here is a solution to your problem using the tabularray
package. The SetCell
macro is the equivalent of both the multicolumn
and the multirow
, in the optional argument r
is for the no of rows to be included (c
is for columns). The hlines
and vlines
option tells to set horizontal and vertical lines around every cell and they automatically take care of multirow and multicolumn (if there is any). The X
column type is equivalent to the tabularx
X
column where the optional value sets the horizontal and vertical alignment of the column respectively and the numbered optional value sets the relative width of the column with respect to default width.
\documentclass[11pt,a4paper]{article}
\usepackage{tabularray}
\begin{document}
\begin{table}[h]
\begin{tblr}{
hlines, vlines,
colspec={*{3}{X[c,m]} X[2.5,c,m]},
}
Zeitpunkt &
Variable &
Datentyp & Beschreibung
\\
\SetCell[r=7]{c}t0, t1, t2
&
Alter &
Numerisch &
Alter eines Studenten in Jahren
\\
&
Geschlecht &
Nominal &
Geschlecht eines Studenten
\\
&
HzbArt &
Nominal &
Art der HZB
\\
&
HzbNote &
Numerisch &
Notendurchschnitt der HZB
\\
&
Ang\_Abschluss &
Nominal &
Bachelor oder Master
\\
&
Studiengang &
Nominal &
Studiengang eines Studenten
\\
& Bildungsland
& Nominal
& Bildungsinländer oder Bildungsausländer
\\
\SetCell[r=2]{c} t1, t2
&
DN\_Sem\_1 &
Numerisch &
Notendurchschnitt nach dem ersten Semester
\\
&
NB\_Pruef\_ Sem\_1 &
Numerisch &
Anzahl der nicht bestandenen Prüfungen nach dem ersten Semester
\\
\SetCell[r=2]{c}t2
&
DN\_Sem\_2 &
Numerisch &
Notendurchschnitt nach dem zweiten Semester
\\
&
NB\_Pruef\_ Sem\_2 &
Numerisch &
Anzahl der nicht bestandenen Prüfungen nach dem zweiten Semester
\\
t0, t1, t2 &
Abbrecher &
Nominal &
Studienabbrecher oder Nicht-Studienabbrecher
\\
\end{tblr}%
\end{table}
\end{document}
However, I will recommend you to get rid of all the vertical lines and most of the horizontal line to give the table a more professional look.
Addendum:
Here is a somewhat better looking (to me) version of the table. I think the left alignment of the 2nd, 3rd and 4th columns (with centered header) looks better.
\documentclass[11pt,a4paper]{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs} %allows to use the booktabs rules in the tblr environment.
\begin{document}
\begin{table}[h]
\begin{tblr}{
stretch=1.5, %adds extra vertical space (1.5 times of default) around the row
colspec={X[c,m] *{2}{X[l,m]} X[2.5,l,m]},
row{1} = {halign=c} %aligns the content of the first row horizontally
}
\toprule
Zeitpunkt &
Variable &
Datentyp & Beschreibung
\\
\midrule
\SetCell[r=7]{c}t0, t1, t2
&
Alter &
Numerisch &
Alter eines Studenten in Jahren
\\
&
Geschlecht &
Nominal &
Geschlecht eines Studenten
\\
&
HzbArt &
Nominal &
Art der HZB
\\
&
HzbNote &
Numerisch &
Notendurchschnitt der HZB
\\
&
Ang\_Abschluss &
Nominal &
Bachelor oder Master
\\
&
Studiengang &
Nominal &
Studiengang eines Studenten
\\
& Bildungsland
& Nominal
& Bildungsinländer oder Bildungsausländer
\\
\midrule
\SetCell[r=2]{c} t1, t2
&
DN\_Sem\_1 &
Numerisch &
Notendurchschnitt nach dem ersten Semester
\\
&
NB\_Pruef\_ Sem\_1 &
Numerisch &
Anzahl der nicht bestandenen Prüfungen nach dem ersten Semester
\\
\midrule
\SetCell[r=2]{c}t2
&
DN\_Sem\_2 &
Numerisch &
Notendurchschnitt nach dem zweiten Semester
\\
&
NB\_Pruef\_ Sem\_2 &
Numerisch &
Anzahl der nicht bestandenen Prüfungen nach dem zweiten Semester
\\
\midrule
t0, t1, t2 &
Abbrecher &
Nominal &
Studienabbrecher oder Nicht-Studienabbrecher
\\
\bottomrule
\end{tblr}%
\end{table}
\end{document}
Addendum 2: Without using tabularray
, it's also possible to center the multirow cells. As I commented, to center vertically, you will need to manually tweak the no of rows (first) argument. And to center the multirow contents horizontally, you can insert it in a multicolumn
command.
\documentclass[11pt,a4paper]{article}
\usepackage{array}
\usepackage{multirow}
\usepackage{ragged2e}
\usepackage{calc}
\usepackage{booktabs}
\newcolumntype{M}[1]{>{\RaggedRight}m{#1}}
\begin{document}
\begin{table}[h]
\renewcommand{\arraystretch}{1.5}
\begin{tabular}
{M{0.16\textwidth-2\tabcolsep - 1.25\arrayrulewidth}
M{0.24\textwidth-2\tabcolsep - 1.25\arrayrulewidth}
M{0.18\textwidth-2\tabcolsep - 1.25\arrayrulewidth}
M{0.44\textwidth-2\tabcolsep - 1.25\arrayrulewidth}}
\toprule
\multicolumn{1}{c}{Zeitpunkt} &
\multicolumn{1}{c}{Variable} &
\multicolumn{1}{c}{Datentyp} &
\multicolumn{1}{c}{Beschreibung}
\\\midrule
\multicolumn{1}{c}{\multirow{8}{*}{t0, t1, t2}}
&
Alter &
Numerisch &
Alter eines Studenten in Jahren
\\
&
Geschlecht &
Nominal &
Geschlecht eines Studenten
\\
&
HzbArt &
Nominal &
Art der HZB
\\
&
HzbNote &
Numerisch &
Notendurchschnitt der HZB
\\
&
Ang\_Abschluss &
Nominal &
Bachelor oder Master
\\
&
Studiengang &
Nominal &
Studiengang eines Studenten
\\
& Bildungsland
& Nominal
& Bildungsinländer oder Bildungsausländer
\\
\midrule
\multicolumn{1}{c}{\multirow{3.3}{*}{t1, t2}}
&
DN\_Sem\_1 &
Numerisch &
Notendurchschnitt nach dem ersten Semester
\\
&
NB\_Pruef\_ Sem\_1 &
Numerisch &
Anzahl der nicht bestandenen Prüfungen nach dem ersten Semester
\\
\midrule
\multicolumn{1}{c}{\multirow{3.3}{*}{t2}}
&
DN\_Sem\_2 &
Numerisch &
Notendurchschnitt nach dem zweiten Semester
\\
&
NB\_Pruef\_ Sem\_2 &
Numerisch &
Anzahl der nicht bestandenen Prüfungen nach dem zweiten Semester
\\
\midrule
t0, t1, t2 &
Abbrecher &
Nominal &
Studienabbrecher oder Nicht-Studienabbrecher
\\
\bottomrule
\end{tabular}%
\end{table}
\end{document}
Best Answer
Your problems stem from the fact that your table, defined with 4 X columns really has none. It suffices to re-define X column type so as to ensure right alignment, and you'll have both a table that looks like what you want, and a simpler code. I also suppressed redundant vertical lines in \multicolumns: