问题:
我一直在准备投影仪演示文稿,现在正处于最后阶段,我想插入一个长表,但不幸的是我找不到解决方案。请指导我。请...
提前致谢........
梅威瑟:
\documentclass[12pt]{beamer}
\usepackage{ragged2e}\justifying
\usepackage{xcolor}
\usepackage{hyperref}
\usetheme{AnnArbor}
%%================================
\usepackage[f]{esvect}
\usecolortheme{beaver}% red color theme
\usefonttheme{professionalfonts} % using non standard fonts for beamer
%%----------------------------------------------------------
\usepackage{makecell, multirow}
\usepackage{siunitx}
\usepackage{etoolbox}
\newrobustcmd\B{\DeclareFontSeriesDefault[rm]{bf}{b}\bfseries}
%%-----------------------------------------------------------
\usepackage[skip=1ex, font=small, labelfont=bf]{caption}
\usefonttheme{serif} % default family is serif
\usepackage{setspace}
\usepackage{lipsum}
\addtobeamertemplate{frametitle}{}{\vspace{-0.4em}} % decrease
\setlength{\parskip}{5pt}
\title[]{\footnotesize{\textbf{My Title}}}
\subtitle{}
\author[]{}
\institute[]{}
\date[]{\textbf{\today}}
%%=================
\begin{document}
\begin{frame}[plain, noframenumbering]
\maketitle
\end{frame}
%%------------------------------------------------------------
\begin{frame}[t]{}
\begin{table}[ht]
\centering
\sisetup{detect-weight,
mode=text}
\setcellgapes{5pt}
\makegapedcells
\caption{My table}
\label{tab:...}
\label{tab:my-table}
\begin{tabular}{|*{5}{S[table-format=1.1]|}
*{2}{S[table-format=-1.11]|}
}
\hline
{\multirow{2.4}{*}{A}} & {\multirow{2.4}{*}{B}} & {\multirow{2.4}{*}{C}} & {\multirow{2.4}{*}{D}} & {\multirow{2.4}{*}{E}} & \multicolumn{2}{c|}{F} \\ \cline{6-7}
& & & & & {G} & {H} \\ \hline
\B 0.2 &\B 0.5 &\B 1 &\B 0.2 &\B 0.5 & -1.8713360906 & -1.7640262021 \\ \hline
\B 0.3 & 0.5 & 1 & 0.2 & 0.5 & -1.9365758323 & -1.7648755545 \\ \hline
\B 0.4 & 0.5 & 1 & 0.2 & 0.5 & -1.9844365775 & -1.7572640364 \\ \hline
0.2 &\B 0.6 & 1 & 0.2 & 0.5 & -1.8893451634 & -1.7769110253 \\ \hline
0.2 &\B 0.7 & 1 & 0.2 & 0.5 & -1.9037201042 & -1.7845630194 \\ \hline
0.2 &\B 0.8 & 1 & 0.2 & 0.5 & -1.9084283289 & -1.78054097011 \\ \hline
0.2 & 0.5 &\B 1.1 & 0.2 & 0.5 & -1.8638586434 & -1.75716821872 \\ \hline
0.2 & 0.5 &\B 1.2 & 0.2 & 0.5 & -1.8563791180 & -1.75030388119 \\ \hline
0.2 & 0.5 &\B 1.3 & 0.2 & 0.5 & -1.8488975550 & -1.74343325690 \\ \hline
0.2 & 0.5 & 1 &\B 0.3 & 0.5 & -1.7816929512 & -1.67995077275 \\ \hline
0.2 & 0.5 & 1 &\B 0.4 & 0.5 & -1.6940695909 & -1.59754625788 \\ \hline
0.2 & 0.5 & 1 &\B 0.5 & 0.5 & -1.60833298231& -1.51669912930 \\ \hline
0.2 & 0.5 & 1 & 0.2 &\B 0.6 & -1.79104380621& -1.69665633242 \\ \hline
0.2 & 0.5 & 1 & 0.2 &\B 0.7 & -1.72028938675& -1.63324789889 \\ \hline
0.2 & 0.5 & 1 & 0.2 &\B 0.8 & -1.66248454886& -1.58021088372 \\ \hline
\end{tabular}
\end{table}
\end{frame}
%%------------------------------------------------------------
\end{document}
答案1
另一个可能的解决方案是使用表包tabularray
。它的使用有一些特殊性,因此是一个新答案。
在列标题中使用tabularray
文本时,如果文本包含字母d
、D
或,e
则E
与规范交互S
并抛出错误。这可以通过两种方式解决:
- 如果表中的数字不包含指数(如 12.34e-6),那么您可以
S
通过选项从列规范中删除这些指数标记input-exponent-markers=
(如下面 MWE 中所使用的) - 另一种方法(更推荐)是将列标题封装在两个花括号中。例如
\SetCell[r=2]{c} {{D}}
或\SetCell[c=2]{c} {{E}}
。
在第一种情况下,MWE 是:
\documentclass[12pt]{beamer}
\usetheme{AnnArbor}
\usecolortheme{beaver}% red color theme
\usefonttheme{professionalfonts} % using non standard fonts for beamer
\usefonttheme{serif} % default family is serif
%----
\setbeamerfont{title page}{size=\small\bfseries}
\setbeamerfont{subtitle}{size=\scriptsize\bfseries}
%----
\setbeamerfont{frametitle}{size=\footnotesize\bfseries}
%----
\setbeamertemplate{caption}[numbered]
\usepackage[font=scriptsize,
labelfont={bf,color=blue}]
{caption}% it is compatible with the last beamer versions
%---------------------------------------------------------------%
\usepackage{ragged2e}\justifying
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\setlength{\parskip}{5pt}
\usepackage{etoolbox}
\newrobustcmd\B{\DeclareFontSeriesDefault[rm]{bf}{b}\bfseries\color{teal}}
\AtBeginEnvironment{table}{\setlength{\parskip}{-5pt}}
%---------------------------------------------------------------%
\usepackage{lipsum}
\title[Presentation title]{Presentation title}
\subtitle{Example of use the \texttt{tabularray} package}
\author[zfc]{Math-Man}
\institute[]{}
\date{\today}
%---------------------------------------------------------------%
\begin{document}
\begin{frame}[plain, noframenumbering]
\maketitle
\end{frame}
%---------------------------------------------------------------%
\section{Result}
\subsection{Simulations}
%---------------------------------------------------------------%
\begin{frame}[t]% no frame title
\begin{table}
\centering
\sisetup{detect-weight,
mode=text,
input-exponent-markers=} % <===
\caption{My table}
\label{tab:tblr}
\footnotesize
\begin{tblr}{hlines, vlines,
colspec={*{5}{ S[table-format=1.1] }
*{2}{ S[table-format=-1.11]} },
colsep=4pt,
abovesep={ 0.5pt}, % <---
belowsep={-0.5pt} % <---
}
\SetCell[r=2]{c} A
& \SetCell[r=2]{c} B
& \SetCell[r=2]{c} C
& \SetCell[r=2]{c} D
& \SetCell[r=2]{c} E
& \SetCell[c=2]{c} F
& \\
& & & & & {{{G}}} & {{{H}}} \\
\B 0.2 &\B 0.5 &\B 1 &\B 0.2 &\B 0.5 & -1.8713360906 & -1.7640262021 \\
\B 0.3 & 0.5 & 1 & 0.2 & 0.5 & -1.9365758323 & -1.7648755545 \\
\B 0.4 & 0.5 & 1 & 0.2 & 0.5 & -1.9844365775 & -1.7572640364 \\
0.2 &\B 0.6 & 1 & 0.2 & 0.5 & -1.8893451634 & -1.7769110253 \\
0.2 &\B 0.7 & 1 & 0.2 & 0.5 & -1.9037201042 & -1.7845630194 \\
0.2 &\B 0.8 & 1 & 0.2 & 0.5 & -1.9084283289 & -1.78054097011 \\
0.2 & 0.5 &\B 1.1 & 0.2 & 0.5 & -1.8638586434 & -1.75716821872 \\
0.2 & 0.5 &\B 1.2 & 0.2 & 0.5 & -1.8563791180 & -1.75030388119 \\
0.2 & 0.5 &\B 1.3 & 0.2 & 0.5 & -1.8488975550 & -1.74343325690 \\
0.2 & 0.5 & 1 &\B 0.3 & 0.5 & -1.7816929512 & -1.67995077275 \\
0.2 & 0.5 & 1 &\B 0.4 & 0.5 & -1.6940695909 & -1.59754625788 \\
0.2 & 0.5 & 1 &\B 0.5 & 0.5 & -1.60833298231& -1.51669912930 \\
0.2 & 0.5 & 1 & 0.2 &\B 0.6 & -1.79104380621& -1.69665633242 \\
0.2 & 0.5 & 1 & 0.2 &\B 0.7 & -1.72028938675& -1.63324789889 \\
0.2 & 0.5 & 1 & 0.2 &\B 0.8 & -1.66248454886& -1.58021088372 \\
\end{tblr}
\end{table}
\end{frame}
\end{document}
在第二种情况下,表格序言和列标题是:
\begin{table}
\centering
\sisetup{detect-weight,
mode=text}
\caption{My table}
\label{tab:tblr}
\footnotesize
\begin{tblr}{hlines, vlines,
colspec={*{5}{ S[table-format=1.1] }
*{2}{ S[table-format=-1.11]} },
colsep=4pt,
abovesep={ 0.5pt}, % <---
belowsep={-0.5pt} % <---
}
\SetCell[r=2]{c} A
& \SetCell[r=2]{c} B
& \SetCell[r=2]{c} C
& \SetCell[r=2]{c} {{D}} % <---
& \SetCell[r=2]{c} {{E}} % <---
& \SetCell[c=2]{c} F
& \\
& & & & & {{{G}}} & {{{H}}} \\
两种情况下的编译结果相同:
注意:与第一个答案相比,此处表格中使用了更大的字体大小,即\scriptsize
改用\footnotesize
。
答案2
- 你真的需要在演讲中填写表格吗?对于观众来说,这通常很无聊 :-(
- 您的表格可以放在一个框架中,您需要减小字体大小并替换
\setcellgapes{5pt}\makegapedcells
为\setlength\extrarowheight{1pt}
:
编辑:
- 标题后空白变大的原因在于段落间距的设置:
\setlength{\parskip}{5pt}
在标题和表格之间也插入了 5pt 的额外垂直空间。可以通过以下方式解决:- 不使用此设置(我看不出有任何理由)
- 在每个表中,在本地将其更改为,或者通过使用带有宏的包来
\setlength{\parskip}{-5pt}
全局执行此操作etoolbox
\AtBeginEnvironment{table}{\setlength{\parskip}{-5pt}}
- 通过使用组合
beamer
字幕机制和caption package (versions of the
Beamerpackage after 2019 to some extent allow cooperation between the
Beamerand
Caption 包)。此组合在以下 MWE 中使用
\setbeamertemplate{caption}[numbered]
\usepackage[font=scriptsize,
labelfont={bf,color=blue}]
{caption}% it is compatible with beamers
- 对于字体大小,
pagetitle
而frametitle
不是使用\setbeamerfont{<object name>}{size=...}
本地调整它们(请参阅下面的 MWE)
\documentclass[12pt]{beamer}
\usetheme{AnnArbor}
\usecolortheme{beaver}% red color theme
\usefonttheme{professionalfonts} % using non standard fonts for beamer
\usefonttheme{serif} % default family is serif
%----
\setbeamerfont{title page}{size=\footnotesize\bfseries}
%----
\setbeamerfont{frametitle}{size=\footnotesize\bfseries}
%----
\setbeamertemplate{caption}[numbered]
\usepackage[font=scriptsize,
labelfont={bf,color=blue}]
{caption}% it is compatible with beamers
%%----------------------------------------------------------
\usepackage{ragged2e}\justifying
\usepackage[f]{esvect}
\usepackage{makecell, multirow}
\usepackage{siunitx}
%\usepackage{xcolor} % it is loaded by beamer
%\usepackage{hyperref} % it is loaded by beamer
\setlength{\parskip}{5pt}
\usepackage{etoolbox}
\newrobustcmd\B{\DeclareFontSeriesDefault[rm]{bf}{b}\bfseries}
\AtBeginEnvironment{table}{\setlength{\parskip}{-5pt}}
%%-----------------------------------------------------------
%\usepackage{setspace}
\usepackage{lipsum}
\title[Presentation title]{Presentation title}
\subtitle{}
\author[Math-Man]{Math-Man}
\institute[]{}
\date[]{\textbf{\today}}
%%=================
\begin{document}
\begin{frame}[plain, noframenumbering]
\maketitle
\end{frame}
%%------------------------------------------------------------
\begin{frame}[t]{}
\begin{table}[ht]
\centering
\sisetup{detect-weight,
mode=text}
\setlength\extrarowheight{1pt}
\caption{My table}
\label{tab:...}
\scriptsize
\begin{tabular}{|*{5}{S[table-format=1.1]|}
*{2}{S[table-format=-1.11]|}
}
\hline
{\multirow{2.4}{*}{A}} & {\multirow{2.4}{*}{B}} & {\multirow{2.4}{*}{C}} & {\multirow{2.4}{*}{D}} & {\multirow{2.4}{*}{E}} & \multicolumn{2}{c|}{F} \\ \cline{6-7}
& & & & & {G} & {H} \\ \hline
\B 0.2 &\B 0.5 &\B 1 &\B 0.2 &\B 0.5 & -1.8713360906 & -1.7640262021 \\ \hline
\B 0.3 & 0.5 & 1 & 0.2 & 0.5 & -1.9365758323 & -1.7648755545 \\ \hline
\B 0.4 & 0.5 & 1 & 0.2 & 0.5 & -1.9844365775 & -1.7572640364 \\ \hline
0.2 &\B 0.6 & 1 & 0.2 & 0.5 & -1.8893451634 & -1.7769110253 \\ \hline
0.2 &\B 0.7 & 1 & 0.2 & 0.5 & -1.9037201042 & -1.7845630194 \\ \hline
0.2 &\B 0.8 & 1 & 0.2 & 0.5 & -1.9084283289 & -1.78054097011 \\ \hline
0.2 & 0.5 &\B 1.1 & 0.2 & 0.5 & -1.8638586434 & -1.75716821872 \\ \hline
0.2 & 0.5 &\B 1.2 & 0.2 & 0.5 & -1.8563791180 & -1.75030388119 \\ \hline
0.2 & 0.5 &\B 1.3 & 0.2 & 0.5 & -1.8488975550 & -1.74343325690 \\ \hline
0.2 & 0.5 & 1 &\B 0.3 & 0.5 & -1.7816929512 & -1.67995077275 \\ \hline
0.2 & 0.5 & 1 &\B 0.4 & 0.5 & -1.6940695909 & -1.59754625788 \\ \hline
0.2 & 0.5 & 1 &\B 0.5 & 0.5 & -1.60833298231& -1.51669912930 \\ \hline
0.2 & 0.5 & 1 & 0.2 &\B 0.6 & -1.79104380621& -1.69665633242 \\ \hline
0.2 & 0.5 & 1 & 0.2 &\B 0.7 & -1.72028938675& -1.63324789889 \\ \hline
0.2 & 0.5 & 1 & 0.2 &\B 0.8 & -1.66248454886& -1.58021088372 \\ \hline
\end{tabular}
\end{table}
\end{frame}
%%------------------------------------------------------------
\end{document}