我想通过将单元格居中并将其 \hline 固定在第一行来优化 beamer 中的表格,使其看起来美观。
\documentclass[english]{beamer}
\usetheme{madrid}
\date{Mohcine}
\begin{document}
\begin{frame}{optimized the following table}
\begin{block}{~\vspace{0.7cm}}
\begin{center}
\vspace{-0.8cm}
\begin{tabular}{p{0.45\textwidth}|p{0.45\textwidth}}
\textcolor{white}{\bf discriminant $\Delta=b^{2}-4ac$} & \textcolor{white}{\bf set of roots} \\\midskip\hline
$\Delta >0$ & $S=\left\{ \dfrac{-b+\sqrt{\Delta}}{2a},\dfrac{-b-\sqrt{\Delta}}{2a} \right\}$\\ \hline
$\Delta=0$ & $S=\left\{ \dfrac{-b}{2a} \right\}$ \\ \hline
$\Delta<0$ & $S=\emptyset$ \\
\end{tabular}
\end{center}
\end{block}
\end{frame}
\end{document}
答案1
\setcellgapes
我建议使用 的命令对单元格进行垂直居中,从而进行改进makecell
,该命令会在单元格的顶部和底部添加固定的垂直空间。与间距问题无关:我用\emptyset
更美观的 替换了我不喜欢的\varnothing
。
\documentclass[english]{beamer}
\usetheme{madrid}
\date{Mohcine}
\usepackage{makecell}
\begin{document}
\begin{frame}{optimized the following table}
\begin{block}{~\vspace{0.7cm}}
\begin{center}
\vspace{-0.8cm}
\setcellgapes{4pt}\makegapedcells
\begin{tabular}{>{\centering}p{0.45\textwidth}|>{\centering\arraybackslash}p{0.45\textwidth}}
\textcolor{white}{\bfseries\boldmath discriminant $\Delta=b^{2}-4ac$} & \textcolor{white}{\bfseries set of roots} \\
$\Delta >0$ & $S=\left\{ \dfrac{-b+\sqrt{\Delta}}{2a},\dfrac{-b-\sqrt{\Delta}}{2a} \right\}$\\ \hline
$\Delta=0$ & $S=\left\{ \dfrac{-b}{2a} \right\}$ \\ \hline
$\Delta<0$ & $S=\varnothing$
\end{tabular}
\end{center}
\end{block}
\end{frame}
\end{document}
答案2
我将使用\renewcommand{\arraystretch}{1.6}
,我将把马德里这个名称与马德里以及的价值固定在一起\vspace
。
\documentclass[english]{beamer}
\usetheme{Madrid}
\date{Mohcine}
\renewcommand{\arraystretch}{2}
\usepackage{array}
\begin{document}
\begin{frame}{optimized the following table}
\begin{block}{~\vspace{0.8cm}}
\begin{center}
\vspace{-1.13cm}
\begin{tabular}{>{\centering\arraybackslash}p{0.45\textwidth}|>{\centering\arraybackslash}p{0.45\textwidth}}
\textcolor{white}{\bf discriminant $\Delta=b^{2}-4ac$} & \textcolor{white}{\bf set of roots} \\[1ex]\hline
$\Delta >0$ & $S=\left\{ \dfrac{-b+\sqrt{\Delta}}{2a},\dfrac{-b-\sqrt{\Delta}}{2a} \right\}$\\ \hline
$\Delta=0$ & $S=\left\{ -\dfrac{b}{2a} \right\}$ \\ \hline
$\Delta<0$ & $S=\emptyset$ \\
\end{tabular}
\end{center}
\end{block}
\end{frame}
\end{document}
答案3
使用该tcolorbox
包:
\documentclass[xcolor={dvipsnames,svgnames,table}]{beamer}
\usetheme{Madrid}
\date{Mohcine}
\usepackage{amssymb}
\usepackage{cellspace,tabularx}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\addparagraphcolumntypes{C}
\usepackage[many]{tcolorbox}
\newtcolorbox{tctabularx}[1]{%
enhanced,
fonttitle=\sffamily\bfseries, fontupper=\small\sffamily,
colback=blue!10, colframe=blue,
#1,
before upper app={\rowcolor{blue!60}},
}% end tctabularx
\begin{document}
\begin{frame}
\centering
\frametitle{Optimized the following table}
\tcbset{width=0.85\linewidth}
\begin{tctabularx}{tabularx={C|SC}}
\textcolor{white}{\textbf{discriminant} $\Delta=b^{2}-4ac$}
& \textcolor{white}{\textbf{set of roots}} \\
$\Delta>0$ & %\smallskip
$S=\left\{ \dfrac{-b+\sqrt{\Delta}}{2a},\dfrac{-b-\sqrt{\Delta}}{2a} \right\}$
%\smallskip
\\ \hline
$\Delta=0$ & $S=\left\{ \dfrac{-b}{2a} \right\}$ \\ \hline
$\Delta<0$ & $S=\varnothing$ \\
\end{tctabularx}
\end{frame}
\end{document}