使用pandoc转换Markdown文件(.md)生成pdf

pandoc --latex-engine=xelatex -V CJKmainfont="Noto Sans CJK SC" -s --toc --toc-depth=2 --highlight-style zenburn  --template=pandoc-template.tex -o output.pdf input.md

产生错误:

! Undefined control sequence.
l.180 \toprule

原因:由于markdown文件里面有表格,转换成latex时候需要booktabs包生产表格,安装booktabs包应该可以解决问题。

但ubuntu下MikTex Console安装booktabs package失败,提示服务器错误。可使用如下sty文件,加入Miktex搜索路径问题解决。

Github: booktabs sty文件

%%
%% This is file `booktabs.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% booktabs.dtx (with options: `package')
%%
%% -----------------------------------------------------------------
%% Author: Simon Fear
%% Maintainer: Danie Els (dnjels@sun.ac.za)
%%
%% This file is part of the booktabs package for publication
%% quality tables for LaTeX
%%
%% Copyright (C) 1995--2005 Simon Fear
%%
%% This program is free software; you can redistribute it and/or
%% modify it under the terms of the GNU General Public License as
%% published by the Free Software Foundation; either version 2 of
%% the License, or (at your option) any later version.
%%
%% This program is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%% GNU General Public License for more details.
%%
%% You should have received a copy of the GNU General Public
%% License along with this program; if not, write to the Free
%% Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
%% MA 02111-1307 USA
%% -----------------------------------------------------------------
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{booktabs}
[2005/04/14 v1.61803 publication quality tables]
\newdimen\heavyrulewidth
\newdimen\lightrulewidth
\newdimen\cmidrulewidth
\newdimen\belowrulesep
\newdimen\belowbottomsep
\newdimen\aboverulesep
\newdimen\abovetopsep
\newdimen\cmidrulesep
\newdimen\cmidrulekern
\newdimen\defaultaddspace
\heavyrulewidth=.08em
\lightrulewidth=.05em
\cmidrulewidth=.03em
\belowrulesep=.65ex
\belowbottomsep=0pt
\aboverulesep=.4ex
\abovetopsep=0pt
\cmidrulesep=\doublerulesep
\cmidrulekern=.5em
\defaultaddspace=.5em
\newcount\@cmidla
\newcount\@cmidlb
\newdimen\@aboverulesep
\newdimen\@belowrulesep
\newcount\@thisruleclass
\newcount\@lastruleclass
\@lastruleclass=0
\newdimen\@thisrulewidth
\def\futurenonspacelet#1{\def\@BTcs{#1}%
\afterassignment\@BTfnslone\let\nexttoken= }
\def\@BTfnslone{\expandafter\futurelet\@BTcs\@BTfnsltwo}
\def\@BTfnsltwo{\expandafter\ifx\@BTcs\@sptoken\let\next=\@BTfnslthree
\else\let\next=\nexttoken\fi \next}
\def\@BTfnslthree{\afterassignment\@BTfnslone\let\next= }
\def\toprule{\noalign{\ifnum0=`}\fi
\@aboverulesep=\abovetopsep
\global\@belowrulesep=\belowrulesep %global cos for use in the next noalign
\global\@thisruleclass=\@ne
\@ifnextchar[{\@BTrule}{\@BTrule[\heavyrulewidth]}}
\def\midrule{\noalign{\ifnum0=`}\fi
\@aboverulesep=\aboverulesep
\global\@belowrulesep=\belowrulesep
\global\@thisruleclass=\@ne
\@ifnextchar[{\@BTrule}{\@BTrule[\lightrulewidth]}}
\def\bottomrule{\noalign{\ifnum0=`}\fi
\@aboverulesep=\aboverulesep
\global\@belowrulesep=\belowbottomsep
\global\@thisruleclass=\@ne
\@ifnextchar[{\@BTrule}{\@BTrule[\heavyrulewidth]}}
\def\specialrule#1#2#3{\noalign{\ifnum0=`}\fi
\@aboverulesep=#2\global\@belowrulesep=#3\global\@thisruleclass=\tw@
\@BTrule[#1]}
\def\addlinespace{\noalign{\ifnum0=`}\fi
\@ifnextchar[{\@addspace}{\@addspace[\defaultaddspace]}}
\def\@addspace[#1]{\global\@belowrulesep=#1\global\@thisruleclass=\tw@
\futurelet\@tempa\@BTendrule}
\def\@BTrule[#1]{%
\global\@thisrulewidth=#1\relax
\ifnum\@thisruleclass=\tw@\vskip\@aboverulesep\else
\ifnum\@lastruleclass=\z@\vskip\@aboverulesep\else
\ifnum\@lastruleclass=\@ne\vskip\doublerulesep\fi\fi\fi
\ifx\longtable\undefined
\let\@BTswitch\@BTnormal
\else\ifx\hline\LT@hline
\let\@BTswitch\@BLTrule
\else
\let\@BTswitch\@BTnormal
\fi\fi
\@BTswitch}
\AtBeginDocument{%
\providecommand*\CT@arc@{}}%% colortbl support
\def\@BTnormal{%
{\CT@arc@\hrule\@height\@thisrulewidth}%
\futurenonspacelet\@tempa\@BTendrule}
\def\@BLTrule{\@ifnextchar({\@@BLTrule}{\@@BLTrule()}}
\def\@@BLTrule(#1){\@setrulekerning{#1}%
\global\@cmidlb\LT@cols
\ifnum0=`{\fi}%
\@cmidruleb
\noalign{\ifnum0=`}\fi
\futurenonspacelet\@tempa\@BTendrule}
\def\@BTendrule{\ifx\@tempa\toprule\global\@lastruleclass=\@thisruleclass
\else\ifx\@tempa\midrule\global\@lastruleclass=\@thisruleclass
\else\ifx\@tempa\bottomrule\global\@lastruleclass=\@thisruleclass
\else\ifx\@tempa\cmidrule\global\@lastruleclass=\@thisruleclass
\else\ifx\@tempa\specialrule\global\@lastruleclass=\@thisruleclass
\else\ifx\@tempa\addlinespace\global\@lastruleclass=\@thisruleclass
\else\global\@lastruleclass=\z@\fi\fi\fi\fi\fi\fi
\ifnum\@lastruleclass=\@ne\relax\else\vskip\@belowrulesep\fi
\ifnum0=`{\fi}}
\def\@setrulekerning#1{%
\global\let\cmrkern@l\z@
\global\let\cmrkern@r\z@
\@tfor\@tempa :=#1\do
{\def\@tempb{r}%
\ifx\@tempa\@tempb
\global\let\cmrkern@r\cmidrulekern
\def\cmrsideswitch{\cmrkern@r}%
\else
\def\@tempb{l}%
\ifx\@tempa\@tempb
\global\let\cmrkern@l\cmidrulekern
\def\cmrsideswitch{\cmrkern@l}%
\else
\global\expandafter\let\cmrsideswitch\@tempa
\fi
\fi}}
\def\cmidrule{\noalign{\ifnum0=`}\fi
\@ifnextchar[{\@cmidrule}{\@cmidrule[\cmidrulewidth]}}
\def\@cmidrule[#1]{\@ifnextchar({\@@cmidrule[#1]}{\@@cmidrule[#1]()}}
\def\@@cmidrule[#1](#2)#3{\@@@cmidrule[#3]{#1}{#2}}
\def\@@@cmidrule[#1-#2]#3#4{\global\@cmidla#1\relax
\global\advance\@cmidla\m@ne
\ifnum\@cmidla>0\global\let\@gtempa\@cmidrulea\else
\global\let\@gtempa\@cmidruleb\fi
\global\@cmidlb#2\relax
\global\advance\@cmidlb-\@cmidla
\global\@thisrulewidth=#3
\@setrulekerning{#4}
\ifnum\@lastruleclass=\z@\vskip \aboverulesep\fi
\ifnum0=`{\fi}\@gtempa
\noalign{\ifnum0=`}\fi\futurenonspacelet\@tempa\@xcmidrule}
\def\@xcmidrule{%
\ifx\@tempa\cmidrule
\vskip-\@thisrulewidth
\global\@lastruleclass=\@ne
\else \ifx\@tempa\morecmidrules
\vskip \cmidrulesep
\global\@lastruleclass=\@ne\else
\vskip \belowrulesep
\global\@lastruleclass=\z@
\fi\fi
\ifnum0=`{\fi}}
\def\@cmidrulea{%
\multispan\@cmidla&\multispan\@cmidlb
\unskip\hskip\cmrkern@l%
{\CT@arc@\leaders\hrule \@height\@thisrulewidth\hfill}%
\hskip\cmrkern@r\cr}%
\def\@cmidruleb{%
\multispan\@cmidlb
\unskip\hskip \cmrkern@l%
{\CT@arc@\leaders\hrule \@height\@thisrulewidth\hfill}%
\hskip\cmrkern@r\cr}%
\def\morecmidrules{\noalign{\relax}}
\endinput
%%
%% End of file `booktabs.sty'.

测试环境:
Ubuntu 18.04.1 LTS;
kernel: 4.15.0-106-generic;
MikTex: 2.9.7445

pandoc转换markdown生成pdf文件表格问题的更多相关文章

  1. windows使用Pandoc将Markdown转换为PDF文件

    pandoc下载:https://github.com/jgm/pandoc/releases/tag/1.19.2.1 //windows下载msi文件 miktex下载:https://mikte ...

  2. 利用 Pandoc 将 Markdown 生成 Word/PDF 文件

    Pandoc 是一个格式转化工具,可以用于各(luan)种(qi)各(ba)样(zao)的文件转换, 反正我是认不全官网上的那个图(傲娇脸), 之前一直使用它将 Markdown 文件转换成 Html ...

  3. 办公室文员必备python神器,将PDF文件表格转换成excel表格!

    [阅读全文] 第三方库说明 # PDF读取第三方库 import pdfplumber # DataFrame 数据结果处理 import pandas as pd 初始化DataFrame数据对象 ...

  4. 前端axios请求二进制数据流转换生成PDF文件空白问题(终极解决方案)

    本文章共1570字,预计阅读时间1 - 3分钟. 问题场景: axios请求二进制数据转换生成PDF空白问题,使用axios请求后端接口,后端返回的二进制流文件,需要转换成PDF,但是在postman ...

  5. [轉載]史上最强php生成pdf文件,html转pdf文件方法

    之前有个客户需要把一些html页面生成pdf文件,然后我就找一些用php把html页面围成pdf文件的类.方法是可谓是找了很多很多,什么html2pdf,pdflib,FPDF这些都试过了,但是都没有 ...

  6. 怎么用PHP在HTML中生成PDF文件

    原文:Generate PDF from html using PHP 译文:使用PHP在html中生成PDF 译者:dwqs 利用PHP编码生成PDF文件是一个非常耗时的工作.在早期,开发者使用PH ...

  7. JAVA生成PDF文件

    生成PDF文件是主要应用的是ITEXT插件 import java.awt.Color; import java.io.File; import java.io.FileOutputStream; i ...

  8. 史上最强php生成pdf文件,html转pdf文件方法

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

  9. java调用wkhtmltopdf生成pdf文件,美观,省事

    最近项目需要导出企业风险报告,文件格式为pdf,于是搜了一大批文章都是什么Jasper Report,iText ,flying sauser ,都尝试了一遍,感觉不是我想要的效果, 需要自己调整好多 ...

  10. Itext生成pdf文件

    来源:https://my.oschina.net/lujianing/blog/894365 1.背景 在某些业务场景中,需要提供相关的电子凭证,比如网银/支付宝中转账的电子回单,签约的电子合同等. ...

随机推荐

  1. vue学习笔记(一) ---- vue指令(v-for 和 key 属性)

    vue指令之v-for和key属性 一. v-for 1. v-for遍历数组 <div id="app"> <h3>好饿,我好想吃~~~~</h3& ...

  2. 搭个ChatGPT算法模型,离Java程序员有多远?

    作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! 最近 ChatGPT 很火,火到了各行各业.记得去年更多的还是码农最新体验后拿它搜代码,现在各 ...

  3. ASP.NET Core - .NET 6 的入口文件

    自从.NET 6 开始,微软对应用的入口文件进行了调整,移除了 Main 方法和 Startup 文件,使用顶级语句的写法,将应用初始化的相关配置和操作全部集中在 Program.cs 文件中,如下: ...

  4. Python 内置界面开发框架 Tkinter入门篇 丁

    如需要转载,请声明原文链接微信公众号「ENG八戒」https://mp.weixin.qq.com/s/X5cqennLrq7i1pzBAAqQ2w 本文大概 2562 个字,阅读需花 15 分钟 内 ...

  5. Python 元组列表排序:初学者可能忽视的细节

    P1085 [NOIP2004 普及组] 不高兴的津津 题目描述 津津上初中了.妈妈认为津津应该更加用功学习,所以津津除了上学之外,还要参加妈妈为她报名的各科复习班.另外每周妈妈还会送她去学习朗诵.舞 ...

  6. .NET Core 项目启动时运行定时任务

    1.任务需求 在每次服务启动时定时(如24小时)清理一次缓存文件 2.代码实现 1)新建文件清理类 .NET Core 提供了BackgroundService的抽象类,在 ExecuteAsync ...

  7. 如何使用 ArrayPool

    如果不停的 new 数组,可能会造成 GC 的压力,因此在 aspnetcore 中推荐使用 ArrayPool 来重用数组,本文将介绍如何使用 ArrayPool. 使用 ArrayPool Arr ...

  8. uboot目录

    目录 api 与硬件无关的 API 函数. arch 与架构体系有关的代码. 各种架构,例如arm cpu  各种版本的cpu, 例如armv7, arm9 各种厂商,例如瑞芯微mach-rockch ...

  9. Window10环境下,Stable Diffusion的本地部署与效果展示

    Diffusion相关技术最近也是非常火爆,看看招聘信息,岗位名称都由AI算法工程师变成了AIGC算法工程师,本周跟大家分享一些Diffusion算法相关的内容. Window10环境下,Stable ...

  10. CPU AMX 详解

    CPU AMX 详解 CPU AMX 详解 概述 算力如何 问题定义 AVX如何解决矩阵乘问题 AMX如何解决矩阵乘问题 如何实现的 计算部分 数据部分 路才开始 概述 2016 年开始,随着 NV ...