Alinhamento horizontal e vertical na tabela

Alinhamento horizontal e vertical na tabela

Eu criaria uma tabela com alinhamento central (horizontal e vertical). Eu percebi isso com "regra". Infelizmente, a primeira coluna não reage a isso.

Meu código:

\documentclass[hyperref={pdfpagelabels=false}]{beamer}
% Die Hyperref Option hyperref={pdfpagelabels=false} verhindert die Warnung: Package hyperref Warning: Option `pdfpagelabels' is turned off (hyperref) because \thepage is undefined. Hyperref stopped early
\usetheme{CambridgeUS}
\usepackage{lmodern}
% lmodern (= Latin Modern) Paket verändert die verwendete Schriftart. Der Hauptunterschied ist die Darstellung der Schrift innerhalb von pdf Dateien. Latin Modern ist um einiges flüßiger.
\usepackage{beamerthemeshadow}
\usepackage[ngerman]{babel}
\usepackage{array}
\usepackage{eurosym}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgf,tikz}
\usepackage{booktabs}
\usepackage{slashbox,pict2e}
\usetikzlibrary{arrows,positioning,fit}
\usetikzlibrary{shadows}
\definecolor{UniHHred}{RGB}{226,0,26}
\usefonttheme{professionalfonts} % default family is serif
\setbeamercolor{frametitle}{fg=black,bg=UniHHred}
\setbeamerfont{frametitle}{size=\large}
\setbeamertemplate{frametitle}{\color{black}\bfseries\insertframetitle\par\vskip-6pt\hrulefill}
\setbeamercolor{block title}{series=\bfseries,size=\huge,fg=black,bg=UniHHred}
\setbeamercolor{block body}{bg=gray!20!bg}
\setbeamercolor{itemize item}{fg=black}
\setbeamercolor{itemize subitem}{fg=black}
\setbeamercolor{title}{fg=black,bg=UniHHred}
\setbeamercolor{section in head/foot}{fg=black, bg=UniHHred}

\makeatother
\setbeamertemplate{footline}
{
  \leavevmode%
  \hbox{%
  \begin{beamercolorbox}[wd=.25\paperwidth,ht=2.25ex,dp=1ex,center]{section in head/foot}%
    \usebeamerfont{author in head/foot}\insertshortauthor
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,center]{section in head/foot}%
    \usebeamerfont{title in head/foot}\insertshorttitle
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.25\paperwidth,ht=2.25ex,dp=1ex,center]{section in head/foot}%
    \insertdate \qquad \insertframenumber{} / \inserttotalframenumber\hspace*{1ex}
  \end{beamercolorbox}}%
  \vskip0pt%
}
\makeatletter

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{headline}{}

\addtobeamertemplate{block begin}{%
  \setlength{\textwidth}{0.9\textwidth}%
}{}
\usetikzlibrary{arrows,positioning} 
\usetikzlibrary{calc}
\usetikzlibrary{shapes,snakes}

\newcommand*\xbar[1]{%
  \hbox{%
    \vbox{%
      \hrule height 0.5pt % The actual bar
      \kern0.5ex%         % Distance between bar and symbol
      \hbox{%
        \kern-0.1em%      % Shortening on the left side
        \ensuremath{#1}%
        \kern-0.1em%      % Shortening on the right side
      }%
    }%
  }%
} 

\makeatletter
\g@addto@macro\normalsize{%  <----
  \setlength\abovedisplayskip{0pt}%  <----
  \setlength\belowdisplayskip{10pt}%  <----
  \setlength\abovedisplayshortskip{0pt}%  <----
  \setlength\belowdisplayshortskip{20pt}%  <----
}

\makeatother
\tikzset{
    declare function={
        normcdf(\x,\m,\s)=1/(1 + exp(-0.07056*((\x-\m)/\s)^3 - 1.5976*(\x-\m)/\s));
    }
}

\usepackage{tabularx}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}} % linksbündig mit Breitenangabe
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}} % zentriert mit Breitenangabe
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}} % rechtsbündig mit Breitenangabe

\usepackage[framemethod=TikZ]{mdframed}

\newcounter{form}[section]\setcounter{form}{0}
\renewcommand{\theform}{\arabic{section}.\arabic{form}}
\newenvironment{form}[2][]{%
\refstepcounter{form}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=blue!40]
{\strut Formel/Erläuterung};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=blue!40]
{\strut Formel/Erläuterung:~#1};}}%
}%
\mdfsetup{innertopmargin=5pt,innerbottommargin=15pt,linecolor=blue!40,%
linewidth=2pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}
\begin{mdframed}[]\relax%
\label{#2}}{\end{mdframed}}

\begin{document}
\begin{center}\begin{tabular}{|*{5}{C{1cm}|}}\hline
\rule{0pt}{12pt} $z_i$    & $-\frac{130}{81}$    & $-\frac{10}{27}$   &  $\frac{70}{81}$   & $\frac{170}{81}$   \\\hline
\rule{0pt}{12pt} $f(z_i)$ & $0,2$ & $0,4$ & $0,3$ & $0,1$  \\\hline
\end{tabular}
\end{center}
\end{document}

Aqui está uma foto do meu problema:

insira a descrição da imagem aqui

Responder1

Você pode usar makecelle collcell:

\documentclass{article}
\usepackage{array,makecell,collcell}

\newcolumntype{C}{>{\collectcell\CELL}c<{\endcollectcell}}

\begin{document}

\begin{center}
\makegapedcells\setcellgapes{5pt}
\newcommand\CELL[1]{\makebox[1cm]{#1}}
\begin{tabular}{|*{5}{C|}}
\hline
$z_i$    & $-\frac{130}{81}$    & $-\frac{10}{27}$   &
  $\frac{70}{81}$   & $\frac{170}{81}$   \\\hline
$f(z_i)$ & $0{,}2$ & $0{,}4$ & $0{,}3$ & $0{,}1$  \\\hline
\end{tabular}
\end{center}

\end{document}

O \CELLcomando deve obter uma definição antes de usar a tabela. Você pode colocar a definição no preâmbulo, se todas as suas células compartilharem o comprimento; você pode usar localmente \renewcommand, é claro.

insira a descrição da imagem aqui

Responder2

Não acho que usar rules seja uma solução limpa, você pode aumentar a altura das linhas emitindo, por exemplo, \renewcommand{\arraystretch}{1.2}. Incluí apenas as partes relevantes do código porque a maior parte do seu código não parece estar relacionada ao problema.

\documentclass[hyperref={pdfpagelabels=false}]{beamer}
\usefonttheme{professionalfonts} % default family is serif
\usepackage{array,lmodern}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}

\begin{frame}
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{|*{5}{C{1cm}|}}\hline
$z_i^{}$ & $-\frac{130}{81}$ & $-\frac{10}{27}$ & $\frac{70}{81}$  & $\frac{170}{81}$ \\ \hline
$f(z_i)$ & $0,2$ & $0,4$ & $0,3$ & $0,1$ \\ \hline
\end{tabular}
\end{frame}

\end{document}

insira a descrição da imagem aqui

informação relacionada