表格中的水平和垂直对齐

表格中的水平和垂直对齐

我将创建一个具有中心对齐(水平和垂直)的表格。我用“规则”实现了它。不幸的是,第一列对此没有反应。

我的代码:

\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}

这是我的问题的图片:

在此处输入图片描述

答案1

您可以使用makecellcollcell

\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}

命令\CELL在使用表之前应该先获得定义。如果所有单元格的长度相同,则可以将定义放在前言中;\renewcommand当然,也可以在本地使用。

在此处输入图片描述

答案2

我不认为使用rules 是一个干净的解决方案,您可以通过发出例如 来增加行高\renewcommand{\arraystretch}{1.2}。我只包含了代码的相关部分,因为您的大多数代码似乎与问题无关。

\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}

在此处输入图片描述

相关内容