我正在使用tikz在乳胶中绘制图表,然后我想将其隔离为图像文件以在线放置。我的猜测是有一种直接提取这些图的方法,而无需从完成的.pdf文件中取出这些图。我该怎么做? (如果很重要,我正在使用TexnicCenter。)

有帮助吗?

解决方案

跟进我的评论: Cirkuit 通过运行类似以下命令序列的内容,将Tikz图转换为图像:

pdflatex img.tex
pdftops -eps img.pdf
convert -density 300 img.eps img.png

这里 img.tex 将是遵循此模板的乳胶文件:

\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}

如果您能够使用Cirkuit或类似的编辑器,或为自己编写脚本以将图表放入该模板中并运行适当的工具,那么您将有一种快速的方法将TIKZ代码转换为PNG图像。

更直接地回答您的问题...不,我不知道转换Tikz图的任何方法 直接地 在某个阶段,无需浏览PDF文件(或至少DVI)而无需浏览PNG。

其他提示

我建议您采用以下方法。将Tikz图片放在单独的文件中,并使用“独立”类独立编译。它使用其他答案中提到的“预览”软件包。在主文档中包括图片加载“独立” 包裹 首先,在图片文件上使用输入。

这将使您可以在没有边距的情况下获得Tikz图片的单个PDF。然后,您可以使用pdf-to-sues PNG转换器获取PNG(建议用于图纸的网络发布)。 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}

主要文档:

\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}

然后对图片进行编译并将其转换,例如使用ImageMagick(例如Linux下):

pdflatex pic
convert -density 600x600 pic.pdf -quality 90 -resize 800x600 pic.png

或尝试SVG:

convert pic.pdf pic.svg

请参阅《 TIKZ手册》部分“外部化图形”。这使您可以制作图形的EPS或PDF版本。我使用EPS文件,将其转换为TIFF,然后可以将它们放在我需要的任何地方。

我通常使用这些行:

\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}

生成的PDF文件包含独立的Tikz图片。要将其转换为任何其他文件格式,只需使用GIMP打开它。

我用它来使file规则创建png文件和缩略图。它的工作类似于创建图像 Texamples.net:

%.png: %.tex
        @sed 's/^\\begin{document}/\
\\pgfrealjobname{dummy}\\begin{document}\\beginpgfgraphicnamed{example}/' $< | \
sed 's/^\\end{document}/\\endpgfgraphicnamed\\end{document}/' > example.tex ; \
        pdflatex --jobname=example example.tex ; \
        gs -dNOPAUSE -r120 -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sDEVICE=png16m \
-sOutputFile=$@ -dBATCH example.pdf ; \
        convert -thumbnail 200 $@ $(addsuffix .thumb.png, $(basename $@)) ; \
        mv example.pdf $(addsuffix .pdf, $(basename $<)) ; rm example.*

ghostview(gs)可能会取代 convert 您可以替换 example 有另一个tempfile前缀。

Windows:只是为像我这样的菜鸟完全明确

如上述乳胶代码中的HABI所建议的那样,请使用prewiew软件包来删除保证金。

安装Miktex和Inkscape并使用以下BAT文件:

cd = "C:\Path to tex"
pdflatex input-file-name.tex
"C:\Program Files (x86)\Inkscape\inkscape.exe" input-file-name.pdf --export-plain-svg=output-file-name.svg
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top