我正在使用TikZ在LaTeX中绘制图表,然后我想将其隔离为图像文件以进行在线.我的猜测是有一种方法可以直接提取这些图表,而无需从完成的.pdf文件中取出它们.我该怎么做呢?(如果重要,我正在使用TeXnicCenter.)
Mar*_*rer 60
我会向您推荐以下方法.将tikz图片放在一个单独的文件中,并使用'standalone'类独立编译它.它使用其他答案中提到的"预览"包.要将图片包含在主文档中,首先加载'standalone' 包,然后在图片文件中使用\ input.
这将允许您获得没有边距的tikz图片的单个PDF.然后,您可以使用PDF-to-say PNG转换器来获取PNG(建议用于图纸的Web发布).SVG格式会更好,因为它是矢量格式,但并非所有浏览器都能显示它.
这里有一些示例代码:
tikz图片文件(例如'pic.tex'):
\documentclass{standalone}
\usepackage{tikz}
% all other packages and stuff you need for the picture
%
\begin{document}
\begin{tikzpicture}
% your picture code
\end{tikzpicture}
\end{document}
Run Code Online (Sandbox Code Playgroud)
主要文件:
\documentclass{article} % or whatever class you are using
\usepackage{standalone}
\usepackage{tikz}
% All other packages required
\begin{document}
% Text text text
% somewhere where you want the tikz picture
\input{pic}
% Text text text
\end{document}
Run Code Online (Sandbox Code Playgroud)
然后编译图片并将其转换,例如使用ImageMagick(例如在Linux下):
pdflatex pic
convert -density 600x600 pic.pdf -quality 90 -resize 800x600 pic.png
Run Code Online (Sandbox Code Playgroud)
或尝试SVG:
convert pic.pdf pic.svg
Run Code Online (Sandbox Code Playgroud)
Dav*_*d Z 25
跟进我的评论:Cirkuit通过运行类似以下命令序列的方式将TikZ图表转换为图像:
pdflatex img.tex
pdftops -eps img.pdf
convert -density 300 img.eps img.png
Run Code Online (Sandbox Code Playgroud)
这img.tex是一个遵循此模板的LaTeX文件:
\documentclass{article}
\usepackage{tikz,amsmath,siunitx}
\usetikzlibrary{arrows,snakes,backgrounds,patterns,matrix,shapes,fit,calc,shadows,plotmarks}
\usepackage[graphics,tightpage,active]{preview}
\PreviewEnvironment{tikzpicture}
\PreviewEnvironment{equation}
\PreviewEnvironment{equation*}
\newlength{\imagewidth}
\newlength{\imagescale}
\pagestyle{empty}
\thispagestyle{empty}
\begin{document}
\begin{tikzpicture}
% (your TikZ code goes here)
\end{tikzpicture}
\end{document}
Run Code Online (Sandbox Code Playgroud)
如果您能够使用Cirkuit或类似的编辑器,或者为自己编写脚本以将图表放入该模板并运行相应的工具,您将可以快速将TikZ代码转换为PNG图像.
更直接地回答你的问题...不,我不知道有什么方法可以将TikZ图直接转换为PNG,而无需在某个阶段通过PDF文件(或至少是DVI).
我通常使用这些方面的东西:
\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
%\setlength\PreviewBorder{2mm} % use to add a border around the image
\usepackage{tikz}
\begin{document}
\begin{preview}
\begin{tikzpicture}
\shade (0,0) circle(2); % background
\draw (0,0) circle(2); % rim
\draw (.75,1) circle(.5); % right eye
\fill (.66,.9) circle(.25); % right pupil
\draw (-.75,1) circle(.5); % left eye
\fill (-.66,.9) circle(.25);% left pupil
\fill (.2,0) circle (.1); % right nostril
\fill (-.2,0) circle (.1); % left nostril
\draw (-135:1) arc (-135:-45:1) -- cycle; % mouth
\end{tikzpicture}
\end{preview}
\end{document}
Run Code Online (Sandbox Code Playgroud)
生成的pdf文件包含独立的TikZ图片.要将其转换为任何其他文件格式,只需使用Gimp打开它.
| 归档时间: |
|
| 查看次数: |
45321 次 |
| 最近记录: |