这应该是一件容易的事,但不知何故我感到困惑,因此我想举一个例子
\documentclass[11pt]{report}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{bayesnet}
\begin{document}
\begin{figure}
\centering
\tikz{ %
\node[latent] (phi) {$\phi$};
\node[latent, right=of phi] (f) {$f$};
\node[obs, right=of f] (y) {$\bf{y}$};
\node[latent, above =of f] (sigma) {$\sigma_y$};
\edge {phi} {f};
\edge {f, sigma} {y};
}
\end{figure}
\end{document}
我在 Windows 上使用 TeXstudio,我想生成图像文件(比如 .eps)而不是 pdf。
答案1
根据我从 tikz 导出 eps 的经验,我对结果并不十分满意。大多数情况下,如果我需要 tikz 中的矢量图形,我会将其编译为 pdf 并使用它(或转换为 svg,例如使用 Inkscape)。如果您只需要一张图片,您可以使用 ImageMagick 将其转换为 png。
为了我自己的目的,我创建了一个ImageExport.tex
文件:
%% Usage for eps-pictures
% Warning: Quality of text seems to be awful with eps...
% Use this documentclass instead of the one below
% \documentclass{standalone}
% Step 1: Include the tikzpicture below, adjust the used packages if needed
% Step 2: Compile to standard pdf, you should receive the image as pdf cropped to the drawing
% Step 3: Run `pdftops -eps ImageExport.pdf`
% Step 4: Rename the resulting eps file accordingly, use it!
% If some app doesn't want to include the graphic correctly, try running `pdftops -level1 -eps ImageExport.pdf` or `pdftops -level2 -eps ImageExport.pdf`
%% Usage for png-pictures
% Needs ImageMagick (http://www.imagemagick.org/script/index.php) and for Windows also Ghostscript (http://ghostscript.com/download/gsdnld.html, 32bit)
% Step 1: Include the tikzpicture below, adjust the used packages if needed
% Step 2: Compile like always but be sure to use the `--shell-escape` option. Ignore errors like "Undefined control sequence \HyperFirstAtBeginDocument"
% Step 3: Rename the resulting png file accordingly, use it!
\documentclass[convert={convertexe={magick}}]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc,...}
\begin{document}
\input{my/tikz/graphic.tex}
\end{document}