TIKZ是LaTeX的一个绘图包,可以绘制其他软件很难画出来的图像。以下是基本用法
代码一:
\documentclass{article} \usepackage{tikz} \usetikzlibrary{arrows.meta}%画箭头用的包 \begin{document} \begin{tikzpicture} \draw[->] (0,0)--(7,0); \draw[->] (0,0)--(0,7); %箭头线 \draw[red] (2,1) -| (1,2);%直角1 \draw[blue] (2,1)|-(1,2);%直角2 \draw[green] (2,2) circle (1);%圆 \draw[black] (4,4) ellipse (1 and 3);%椭圆:短、长半轴 \draw[yellow] (3,3) rectangle (4,1);%矩形 \draw[orange] (0,0) -- (2,1-|1,2);%找到垂点并与(0,0)连线 \draw[purple] (0,1)--(1,1.5)--(0,2)--cycle %封闭的线段 (0,2)--(1,3);%不加分号的连写 \end{tikzpicture} \end{document}
效果图一:
代码二:
\documentclass{article} \usepackage{tikz} \usetikzlibrary{arrows.meta}%画箭头用的包 \begin{document} \begin{tikzpicture} \draw[->] (0,0)--(7,0); \draw[->] (0,0)--(0,7); %箭头线 \draw[red] (3,2) arc (0:120:1);%圆弧:起始点,开始角度:结束角度:半径 \draw[blue] (3,2) arc (0:120:1 and 2);%椭圆弧 \draw[green] (0,0) sin (3,1) cos (5,0);%画pi/2的正弦、余弦 \draw[orange] (3,3)..controls (4,4)and(5,5) .. (4,3); %贝塞尔曲线:起点..controls 控制点 and 控制点..终点 \end{tikzpicture} \end{document}
效果图二:
代码三:
\documentclass{article} \usepackage{tikz} \usetikzlibrary{arrows.meta}%画箭头用的包 \begin{document} \begin{tikzpicture} \draw[help lines,step = 0.5] (-3,-3) grid (3,3); %辅助线格子 \draw[-latex] (-4,0) -- (4,0); \draw[-latex] (0,-4) -- (0,4);%实心箭头 \draw[domain = -2:360][samples = 200] plot({cos(\x)}, {0.5*sin(\x)});%函数图像,参数方程,内有小括号,外面必须用花括号括起来,samples是画函数图时列出的点 \filldraw[fill = yellow,draw = blue][ultra thick] (2,2) circle (1);%填色,还可以设置线宽 \end{tikzpicture} \end{document}
效果图三:
代码四:
\documentclass{article} \usepackage{tikz} \usetikzlibrary{arrows.meta}%画箭头用的包 \begin{document} \begin{tikzpicture}[>=Stealth]%设置箭头,环境中所有箭头都用这个库 \draw[->] (-4,0) -- (4,0); \draw[->>] (0,-4) -- (0,4); \draw(-3,2)--(-3,3)[rounded corners = 0.3cm] -- (-2,3)--(-1.5,2)[sharp corners]--(-2.5,1)--cycle;%圆角多边形 \draw[help lines](0,0) rectangle (1,1);%辅助线 \draw[scale=1.5] (0,0) rectangle (1,1);%缩放 \draw[rotate=30] (0,0) rectangle (1,1);%扰起点旋转 \draw[help lines](2,0) rectangle (3,1); \draw[shift={(0.5,0.5)}](2,0) rectangle (3,1);%平移 \draw[help lines](4,0) rectangle (5,1); \draw[xslant=0.4](4,0) rectangle (5,1);%倾斜 \end{tikzpicture} \end{document}
效果图四:
代码五: