问题

软件 >> TeX >> PGF
Questions in category: PGF (PGF).

TiKZ 简介

Posted by haifeng on 2011-08-18 16:55:52 last update 2011-08-18 22:22:04 | Answers (0) | 收藏


TikZ 是 PGF 中的一个宏包, 用于绘图. TikZ 跟 Unix 一样, 意思是 TikZ ist kein Zeichenprogramm. 它们都是由 Till Tantau 教授所开发的. TikZ 是 PGF 的前端, 提供了比较简单的语法, 使得相对于 PGF 来得更为好用.

下面是在 LaTeX 中使用 TikZ 作图的一个例子

LaTeX

\documentclass{article}
\usepackage{tikz}
\begin{document}
We are working on
\begin{tikzpicture}
\draw (-1.5,0) -- (1.5,0);%从点(-1.5,0)至(1.5,0)画一条直线, -- 表示直线
\draw (0,-1.5) -- (0,1.5);
\end{tikzpicture}.
\end{document}

这里的坐标是相对于一个特殊坐标系的, 1 代表了 1cm.

如果仅是一个 \draw 命令, 则也可以使用下面的 \tikz 命令,

\tikz \draw (-1.5,0) -- (1.5,0);%
% 等价于\r
\tikz{\draw (-1.5,0) -- (1.5,0)}%将{}中的内容作为参数
事实上, \tikz 将直到下一个分号之间内容或上面{}中的内容放入
\begin{tikzpicture}
\end{tikzpicture}
环境中.

Plain TeX

%% Plain TeX file
\input tikz.tex
\baselineskip=12pt
\hsize=6.3truein
\vsize=8.7truein
We are working on
\tikzpicture
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\endtikzpicture.
\bye

可以使用下面任一种方式生成 pdf 文件.

  • pdftex
  • tex-->dvips-->ps2pdf
  • tex-->dvipdfm

ConTeXt

%% ConTeXt file
\usemodule[tikz]
\starttext
We are working on
\starttikzpicture
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\stoptikzpicture.
\stoptext


References:
Till Tantau, The TikZ and PGF packages --- Manual for Version 2.00
http://sourceforge.net/projects/pgf