## 线段和点
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[gray, thick] (-1,2) -- (2,-4); % 画线段:gray和thick确定线颜色和线粗,后面两个坐标确定线段端点
\draw[gray, thick] (-1,-1) -- (2,2);
\filldraw[black] (0,0) circle (2pt) %画点(fill表示填充),black:填充颜色,2pt:半径,两个像素
node[anchor=west]{Intersection point}; % 画一个node(其实是边框),点在边框的west方向,边框内容为Intersection point
\end{tikzpicture}
\end{document}

路径path
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (-2,0) -- (2,0);
\filldraw [gray] (0,0) circle (2pt);
\draw (-2,-2) .. controls (0,0) .. (2,-2); % 绘制Bézier curve:(-2, -2)和(2, -2)为端点,(0, 0)为控制点,可以理解为吸引点,来确定曲线的曲度
\draw (-2,2) .. controls (-1,0) and (1,0) .. (2,2);% 绘制Bézier curve:(-2, 2)和(2, 2)为端点,(-2, 0)和(1, 0)为控制点,可以理解为吸引点,来确定曲线的曲度
\end{tikzpicture}
\end{document}

圆、椭圆和多边形
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\filldraw[color=red!60, fill=red!5, very thick](-1,0) circle (1.5); % 绘制圆,color:圆环颜色60%red;fill:填充颜色;very thick:圆环厚度,(-1, 0)表示圆心坐标,circle:圆的半径
\fill[blue!50] (2.5,0) ellipse (1.5 and 0.5); % 绘制椭圆:
\draw[ultra thick, ->] (6.5,0) arc (0:220:1); % 绘制圆的曲线,->线的尾部加箭头,(6.5, 0)表示起点坐标;arc确定形状,(0:220:1)表示起点角度,终点角度和半径
\end{tikzpicture}
\end{document}
fill和filldraw的区别是一个填充相同颜色,一个可以填充其他颜色,其他部分基本一致
fill[参数]:参数有颜色
filldraw[参数]:参数有color, fill, 边缘厚度
fill/filldraw[...]+中心点+形状(circle/elipse)(形状参数)
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[blue, very thick] (0,0) rectangle (3,2); %绘制矩形:起点坐标(0, 0),长宽:3, 2
\draw[orange, ultra thick] (4,0) -- (6,0) -- (5.7,2) -- cycle; % 多边形:需要多点坐标,cycle表示封闭图形
\end{tikzpicture}
\end{document}
Diagram
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
roundnode/.style={circle, draw=green!60, fill=green!5, very thick, minimum size=7mm}, % minimum size表示图形大小
squarednode/.style={rectangle, draw=red!60, fill=red!5, very thick, minimum size=5mm},
] % 确定不同节点类型,属性
%Nodes 绘制节点
\node[squarednode] (maintopic) {2}; % 绘制2节点,名称为maintopic,是一个方形节点
\node[roundnode] (uppercircle) [above=of maintopic] {1}; % 绘制1节点,是一个圆形节点,above表示在maintopic节点的上方
\node[squarednode] (rightsquare) [right=of maintopic] {3}; % 绘制3节点,是一个方形节点
\node[roundnode] (lowercircle) [below=of maintopic] {4}; % 绘制4节点,是一个圆形节点
%Lines 绘制节点之间的连线
\draw[->] (uppercircle.south) -- (maintopic.north); % 确定起点和终点
\draw[->] (maintopic.east) -- (rightsquare.west);
\draw[->] (rightsquare.south) .. controls +(down:7mm) and +(right:7mm) .. (lowercircle.east); % down和right的表示连接3和4的切线方向
\end{tikzpicture}
\end{document}

上述的相对位置确定是根据right = of ***,位置也可以通过坐标at来确定
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
roundnode/.style={circle, draw=green!60, fill=green!5, very thick, minimum size=7mm},
squarednode/.style={rectangle, draw=red!60, fill=red!5, very thick, minimum size=5mm},
whitesquarednode/.style={rectangle, minimum size=5mm},
scale = 0.8, % 整张图进行缩放
]
%Nodes
\node[squarednode] (maintopic) at (0, 0) {2}; % 用at确定node位置
\node[roundnode] (uppercircle) at (0, 2) {1};
\node[squarednode] (rightsquare) at (2, 0) {3};
\node[roundnode] (lowercircle) at (0, -2) {4};
% \node[whitesquarednode] (5) at (0, -1) {5};
\node[whitesquarednode](label) at (0, -1) {label};
%Lines
\draw[->] (uppercircle.south) -- (maintopic.north);
\draw[->] (maintopic.east) -- (rightsquare.west);
\draw[dashed, green, very thick] (rightsquare.south) .. controls +(down:10mm) and +(right:7mm) .. (lowercircle.east); % dashed:线型
\end{tikzpicture}
\end{document}
1088

被折叠的 条评论
为什么被折叠?



