Tabular - Zelleneinträge vertikal und horizontal zentrieren

Antwort erstellen


Diese Frage dient dazu, das automatisierte Versenden von Formularen durch Spam-Bots zu verhindern.
Smilies
:D :) :( :o :shock: :? 8) :lol: :-x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen:

BBCode ist eingeschaltet
[img] ist eingeschaltet
[flash] ist ausgeschaltet
[url] ist eingeschaltet
Smilies sind eingeschaltet

Die letzten Beiträge des Themas

Ich habe die Datenschutzerklärung gelesen und bin damit einverstanden.

   

Wenn du eine Datei oder mehrere Dateien anhängen möchtest, gib die Details unten ein.

Ansicht erweitern Die letzten Beiträge des Themas: Tabular - Zelleneinträge vertikal und horizontal zentrieren

Vielen Dank, dein Beispiel funktioniert bei mir leider nicht

von Manu3790 » Do 10. Mai 2018, 18:28

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!

von Bartman » Di 8. Mai 2018, 16:44

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}

Tabular - Zelleneinträge vertikal und horizontal zentrieren

von Manu3790 » Di 8. Mai 2018, 08:58

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}

Nach oben