LaTeX高效写作系列:word表格转LaTeX

作者: 九天学者 | 来源:发表于2018-09-09 00:49 被阅读20次

    Fancy版本见九天学者的个人博客,关注文集博士干点啥或者微信公众号九天学者及时获取连载更新。


    如何将word表格转为\LaTeX{}格式

    迫于无奈从刚开始学习计算机就上了某软这条贼船,不少情况下,将表格写为了word文件。如果要重新把这些表格再敲一遍\LaTeX{}也未免太累了点,本人是个懒癌患者,能不亲自动手就让计算机帮我做。最方便的就是用万能的文本转换工具pandoc,只有你想不到的,没有它做不到的。一般都集成在anaconda发型版里,作者用的是3.6版本。如果没有,则用pip install pandoc安装即可,非常方便。虽然整个word文档的转换结果不会很完美,但是大体内容都在了,只需要根据自己需要做一些小调整即可。

    • word \to \ \LaTeX{}
    pandoc my.docx -o my.tex
    

    比如我的一个word表格,内容挺多,要是一个一个往\LaTeX里面敲,还是需要费点功夫的。最左边这一列里面有mathtype写的公式,pandoc不识别,会当成空格处理。

    Word Table with Mathtype
    • Pandoc转换结果
      因为word转别的格式本来就很复杂,它有自己的一套格式体系。对于复杂的word文档,如果想一步到位转换为\LaTeX格式,估计不太现实。但是总体还不错,在转换结果上稍微修一修调一调即可。比如上面的word中的表格转换为\LaTeX的结果为:
    \begin{longtable}[]{@{}lll@{}}
      \toprule
      Symbol & Definition & Value/Units\tabularnewline
      \midrule
      \endhead
      & permeability &\tabularnewline
      & initial permeability &\tabularnewline
      & Darcy velocity &\tabularnewline
      \emph{p} & pressure & Pa\tabularnewline
      & gravitational acceleration vector & 9.81\tabularnewline
      & specific heat capacity of fluid &\tabularnewline
      & specific heat capacity of rock & 880\tabularnewline
      & thermal conductivity of rock & 1.5\tabularnewline
      & concentration (mass fraction) of irons &\tabularnewline
      & chemical diffusivity &\tabularnewline
      & apparent solubility product &\tabularnewline
      & effective solubility product &\tabularnewline
      & saturation &\tabularnewline
      \emph{M} & mass & \emph{kg}\tabularnewline
      & mass fraction &\tabularnewline
      & \emph{Greek Symbols}\tabularnewline
      & fluid's dynamic viscosity &\tabularnewline
      & fluid density &\tabularnewline
      & porosity of the rock & 0.1\tabularnewline
      & fluid's expansivity &\tabularnewline
      & fluid's compressibility &\tabularnewline
      & \emph{Subscripts} &\tabularnewline
      \emph{f} & fluid &\tabularnewline
      \emph{r} & rock &\tabularnewline
      \emph{a} & anhydrite &\tabularnewline
      \emph{p} & pyrite &\tabularnewline
      \emph{fap} & fluid, anhydrite and pyrite &\tabularnewline
      \bottomrule
    \end{longtable}
    

    可以看到\begin区域跟前面讲的简单表格不一样了(需要添加相应的库包),虽然这也是个相对简单的表格而已。为简单起见,所以我们只需要稍微做一点小修改即可:把表格内容复制粘贴简单表格框架内,见在线代码\LaTeX编译结果如下图所示,

    转换表格编译结果

    接下来只需要将mathtype公式补全即可,\LaTeX最擅长的就是写公式,补全他五分钟之内绝对没问题。


    如果此文对您有启发,感谢您支持原创: 有钱的动手打个赏,没钱的动手点个赞
    您的鼓励就是我原创的动力。个人水平有限,若有问题,可在下方留言讨论。


    相关文章

      网友评论

        本文标题:LaTeX高效写作系列:word表格转LaTeX

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