如何将 TikZ 图形导出为 SVG
如果你有 TikZ 图形,你可以使用 LaTeX standalone 包使页面适应内容:
tikz_standalone_example.tex
% 最小 TikZ standalone 示例
\documentclass[tikz, border=1mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) node [] {My text};
\end{tikzpicture}
\end{document}假设你已将该文件保存为 MyDiagram.tex,你可以将其转换为 PDF,然后使用以下命令将该 PDF 转换为 SVG
convert_to_svg.sh
pdflatex MyDiagram.tex
pdf2svg MyDiagram.pdf MyDiagram.svg这将生成此 SVG:
注意内容周围的 1mm 边框是有意的,对于大多数用例推荐使用。背景默认透明(但在此博客文章的 HTML 中已设置为白色以说明 SVG 的范围)。
你也可以使用此 Makefile 模板:
Makefile
%.pdf: %.tex
pdflatex $<
%.svg: %.pdf
pdf2svg $< $@
all: MyDiagram.svg它允许你自动为一个或多个 TeX 文件运行命令。
Check out similar posts by category:
LaTeX
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow