美文网首页数目字生存
在Jyputer Notebook中用Latex生成含公式表格

在Jyputer Notebook中用Latex生成含公式表格

作者: askka | 来源:发表于2019-03-06 11:37 被阅读0次

    华中科技大学出版社的《电力系统分析》算得上是该专业的经典教材之一了。笔者制作PPT课件过程中需要用到该教材中的插图,但发现扫描图的实在是不清晰所以就想着重新绘制一个。这又是表格又是公式的,说起来用Latex应该是最方便的吧。

    原教材插图

    原图参见《电力系统分析(第三版)》P105

    绘制思路

    要完成的图表并不复杂,利用\begin{aligned}和\end{aligned}实现公式对齐即可,Latex语法如下所示:

    \begin{aligned}
    &i_\infty \\
    &\uparrow \\
    &i_{f0}
    \end{aligned}
    

    Latex公式中的“\\”为换行符号,“&”是段落中公式的对齐位置。显示效果如下:



    如果不明确对齐位置,则显示效果会不尽如人意。如下图所示:


    按此思路依葫芦画瓢,将所有电流分量绘制完成:

    \begin{equation}  
        \begin{array}{c}
            \overbrace{\qquad \qquad \qquad \qquad \qquad }^{\text{基频分量}}  \\
            \begin{array}{c}  
                &\text{稳态短路电流} \\ &i_\infty \\  &\uparrow \\ &i_{f0} \\& \text{稳态励磁电流}
            \end{array} 
            \qquad \qquad 
            \begin{array}{c}  
                &\text{基频自由分量} \\ &\Delta i' = i' -i_\infty \\ &\uparrow \\&i_\infty \\& \text{励磁绕组自由分量}
            \end{array} \\
            \underbrace{\qquad \qquad \qquad \qquad \qquad }_{\text{直流分量}}  
        \end{array} 
        \qquad \qquad
        \begin{array}{c}
            \overbrace{\qquad \qquad}^{\text{非基频分量}}  \\  
            \begin{array}{c}  
                &\text{直流分量} \qquad \text{倍频分量} \\
                &i_{ap} \; \longrightarrow \; i_{2\omega} \\ & \nwarrow \quad \nearrow \\ & \Delta i_\omega \\& \text{励磁绕组基频}
            \end{array} \\ \\
            \quad \text{直流分量}
        \end{array} 
    \end{equation}   
    

    Ctrl+enter执行的结果如下图:


    接下来将表格框线加上,并将各个电流分量的衰减时间常数也对应标注上。执行的结果如下图:
    \begin{equation} 
    \begin{array}{c|cc}
    \hline 
        \quad & \text{强制分量} & \text{自由分量}\qquad \qquad \qquad \qquad  \\
    \hline
        \text{定子} & \overbrace{\qquad \qquad \qquad \qquad \qquad }^{\text{基频分量}}  & \overbrace{\qquad \qquad}^{\text{非基频分量}} \\ 
        \quad & \begin{array}{ccc}   
    \text{稳态短路电流} &\qquad &\text{基频自由分量} \\
    i_\infty &\qquad &\Delta i' = i' -i_\infty \\
    \uparrow &\qquad &\uparrow \\
    i_{f0} &\qquad &i_\infty \\ 
    \text{稳态励磁电流} &\qquad & \text{励磁绕组自由分量} \end{array} 
     & \begin{array}{c} 
         &\text{直流分量} \qquad \text{倍频分量} \\ &i_{ap} \; \longrightarrow \; i_{2\omega} \\ & \nwarrow \quad \nearrow \\ & \Delta i_\omega \\& \text{励磁绕组基频}
     \end{array} \\
    \text{转子} & \underbrace{\qquad \qquad \qquad \qquad \qquad }_{\text{直流分量}} & \quad \text{直流分量}\\ 
    \hline
        \text{衰减时间常数} & \infty \qquad \qquad \qquad \qquad \; T'_d & T_a \\
    \hline
    \end{array}
    \end{equation}
    

    利用在线Latex编辑公式

    笔者是在Jupyter Notebook中执行的上述公式。当然也可以考虑利用在线Latex编辑器编辑。需注意的是:

    • codecogs不支持中文、且公式代码不能太长;
    • 插入表格中的公式需要用$...$来标记,否则会报错。在Jyputer Notebook中直接用mathjax不存在此问题,但mathjax不支持"\tabular"而只支持"\array" 。

    试着在线编辑Latex公式得到的结果如下:


    在线编辑的结果

    在Python中调用Latex公式

    此外也尝试了下用Python代码来生成公式的方法。导入display、Math、Latex三个包,用起来也挺方便的。

    from IPython.display import display, Math, Latex
    display(Math(r"$\Delta i' = i' -i_\infty \\ \uparrow\\i_\infty$"))
    

    本人电脑上的运行效果:

    Python代码执行结果
    以上是笔者在Jyputer Notebook中绘制含公式表格的过程。得到了想要的清晰表格的同时,感慨于Jupyter Notebook和Latex的强大功能。
    此外值得一提的是,在Office软件中也已支持公式的直接输入(非Mathtype!),对于一些简单的公式可利用快捷键"Alt+="插入。有兴趣的同学可移步如何在 Word 和 PowerPoint 中优雅地插入 Latex 公式进一步了解。
    参考资料

    相关文章

      网友评论

        本文标题:在Jyputer Notebook中用Latex生成含公式表格

        本文链接:https://www.haomeiwen.com/subject/hwktpqtx.html