如何用LaTeX写一个PPT

如何用LaTeX写一个PPT

 说到写PPT大家一般会想到的是微软的Microsoft PowerPoint,因为他更易于制作并且拥有丰富的动画,但是当你需要制作一个学术相关的ppt时,你需要更好的排版以及显示源代码时,Microsoft PowerPoint又不具备这样的功能。

SO

 如果你是一位LaTeX用户,并且需要做演示文稿,那么使用LaTeX来制作PPT是一个不错的选择。不仅可以充分发挥LaTeX排版的优势,还可以方便地将源代码显示在幻灯片上,方便讲解和交流。

LaTeX制作PPT的优缺点

优点:

  • 完美的排版效果:LaTeX是一种专业的排版系统,对于文字和公式的排版效果非常优秀,因此使用LaTeX制作PPT可以保证幻灯片的美观和专业性。
  • 显示源代码:LaTeX的一个重要特点是可以很容易地显示源代码,这对于演讲者来说是非常方便的,因为他们可以通过幻灯片来演示代码。
  • 可以在版本控制系统中管理:使用LaTeX可以很容易地将幻灯片放入版本控制系统中,这使得团队协作变得更加容易。

缺点:

  • 需要学习:LaTeX是一种非常强大的工具,但是它也需要一些学习和使用的时间和精力。如果你不熟悉LaTeX,那么在制作PPT时可能会遇到一些困难。
  • 制作时间较长:由于LaTeX需要编译,因此制作PPT可能需要更长的时间。
  • 动画效果较差:相比于Microsoft PowerPoint,LaTeX的动画效果可能会稍显逊色。

以下是如何使用LaTeX写一个PPT并显示源代码的步骤:

步骤一:选择PPT模板

 在LaTeX中,有许多第三方的PPT模板可以选择。在这里,我们选择beamer模板来制作我们的PPT。在LaTeX文档头部加入以下代码,即可使用beamer模板:

\documentclass{beamer}

步骤二:设置主题和颜色

 在beamer模板中,主题和颜色是可以自定义的。以下是一些常用的主题和颜色:

主题:

  • default
  • Berlin
  • CambridgeUS
  • Madrid
  • Warsaw
    颜色:
  • default
  • beaver
  • dolphin
  • whale

 在LaTeX文档头部加入以下代码,即可设置主题和颜色:

\usetheme{主题名称}
\usecolortheme{颜色名称}

 例如,使用Berlin主题和dolphin颜色:

\usetheme{Berlin}
\usecolortheme{dolphin}

步骤三:添加幻灯片内容

 在LaTeX中,添加幻灯片的方式是使用\frame命令。以下是一个例子:

\begin{frame}
\frametitle{第一张幻灯片}
这是第一张幻灯片的内容。
\end{frame}

 在\frametitle命令中,可以设置幻灯片的标题。在\frame命令中,可以添加幻灯片的内容。如果需要添加代码,可以使用verbatim环境来实现。

\begin{frame}[fragile]
\frametitle{显示代码}
\begin{verbatim}
#include <stdio.h>
int main() {
printf("Hello, world!");
return 0;
}
\end{verbatim}
\end{frame}

 如果你需要展示图片的时候 你可以使用\column{}命令,通过调整大小的参数可以很好的展示出左图右稿或者左稿右图的效果。

\begin{columns}
\column{0.5\textwidth}
\end{columns}

 在\begin{frame}命令中,使用[fragile]选项可以让LaTeX正确地处理代码。

步骤四:生成PPT

 添加完所有幻灯片内容后,就可以使用LaTeX编译器生成PPT了。常用的LaTeX编译器有pdflatexxelatex。以下是一个例子:

在这里插入图片描述
在这里插入图片描述

\documentclass{beamer}

% 导入所需的宏包
\usepackage[utf8]{inputenc}
\usepackage{ctex}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

% 设置主题和颜色
\usetheme{Madrid}
\usecolortheme{seahorse}

% 设置文档信息
\title{动态报告排版作业2}
\author{tjx}
\institute{201212345678}
\date{\today}

% 开始文档
\begin{document}

% 标题页
\begin{frame}
  \titlepage
\end{frame}

% 目录页
\begin{frame}
  \frametitle{目录}
  \tableofcontents
\end{frame}

% 章节页
\section{实例1:科学数据分析}
\begin{frame}
  \frametitle{实例1:科学数据分析}
  \begin{columns}
	\column{0.5\textwidth}
	\begin{itemize}
		\item {
			第一步:将数据加入到TeX
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.5\textwidth}
    \begin{tikzpicture}[scale=0.65]
    \begin{loglogaxis}[
    title=Convergence Plot,
    xlabel={Degrees of freedom},
    ylabel={$L_2$ Error},
    ]
    \addplot table {data_d2.dat};
    \end{loglogaxis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\begin{frame}
  \frametitle{实例1:科学数据分析}
    \begin{columns}
	\column{0.5\textwidth}
	\begin{itemize}
		\item {
			第二步:将其余的数据加进来
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.5\textwidth}
    \begin{tikzpicture}[scale=0.65]
    \begin{loglogaxis}[
    title=Convergence Plot,
    xlabel={Degrees of freedom},
    ylabel={$L_2$ Error},
    ]
    \addplot table {data_d2.dat};
    \addplot table {data_d3.dat};
    \addplot table {data_d4.dat};
    \end{loglogaxis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\begin{frame}
  \frametitle{实例1:科学数据分析}
    \begin{columns}
	\column{0.5\textwidth}
	\begin{itemize}
		\item {
			第三步:增加legend + grid
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.5\textwidth}
    \begin{tikzpicture}[scale=0.65]
    \begin{loglogaxis}[
    title=Convergence Plot,
    xlabel={Degrees of freedom},
    ylabel={$L_2$ Error},
    grid=major,
    legend entries={$d=2$,$d=3$,$d=4$},
    ]
    \addplot table {data_d2.dat};
    \addplot table {data_d3.dat};
    \addplot table {data_d4.dat};
    \end{loglogaxis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\begin{frame}
  \frametitle{实例1:科学数据分析}
    \begin{columns}
	\column{0.5\textwidth}
	\begin{itemize}
		\item {
			第四步:增加一条拟合直线
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.5\textwidth}
    \begin{tikzpicture}[scale=0.65]
    \begin{loglogaxis}[
    title=Convergence Plot,
    xlabel={Degrees of freedom},
    ylabel={$L_2$ Error},
    grid=major,
    legend entries={$d=2$,$d=3$,$d=4$},
    ]
    \addplot table {data_d2.dat};
    \addplot table {data_d3.dat};
    \addplot table {data_d4.dat};
    \addplot table[
    x=dof,
    y={create col/linear regression={y=l2_err,
    variance list={1000,800,600,500,400,200,100}}}]
    {data_d4.dat};
    \end{loglogaxis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\begin{frame}
  \frametitle{实例1:科学数据分析}
    \begin{columns}
	\column{0.5\textwidth}
	\begin{itemize}
		\item {
			第五步:使用TikZ添加注释:一个斜率三角形。
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.5\textwidth}
    \begin{tikzpicture}[scale=0.65]
    \begin{loglogaxis}[
    title=Convergence Plot,
    xlabel={Degrees of freedom},
    ylabel={$L_2$ Error},
    grid=major,
    legend entries={$d=2$,$d=3$,$d=4$},
    ]
    \addplot table {data_d2.dat};
    \addplot table {data_d3.dat};
    \addplot table {data_d4.dat};
    \addplot table[
    x=dof,
    y={create col/linear regression={y=l2_err,
    variance list={1000,800,600,500,400,200,100}}}]
    {data_d4.dat}
    coordinate [pos=0.25] (A)
    coordinate [pos=0.4] (B)
    ;
    \xdef\slope{\pgfplotstableregressiona} % save the slope parameter
    \draw (A) -| (B) % draw the opposite and adjacent sides of the triangle
    node [pos=0.75,anchor=west] {\pgfmathprintnumber{\slope}};
    \end{loglogaxis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\section{实例2:函数可视化}
\begin{frame}
  \frametitle{实例2:函数可视化}
    \begin{columns}
	\column{0.5\textwidth}
	\begin{itemize}
		\item {
			任务一:实现来自数据文件中的数据构成函数的可视化
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.5\textwidth}
    \begin{tikzpicture}[scale=1.5]
    \begin{axis}[
    title=Inv. cum. normal,
    xlabel={$x$},
    ylabel={$y$},
    tiny,
    ]
    \addplot[blue] table {invcum.dat};
    \end{axis}
    \end{tikzpicture}
    \end{columns}
    
\end{frame}

\begin{frame}
  \frametitle{实例2:函数可视化}
    \begin{columns}
	\column{0.5\textwidth}
	\begin{itemize}
		\item {
			任务一:实现来自数据文件中的数据构成函数的可视化,微调过后。
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.5\textwidth}
    \begin{tikzpicture}[scale=1.5]
    \begin{axis}[
    title=Inv. cum. normal,
    xlabel={$x$},
    ylabel={$y$},
    tiny,
    ymin=-3, ymax=3,
    minor y tick num=1,
    ]
    \addplot[blue] table 
    {invcum.dat};
    \end{axis}
    \end{tikzpicture}
    \end{columns}
    
\end{frame}

\begin{frame}
  \frametitle{实例2:函数可视化}
    \begin{columns}
	\column{0.5\textwidth}
	\begin{itemize}
		\item {
			增加第2张图:有表达式的函数
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.5\textwidth}
    \begin{tikzpicture}[scale=1.0]
    \begin{axis}[
    title=Inv. cum. normal,
    xlabel={$x$},
    ylabel={$y$},
    tiny,
    ymin=-3, ymax=3,
    minor y tick num=1,
    ]
    \addplot[blue] table {invcum.dat};
    \end{axis}
    \end{tikzpicture}
    %
    \hskip 10pt % insert a non-breaking space of specified width.
    % 
    \begin{tikzpicture}[scale=0.5]
    \begin{axis}[
    ]
    % density of Normal distribution:
    \newcommand\MU{0}
    \newcommand\SIGMA{1e-3}
    \addplot[red,domain=-3*\SIGMA:3*\SIGMA,samples=201]
    {exp(-(x-\MU)^2 / 2 / \SIGMA^2) / (\SIGMA * sqrt(2*pi))};
    \end{axis}
    \end{tikzpicture}
    \end{columns}
    
\end{frame}

\begin{frame}
  \frametitle{实例2:函数可视化}
    \begin{columns}
	\column{0.3\textwidth}
	\begin{itemize}
		\item {
			y的刻度位置修改
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.7\textwidth}
    \begin{tikzpicture}[baseline,scale=1.2]
    \begin{axis}[
    title=Inv. cum. normal,
    xlabel={$x$},
    ylabel={$y$},
    tiny,
    ymin=-3, ymax=3,
    minor y tick num=1,
    ]
    \addplot[blue] table {invcum.dat};
    \end{axis}
    \end{tikzpicture}%
    %
    \begin{tikzpicture}[baseline,scale=1.2]
    \begin{axis}[
    tiny,
    yticklabel pos=right,
    ]
    % density of Normal distribution:
    \newcommand\MU{0}
    \newcommand\SIGMA{1e-3}
    \addplot[red,domain=-3*\SIGMA:3*\SIGMA,samples=201]
    {exp(-(x-\MU)^2 / 2 / \SIGMA^2) / (\SIGMA * sqrt(2*pi))};
    \end{axis}
    \end{tikzpicture}
    \end{columns}
    
\end{frame}

\begin{frame}
  \frametitle{实例2:函数可视化}
    \begin{columns}
	\column{0.5\textwidth}
	\begin{itemize}
		\item {
			风格调整
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.5\textwidth}
    \begin{tikzpicture}[scale=1.5]
    \begin{axis}[
    tiny,
    axis lines=left,
    scaled ticks=false,
    xticklabel style={
    rotate=90,
    anchor=east,
    /pgf/number format/precision=3,
    /pgf/number format/fixed,
    /pgf/number format/fixed zerofill},
    ]
    % density of Normal distribution:
    \newcommand\MU{0}
    \newcommand\SIGMA{1e-3}
    \addplot[red,domain=-3*\SIGMA:3*\SIGMA,samples=201]
    {exp(-(x-\MU)^2 / 2 / \SIGMA^2) / (\SIGMA * 
    sqrt(2*pi))};
    \end{axis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\section{实例3:散点图}
\begin{frame}
  \frametitle{实例3:散点图}
    \begin{columns}
	\column{0.3\textwidth}
	\begin{itemize}
		\item {
			通过已给文件画散点图
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.7\textwidth}
    \begin{tikzpicture}[scale=1.0]
    \begin{axis}
    \addplot+[only marks] table
    {concat_VV_together_grid.dat};
    \end{axis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\begin{frame}
  \frametitle{实例3:散点图}
    \begin{columns}
	\column{0.3\textwidth}
	\begin{itemize}
		\item {
			调整
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.7\textwidth}
    \begin{tikzpicture}[scale=1.0]
    \begin{axis}[
    enlargelimits=false,
    ]
    \addplot+[only marks,mark size=0.6pt]
    table {concat_VV_together_grid.dat};
    \end{axis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\begin{frame}
  \frametitle{实例3:散点图}
    \begin{columns}
	\column{0.3\textwidth}
	\begin{itemize}
		\item {
			根据元数据进行颜色编码
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.7\textwidth}
    \begin{tikzpicture}[scale=1.0]
    \begin{axis}[
    enlargelimits=false,
    ]
    \addplot+[only marks,scatter,
    mark size=0.6pt
    ]
    table[meta=f(x)]
    {concat_VV_together_grid.dat};
    \end{axis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\begin{frame}
  \frametitle{实例3:散点图}
    \begin{columns}
	\column{0.3\textwidth}
	\begin{itemize}
		\item {
			根据元数据进行颜色编码
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.7\textwidth}
    \begin{tikzpicture}[scale=1.0]
    \begin{axis}[
    enlargelimits=false,
    colorbar,
    ]
    \addplot+ [
    only marks,
    scatter,
    point meta={
    ln(1e-6+abs(\thisrow{f(x)}))/ln(10)
    },
    mark size=0.6pt,
    ] table {concat_VV_together_grid.dat};
    \end{axis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\begin{frame}
  \frametitle{实例3:散点图}
    \begin{columns}
	\column{0.3\textwidth}
	\begin{itemize}
		\item {
			散点图:每个点用类标签画散点图
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.7\textwidth}
    \begin{tikzpicture}[scale=1.0]
    \begin{axis}[
        xlabel={$x$},
        ylabel={$y$},
        scatter/classes={
        a={mark=square*,blue},
        b={mark=triangle*,red},
        c={mark=o,draw=black} }]
        \addplot [scatter,only marks,scatter src=explicit symbolic] 
        coordinates {
      (0.1,0.15) [a]
      (0.45,0.27) [c]
      (0.02,0.17) [a]
      (0.06,0.1)  [a]
      (0.9,0.5)   [b]
      (0.5,0.3)   [c]
      (0.85,0.52) [b]
      (0.12,0.05) [a]
      (0.73,0.45) [b]
      (0.53,0.25) [c]
      (0.76,0.5)  [b]
      (0.55,0.32) [c]
    };
    \end{axis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\begin{frame}
  \frametitle{实例3:散点图}
    \begin{columns}
	\column{0.3\textwidth}
	\begin{itemize}
		\item {
			散点图:在指定位置画出单个字符串标签
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.7\textwidth}
    \begin{tikzpicture}[scale=1.0]
    \begin{axis}[
    enlargelimits=0.2,
    ]
    \addplot+[nodes near coords,only marks,
    point meta=explicit symbolic]
    coordinates {
    (0.5,0.2) [1]
    (0.2,0.1) [t2]
    (0.7,0.6) [3]
    (0.35,0.4) [Y4]
    (0.65,0.1) [5]
    };
    \end{axis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\section{实例4:两个变量的函数}
\begin{frame}
  \frametitle{实例4:两个变量的函数}
    \begin{columns}
	\column{0.3\textwidth}
	\begin{itemize}
		\item {
			根据数据矩阵绘制曲面图+根据表达式绘制轮廓图
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.7\textwidth}
    \begin{tikzpicture}
    \begin{axis}
    \addplot3[surf,mesh/ordering=y varies]
    table {concat_VV_together.dat};
    \end{axis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\begin{frame}
  \frametitle{实例4:两个变量的函数}
    \begin{columns}
	\column{0.3\textwidth}
	\begin{itemize}
		\item {
			微调
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.7\textwidth}
    \begin{tikzpicture}
    \begin{axis}[
    view/h=40,
    colorbar horizontal,
    xlabel=$x$, ylabel=$y$,
    ]
    \addplot3[surf,mesh/ordering=y varies,
    shader=interp]
    table {concat_VV_together.dat};
    \end{axis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\begin{frame}
  \frametitle{实例4:两个变量的函数}
    \begin{columns}
	\column{0.3\textwidth}
	\begin{itemize}
		\item {
			覆盖网格(overlay grid)
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.7\textwidth}
    \begin{tikzpicture}
    \begin{axis}[
    view/h=40,
    colorbar horizontal,
    xlabel=$x$, ylabel=$y$,
    ]
    \addplot3[surf,mesh/ordering=y varies,
    shader=interp]
    table {concat_VV_together.dat};
    \addplot3[blue,mark=*,
    mark options={fill=blue!80!black},
    only marks,mark size=0.6pt]
    table[z expr=1.2]
    {concat_VV_together_grid.dat};
    \end{axis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\begin{frame}
  \frametitle{实例4:两个变量的函数}
    \begin{columns}
	\column{0.3\textwidth}
	\begin{itemize}
		\item {
			等高线图(contour plot of function expression)
		}
	\end{itemize}\
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\bigskip
	\column{0.7\textwidth}
    \begin{tikzpicture}
    \begin{axis}[
    title={$x \exp(-x^2-y^2)$},
    enlarge x limits,
    view={0}{90},
    xlabel=$x$, ylabel=$y$,
    ]
    \addplot3[domain= -2:2,
    domain y=-1.3:1.3,
    contour gnuplot={number=14},thick]
    {exp(-x^2-y^2)*x};
    \end{axis}
    \end{tikzpicture}
    \end{columns}
\end{frame}

\section{小结}
\begin{frame}
  \frametitle{小结}
    \begin{itemize}
		\item {
			很多图都可以画出来,但是散点图的画法和课件上有所不同,可能存在版本的问题(我问过几个同学都画不出来),其他图片都挺顺利的,就是初期有很多参数要调,调整以后就没什么大问题了。
		}
	\end{itemize}
\end{frame}
  
\end{document}

本文出自北理工tjx的学生练习

  • 17
    点赞
  • 107
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值