表格中的水平和垂直對齊

表格中的水平和垂直對齊

我將建立一個具有中心對齊方式(水平和垂直)的表格。我用“規則”來實現它。不幸的是,第一欄對此沒有反應。

我的程式碼:

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

在此輸入影像描述

相關內容