首页/文章/ 详情

Beamer简易教学 | 3 三线表、插图

1年前浏览607

本次给大家带来的是:如何在Beamer中进行图表设置?

主要内容:三线表、图片环境、子图设置、交叉引用。这些设置是大家在准备汇报时,最常用的图表设置,没有讲到的部分可根据自己的需求进行网络搜索。


三线表

预想效果

代码片

\usepackage{booktabs}
%-----------------------------------------
\begin{frame}{三线表设置}
如表\ref{tab1}所示
\begin{table}
\centering
\caption{The first table}
\label{tab1}
\begin{tabular}{cccccc}
   \toprule
   序号 & 姓名 & 性别 & 年龄 & 身高/cm & 体重/kg \\
   \midrule
   1 & 张三 & M & 16 & 163 & 50 \\
   2 & 王红 & F & 15 & 159 & 47 \\
   3 & 李二 & M & 17 & 165 & 52 \\
   \bottomrule
\end{tabular}
\end{table}
\end{frame}

代码解读

  1. 首先引入“三线表宏包”——\usepackage{booktabs}

  2. \begin{table}....\end{table}表示创建一个“浮动”表的环境,在这里面可以通过\caption{The first table}命名表名,\centering使得表格居中显示,\label{tab1}给表格加入交叉引用序号,在正文区使用\ref{tab1}即可进行引用,属于可选选项,有必要时再使用;

  3. \begin{tabular}{cccccc}...\end{tabular}是表格环境的核心代码,{cccccc}表示 6 列内容均居中显示,\toprule、\midrule、 \bottomrule表示三线表的上、中、下三条线,系统自动显示粗细,不同列用符号      分割,换行符使用\\

创建表格环境并不费事,只需要花两三分钟理解语句意思即可,麻烦的的是创建表格的符号比较繁杂,这时我们可以使用第三方创建Latex表格的工具——

https://www.tablesgenerator.com/

这是个在线小工具,如下图所示,用户可以较直观的方式填充表格,甚至可以直接粘贴Excel内容至该网站上,一键即可生成相应的Latex表格语句。

图片环境

普通插图

预想效果

代码片

\graphicspath{{Fig/}}% 添加图片路径
%---------------------------------
\begin{frame}{插图1}
\begin{center}
  \includegraphics[width=0.8\textwidth]{梅西}
\end{center}
\end{frame}

\begin{frame}{插图2}
\begin{center} 
  \includegraphics[width=4.5cm,height=3.0cm]{梅西}\qquad
  \includegraphics[width=0.5\textwidth]{梅西_1}
\end{center}
\end{frame}

代码解读

  1. 在Beamer中内置有图片宏包,故不需要专门引入\usepackage{graphicx}包;
  2. \graphicspath{{Fig/}}加入文件路径,建立一个好习惯,将所有用到的图片都放到一个文件夹中,以后的代码插入图片时,只需写入文件名即可。
  3. \begin{center}...\end{center}创建一个居中环境,里面的内容将在幻灯片中居中显示;
  4. \includegraphics[width=0.8\textwidth]{梅西}是插图语句,[width=0.8\textwidth]表示该图片将占据0.8倍的文本框宽度(原比例不变),此案例为单栏,故呈现的是0.8倍的幻灯片宽度,若设置双栏,则为该栏宽度的 0.8 倍宽度,{梅西}由于引入了文件路径,故不需要填写图片的绝对路径,后缀名也不需要添加。
  5. \qquad两个空格宽度间隔;
  6. \includegraphics[width=4.5cm,height=3.0cm]{梅西}以限制高度和宽度来缩放图片,这种方式在提前知道图片比例还好,不过个人感觉比较麻烦,还是[width=0.8\textwidth]这样成倍数的关系方便些。

Figure环境

预想效果

代码片

\setbeamertemplate{caption}[numbered]% 图表序号
%---------------------------------------------------------
\begin{frame}{Figure浮动环境}
球王梅西如图\ref{Messi1}所示
\begin{figure}
  \centering
  \includegraphics[width=0.5\textwidth]{梅西_2}
  \caption{Messi}\label{Messi1}
\end{figure}
\end{frame}

代码解读

  1. \begin{figure}...\end{figure}创建图片浮动体环境,使得插图的显示更加全面;
  2. \caption{Messi}\label{Messi1}显示图片解释和引用序号;
  3. \setbeamertemplate{caption}[numbered]显示图号和表号,个人使用过程中发现没有此语句,插图序号会消失!

子图设置

预先效果

代码片

\setbeamertemplate{caption}[numbered]
\usepackage{subfigure}
%-------------------------------------------------
\begin{frame}{子图设置}
梅西如图\ref{Fig5},梅西1如图\ref{Fig1},梅西2如图\ref{Fig2},梅西3如图\ref{Fig3},梅西4如图\ref{Fig4},
\begin{figure}[H]
    \centering  %图片全局居中
    \vspace{-0.35cm} %设置与上面正文的距离
    \subfigtopskip=2pt %设置子图与上面正文或别的内容的距离
    \subfigbottomskip=2pt %设置第二行子图与第一行子图的距离,即下面的头与上面的脚的距离
    \subfigcapskip=-5pt %设置子图与子标题之间的距离
    \subfigure[梅西1]{
        \label{Fig1}
        \includegraphics[width=0.25\textwidth]{梅西}}
    \subfigure[梅西2]{
        \label{Fig2}
        \includegraphics[width=0.25\textwidth]{梅西_1}}
\\
    \subfigure[梅西3]{
        \label{Fig3}
        \includegraphics[width=0.25\textwidth]{梅西_2}}
    \subfigure[梅西4]{
        \label{Fig4}
        \includegraphics[width=0.25\textwidth]{梅西_3}}
    \caption{Messi}
    \label{Fig5}
\end{figure}

代码解释

  1. \usepackage{subfigure}引入子图宏包;
  2. 子图的详细设置已在代码中注释的非常清楚,用户只需更换文件名和\label\caption,然后复 制粘贴即可,本次案例展示为       组图,同样适用       组图。

完整代码

\documentclass{beamer}
%-----------------------------导言区---------------------
\usetheme{Warsaw}
\setbeamertemplate{caption}[numbered]% 图表序号
\usepackage{ctex}% 中文环境
\usepackage{subfigure}% 子图
\usepackage{booktabs}% 三线表
\graphicspath{{Fig/}}% 添加图片路径
%-----------------------------正文区---------------------
\begin{document}

\begin{frame}{三线表设置}
如表\ref{tab1}所示
\begin{table}
\centering
\caption{The first table}
\label{tab1}
\begin{tabular}{cccccc}
   \toprule
   序号 & 姓名 & 性别 & 年龄 & 身高/cm & 体重/kg \\
   \midrule
   1 & 张三 & M & 16 & 163 & 50 \\
   2 & 王红 & F & 15 & 159 & 47 \\
   3 & 李二 & M & 17 & 165 & 52 \\
   \bottomrule
\end{tabular}
\end{table}
\end{frame}

\begin{frame}{插图1}
\begin{center}
  \includegraphics[width=0.8\textwidth]{梅西}
\end{center}
\end{frame}

\begin{frame}{插图2}
\begin{center} 
  \includegraphics[width=4.5cm,height=3.0cm]{梅西}\qquad
  \includegraphics[width=0.5\textwidth]{梅西_1}
\end{center}
\end{frame}

\begin{frame}{Figure浮动环境}
球王梅西如图\ref{Messi1}所示
\begin{figure}
  \centering
  \includegraphics[width=0.5\textwidth]{梅西_2}
  \caption{Messi}\label{Messi1}
\end{figure}

\end{frame}

\begin{frame}{子图设置}
梅西如图\ref{Fig5},梅西1如图\ref{Fig1},梅西2如图\ref{Fig2},梅西3如图\ref{Fig3},梅西4如图\ref{Fig4},
\begin{figure}[H]
    \centering  %图片全局居中
    \vspace{-0.35cm} %设置与上面正文的距离
    \subfigtopskip=2pt %设置子图与上面正文或别的内容的距离
    \subfigbottomskip=2pt %设置第二行子图与第一行子图的距离,即下面的头与上面的脚的距离
    \subfigcapskip=-5pt %设置子图与子标题之间的距离
    \subfigure[梅西1]{
        \label{Fig1}
        \includegraphics[width=0.25\textwidth]{梅西}}
    \subfigure[梅西2]{
        \label{Fig2}
        \includegraphics[width=0.25\textwidth]{梅西_1}}
\\
    \subfigure[梅西3]{
        \label{Fig3}
        \includegraphics[width=0.25\textwidth]{梅西_2}}
    \subfigure[梅西4]{
        \label{Fig4}
        \includegraphics[width=0.25\textwidth]{梅西_3}}
    \caption{Messi}
    \label{Fig5}
\end{figure}

\end{frame}

\end{document} 


-End-


易木木响叮当

想陪你一起度过短暂且漫长的科研生活



来源:易木木响叮当
理论通用
著作权归作者所有,欢迎分享,未经许可,不得转载
首次发布时间:2023-06-02
最近编辑:1年前
易木木响叮当
硕士 有限元爱好者
获赞 205粉丝 215文章 320课程 2
点赞
收藏
未登录
还没有评论
课程
培训
服务
行家
VIP会员 学习 福利任务 兑换礼品
下载APP
联系我们
帮助与反馈