Tabular - Zelleneinträge vertikal und horizontal zentrieren

Tabellen und Grafiken erstellen und anordnen


Manu3790
Forum-Anfänger
Forum-Anfänger
Beiträge: 49
Registriert: Mi 6. Jul 2016, 14:00

Tabular - Zelleneinträge vertikal und horizontal zentrieren

Beitrag von Manu3790 »

Hallo Leute,

weiß jemand wie man innerhalb einer Zelle, den Text vertikal sowie horizontal mittig ausrichten kann?

Vertikal bekomme ich hin, in dem man auf die Spalte auf center einstellt.

Aber wie bekomme ich die horizontale, mittige Ausrichtung hin?

Durch das Einfärben wird es offensichtlich, dass der Text nicht mittig steht.

Vielen Dank für eure Hilfe!

Anbei ein Minimalbeispiel:
\documentclass[%
12pt,
ngerman,   
a4paper,
]{scrbook}

\usepackage{tabularx}
\usepackage{array}
\usepackage{booktabs} % nicer tables
\usepackage{rotating}
\newcommand\tabrotate[1]{\begin{turn}{90}\rlap{#1}\end{turn}}
\usepackage{varwidth}
\newcommand\tabvarwidth[2][3cm]{\begin{varwidth}[b]{#1}\centering #2\end{varwidth}}
\usepackage{colortbl}


\begin{document}
\begin{tabular}{lc|cccccccccc|cc}
	
\\
\\
\\
\\
\\
\\
		&&
		
	\tabrotate{z}&
	\tabrotate{z}&
		\tabrotate{z}&
			\tabrotate{z}&
				\tabrotate{z}&
					\tabrotate{z}&
						\tabrotate{z}&
							\tabrotate{z}&
								\tabrotate{z}&
									\tabrotate{z} &  &  \\
	

	\bfseries u && 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & \bfseries{$\sum$} & \bfseries x\\

	\midrule
	x & 1 & \cellcolor{blue}1 & 0 & 2 & 2 & 0 & 2 & 2 & 2 & 0 & 2 & 13 & 13\\
	x & 2 & 2 & \cellcolor{blue}1 & 2 & 2 & 0 & 1 & 2 & 2 & 2 & 2 & 16 & 16\\
	x & 3 & 0 & 0 & \cellcolor{blue}1 & 2 & 0 & 1 & 1 & 2 & 0 & 2 & 9 & 9\\
	x & 4 & 0 & 0 & 0 & \cellcolor{blue}1 & 0 & 0 & 0 & 2 & 0 & 0 & 3 & 3\\
	x & 5 & 2 & 2 & 2 & 2 & \cellcolor{blue}1 & 2 & 2 & 2 & 2 & 2 & 19 & 19\\
	x & 6 & 0 & 1 & 1 & 2 & 0 & \cellcolor{blue}1 & 2 & 2 & 0 & 2 & 11 & 11\\
	x & 7 & 0 & 0 & 1 & 2 & 0 & 0 & \cellcolor{blue}1 & 2 & 0 & 0 & 6 & 6\\
	x & 8 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \cellcolor{blue}1 & 0 & 0 & 1 & 1\\
	x & 9 & 2 & 0 & 2 & 2 & 0 & 2 & 2 & 2 & \cellcolor{blue}1 & 2 & 15 & 15\\
	x & 10 & 0 & 0 & 0 & 2 & 0 & 0 & 2 & 2 & 0 & \cellcolor{blue}1 & 7 & 7\\
	\midrule
	&  &  &  &  &  &  &  &  &  &  &  &  & \\
\end{tabular}
\end{document}

Bartman
Forum-Meister
Forum-Meister
Beiträge: 2456
Registriert: Do 16. Jul 2009, 21:41
Wohnort: Hessische Provinz

Beitrag von Bartman »

In Deinem und in meinem alternativen Beispiel wird der Text horizontal zentriert ausgerichtet.
\documentclass[border=5pt]{standalone}

%\usepackage{tabularx}% lädt array
\usepackage{array}
\usepackage{booktabs} % nicer tables
\usepackage{rotating}
\usepackage{amsmath}
%\usepackage{varwidth}
\usepackage[table]{xcolor}% Ersatz für das Laden von colortbl
\usepackage{bm}

\newcommand\tabrotate[1]{\begin{turn}{90}\rlap{#1}\end{turn}}
%\newcommand\tabvarwidth[2][3cm]{\begin{varwidth}[b]{#1}\centering #2\end{varwidth}}

\begin{document}
\begin{tabular}{l*{13}c}
\toprule
&&
\tabrotate{z}&
\tabrotate{z}&
\tabrotate{z}&
\tabrotate{z}&
\tabrotate{z}&
\tabrotate{z}&
\tabrotate{z}&
\tabrotate{z}&
\tabrotate{z}&
\tabrotate{z}&& \\
   
\bfseries u && 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 &  $\bm{\sum}$ & \bfseries x\\

\cmidrule(lr){1-2}
\cmidrule(lr){3-12}
\cmidrule(lr){13-14}
x & 1 & \cellcolor{blue}1 & 0 & 2 & 2 & 0 & 2 & 2 & 2 & 0 & 2 & 13 & 13\\
x & 2 & 2 & \cellcolor{blue}1 & 2 & 2 & 0 & 1 & 2 & 2 & 2 & 2 & 16 & 16\\
x & 3 & 0 & 0 & \cellcolor{blue}1 & 2 & 0 & 1 & 1 & 2 & 0 & 2 & 9 & 9\\
x & 4 & 0 & 0 & 0 & \cellcolor{blue}1 & 0 & 0 & 0 & 2 & 0 & 0 & 3 & 3\\
x & 5 & 2 & 2 & 2 & 2 & \cellcolor{blue}1 & 2 & 2 & 2 & 2 & 2 & 19 & 19\\
x & 6 & 0 & 1 & 1 & 2 & 0 & \cellcolor{blue}1 & 2 & 2 & 0 & 2 & 11 & 11\\
x & 7 & 0 & 0 & 1 & 2 & 0 & 0 & \cellcolor{blue}1 & 2 & 0 & 0 & 6 & 6\\
x & 8 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \cellcolor{blue}1 & 0 & 0 & 1 & 1\\
x & 9 & 2 & 0 & 2 & 2 & 0 & 2 & 2 & 2 & \cellcolor{blue}1 & 2 & 15 & 15\\
x & 10 & 0 & 0 & 0 & 2 & 0 & 0 & 2 & 2 & 0 & \cellcolor{blue}1 & 7 & 7\\
\bottomrule
\end{tabular}
\end{document}

Manu3790
Forum-Anfänger
Forum-Anfänger
Beiträge: 49
Registriert: Mi 6. Jul 2016, 14:00

Vielen Dank, dein Beispiel funktioniert bei mir leider nicht

Beitrag von Manu3790 »

Hallo Bartman,

danke für deine Mühe.

Dein Beispiel funktioniert bei mir jedoch leider auch nicht wie gewünscht. Die Zahl 1 steht immer noch nicht mittig in der Zelle (horizontal gesehen)...

Viele Grüße!

Antworten