赞
踩
TexWorks
,免费,大约占内存
8
G
8G
8G,有点大texdoc tikz
即可显示官方pdf的文档,有
1321
1321
1321 页…\documentclass{article} % 百分号后的为注释,不运行
\usepackage{tikz} % 使用 tikz 包
\begin{document} % 开始文档
We are working on
\begin{tikzpicture} % 对于需要 tikz 绘图的内容,可以这样形式
\draw (-1.5,0) -- (1.5,0); % 命令需要以分号结尾,表示调用 draw 方法,绘制从点 A 到点 B 的线段
\draw (0,-1.5) -- (0,1.5);
\end{tikzpicture}
\tikz \draw (-1.0,-1.0) -- (1.0,1.0); % 或者对于简单的图形,使用 \tikz 单行命令绘制图形
\tikz \draw (0,-1.0) -- (1.0,0);
\end{document}
tikzpicture
是一副图。--
进行绘制路径。\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (-1.5,0) -- (1.5,0) -- (0,-1.5) -- (0,1.5);
\end{tikzpicture}
\end{document}
\filldraw
方法绘制出了其中这四个点\draw A .. controls B and C .. D;
进行绘制曲线,这里起点为A,起点控制点为B,终点控制点为C,终点为D\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\filldraw [gray] (0,0) circle [radius=2pt]
(1,1) circle [radius=2pt]
(2,1) circle [radius=2pt]
(2,0) circle [radius=2pt];
\draw (0,0) .. controls (1,1) and (2,1) .. (2,0);
\end{tikzpicture}
\end{document}
\draw A circle [radius=B];
绘制圆心为A,半径为B的圆,单位可以是
p
t
pt
pt 像素,或者
c
m
cm
cm\draw A ellipse [x radius=B, y radius=C];
绘制椭圆,圆心为A,还有两个半距的长度。[attr = x]
进行赋值,比如使用 [rotate=30]
进行图形旋转30度。\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikz \draw (0,0) circle [radius=10pt];
\tikz \draw (0,0) ellipse [x radius=20pt, y radius=10pt];
\tikz \draw (0,0) circle [radius=1cm];
\end{document}
\draw A rectangle B;
表示绘制对角顶点为A,B的矩形\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (0.5,0.5);
\draw (-0.5,-0.5) rectangle (-1,-1);
\end{tikzpicture}
\end{document}
\draw [step=A] B grid C;
绘制从点B到点C,步长为A的网格。[gray, very thin]
来修改网格线的颜色和粗细\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\draw (0,0) circle [radius=1cm];
\end{tikzpicture}
\end{document}
[gray, very thin]
,每次都说明肯定很麻烦Style_Name/.style={A,B,C……}
可以让 [Style Name]
等价与 [A,B,C,……]
\tikzset{}
中,来让全局可用color=red!50
指颜色为50%的红。\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{MyStyle/.style={color=red!50,very thin}}
\begin{tikzpicture}
\draw [MyStyle] (0,0) circle [radius = 1cm];
\draw (2,0) circle [radius = 1cm];
\end{tikzpicture}
\end{document}
ultra thin, very thin, thin, semithick, thick, very thick, ultra thick
dashed
dotted
loosely XXX, densely XXX
,这里 XXX 为短线或点线\draw A arc[start angle=B, end angle=C, radius=D];
即圆心坐标A,开始角度B,结束角度C,半径Dx radius, y radius
即可。\documentclass{article} \usepackage{tikz} \begin{document} \tikzset{MyStyle/.style={color=red!50,very thin}} \begin{tikzpicture}[scale=3] \draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4); \draw (-1.5,0) -- (1.5,0); \draw (0,-1.5) -- (0,1.5); \draw (0,0) circle [radius=1cm]; \draw (3mm,0mm) arc [start angle=0, end angle=30, radius=3mm]; \end{tikzpicture} \begin{tikzpicture} \tikz \draw (0,0) arc [start angle=0, end angle=315, x radius=1.75cm, y radius=1cm]; \end{tikzpicture} \end{document}
\clip 图形;
语法。这里
图形
图形
图形 可以使用之前的圆,椭圆,矩形等图形。\clip [draw] 图形
语法,绘制并剪切图形\documentclass{article}
\usepackage{tikz}
\tikzset{MyStyle/.style={color=red!50,very thin}}
\begin{document}
\begin{tikzpicture}[scale=3]
\clip [draw] (-0.1,-0.2) rectangle (1.1,0.75);
\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\draw (-1.5,0) -- (1.5,0);
\draw (0,-1.5) -- (0,1.5);
\draw (0,0) circle [radius=1cm];
\draw (3mm,0mm) arc [start angle=0, end angle=30, radius=3mm];
\end{tikzpicture}
\end{document}
\draw A parabola B;
绘制从点A到点B的抛物线\draw A B
绘制从点A到点B的曲线,这里点的坐标使用 sin(x,y)
或 cos(x,y)
来表示\draw A B C D ……
来绘制连续的正弦曲线。\documentclass{article}
\usepackage{tikz}
\tikzset{MyStyle/.style={color=red!50,very thin}}
\begin{document}
\begin{tikzpicture}
\draw (0,0) parabola (1,1);
\end{tikzpicture}
\begin{tikzpicture}
\draw[x=1.57ex,y=1ex] (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0)
(0,1) cos (1,0) sin (2,-1) cos (3,0) sin (4,1);
\end{tikzpicture}
\end{document}
\fill
函数进行填充cycle
作为最后的坐标,可以看下下图两者的区别。\fill[green!20!white]
表示填充使用20%的绿和80%的白。\documentclass{article} \usepackage{tikz} \tikzset{MyStyle/.style={color=red!50,very thin}} \begin{document} \begin{tikzpicture}[line width=5pt] \draw (0,0) -- (1,0) -- (1,1) -- (0,0); \draw (2,0) -- (3,0) -- (3,1) -- cycle; \end{tikzpicture} \begin{tikzpicture}[line width=5pt] \fill (0,0) -- (1,0) -- (1,1) -- (0,0); \fill (2,0) -- (3,0) -- (3,1) -- cycle; \end{tikzpicture} \end{document}
\shade
或者 \shadedraw
来渲染[posA colorA, posB colorB]
来表示过度位置和过度颜色,见下方代码[ball]
表示渲染成球体\documentclass{article}
\usepackage{tikz}
\tikzset{MyStyle/.style={color=red!50,very thin}}
\begin{document}
\begin{tikzpicture}[rounded corners,ultra thick]
\shade[top color=yellow,bottom color=black] (0,0) rectangle +(2,1);
\shade[left color=yellow,right color=black] (3,0) rectangle +(2,1);
\shadedraw[inner color=yellow,outer color=black,draw=yellow] (6,0) rectangle +(2,1);
\shade[ball color=green] (9,.5) circle (.5cm);
\end{tikzpicture}
\end{document}
A rectangle +B
的语法,这里A,B是坐标点。+A
表示当前点的坐标为:上一个指明的点的坐标下x,y的变化量。++A
表示在 +A
的基础上,让该点成为新的指明的点。-A
和 --A
的语法(1,2) rectangle ++(1,2)
等价与 (1,2) rectangle (2,4)
[->]
, [<-]
, [<->]
属性表明绘制箭头的种类,使用一般的 \draw
绘制即可[<<-]
或者 [><>-<><<]
[>=kind of end arrow tip]
来更改箭头的类型,比如使用 arrows.meta
包中 Stealth
,更改箭头类型如下:\documentclass{article} \usepackage{tikz} \usetikzlibrary {arrows.meta} \tikzset{MyStyle/.style={color=red!50,very thin}} \begin{document} \begin{tikzpicture} \draw [<<<<->] (0,0) arc [start angle=180, end angle=30, radius=10pt]; \draw [<->] (1,0) -- (1.5cm,10pt) -- (2cm,0pt) -- (2.5cm,10pt); \end{tikzpicture} \begin{tikzpicture}[>=Stealth] \draw [->] (0,0) arc [start angle=180, end angle=30, radius=10pt]; \draw [<<-,very thick] (1,0) -- (1.5cm,10pt) -- (2cm,0pt) -- (2.5cm,10pt); \end{tikzpicture} \end{document}
\foreach \var in {set} {Do something}
来遍历变量 var
$something$
中两个美元符号中间用来输出 Latex
符号\x
表示变量 x
\foreach
可以嵌套,如下面:\documentclass{article} \usepackage{tikz} \usetikzlibrary {arrows.meta} \tikzset{MyStyle/.style={color=red!50,very thin}} \begin{document} \begin{tikzpicture} \foreach \x in {1,2,3} {$x =\x$, } \end{tikzpicture} \begin{tikzpicture} \foreach \x in {1,2,...,5,7,8,...,12} \foreach \y in {1,...,5} { \draw (\x,\y) +(-.5,-.5) rectangle ++(.5,.5); \draw (\x,\y) node{\x,\y}; } \end{tikzpicture} \end{document}
node
关键词后面会跟着可选内容 []
以及花括号 {补充文本信息}
\draw A node[fill=yellow!80!black]{C}
在点A绘制后,在该位置添加一个文本信息C,使用填充格式[sloped,above]
,[sloped,below]
更改字体在曲线上显示的位置[anchor=north]
更改显示字锚点的基础位置\documentclass{article} \usepackage{tikz} \usetikzlibrary {arrows.meta} \tikzset{MyStyle/.style={color=red!50,very thin}} \begin{document} \begin{tikzpicture} \draw (0,0) rectangle (2,2); \draw (0.5,0.5) node [fill=yellow!80!black] {Text at \verb!node 1!} -- (1.5,1.5) node {Text at \verb!node 2!}; \end{tikzpicture} \begin{tikzpicture} \draw (0,0) .. controls (6,1) and (9,1) .. node[near start,sloped,above] {near start} node {midway} node[very near end,sloped,below] {very near end} (12,0); \end{tikzpicture} \end{document}
\coordinate (A) at B;
表示给定点A,位置为B\coordinate (A) at (B:C)
表示给定点A,位置为角度B处C距离。B为弧度制。AB、BC
,然后使用 pic {angle = A--B--C}
来给定三个点,绘制他们之间的弧线角度。\documentclass{article} \usepackage{tikz} \usetikzlibrary {angles,quotes} \tikzset{MyStyle/.style={color=red!50,very thin}} \begin{document} \begin{tikzpicture}[scale=3] \coordinate (A) at (1,0); \coordinate (B) at (0,0); \coordinate (C) at (30:1cm); \draw (A) -- (B) -- (C) pic [draw=green!50!black, fill=green!20, angle radius=9mm, "$\alpha$"] {angle = A--B--C}; \end{tikzpicture} \end{document}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。