Latex常用原创
# 矩阵
点击查看
$$
\begin{equation}
A_1=\left[ \begin{array}{cccc} %{c c c}表示矩阵中数据的位置,c为剧中,l为靠左,r为靠右。
0 & 1 & 1 & 0\\
0 & 0 & 0 & 0\\
0 & 0 & 0 & 0\\
1 & 0 & 0 & 0\\
\end{array}
\right ]
\qquad
A_2=\left[ \begin{array}{cccc}
0 & 1 & 1 & 0\\
0 & 0 & 0 & 0\\
0 & 0 & 0 & 0\\
1 & 0 & 0 & 0\\
\end{array}
\right ]
\qquad
A_2=\left[ \begin{array}{cccc}
0 & 1 & 1 & 0\\
0 & 0 & 0 & 0\\
0 & 0 & 0 & 0\\
1 & 0 & 0 & 0\\
\end{array}
\right ]
\end{equation}
$$
# 邻接表
点击查看
\documentclass[dvisvgm]{standalone} %生成使用dvisvgm生成SVG,需要配合standalone(文档类使用)
\usepackage{tikz} %导言区调用tikz宏包
\usetikzlibrary{calc,matrix,decorations.markings,decorations.pathreplacing}
\usetikzlibrary{arrows,shapes,chains}
\begin{document}
\begin{tikzpicture}[nodes in empty cells,
nodes={minimum width=0.7cm, minimum height=0.6cm}]
\node(0){0};
\node[draw,rectangle,node distance=0.7cm,right of=0,minimum height=0.8cm](n0){$V_1$} ;
\node[rectangle,draw,right of=n0,node distance=0.7cm,minimum height=0.8cm](n1){};
\node[rectangle,draw,right of=n1](n2){1};
\node[rectangle,draw, right of=n2,node distance=0.7cm](n3){10};
\node[rectangle,draw,right of=n3,node distance=0.7cm](n4){};
\node[rectangle,draw, right of=n4](n5){3};
\node[rectangle,draw, right of=n5,node distance=0.7cm](n6){4};
\node[rectangle,draw,right of=n6,node distance=0.7cm](n7){};
\node[rectangle,draw, right of=n7](n8){4};
\node[rectangle,draw, right of=n8,node distance=0.7cm](n9){12};
\node[rectangle,draw, right of=n9,node distance=0.7cm](n10){$\wedge$};
\draw[-latex] (n1.center) -- (n2.west);
\draw[-latex] (n4.center) -- (n5.west);
\draw[-latex] (n7.center) -- (n8.west);
\node(1)[node distance=0.8cm,below of=0]{1};
\node[draw,rectangle,node distance=0.7cm,right of=1,minimum height=0.8cm](n10){$V_2$} ;
\node[rectangle,draw,right of=n10,node distance=0.7cm,minimum height=0.8cm](n11){};
\node[rectangle,draw,right of=n11](n12){0};
\node[rectangle,draw, right of=n12,node distance=0.7cm](n13){10};
\node[rectangle,draw,right of=n13,node distance=0.7cm](n14){};
\node[rectangle,draw, right of=n14](n15){2};
\node[rectangle,draw, right of=n15,node distance=0.7cm](n16){15};
\node[rectangle,draw,right of=n16,node distance=0.7cm](n17){};
\node[rectangle,draw, right of=n17](n18){3};
\node[rectangle,draw, right of=n18,node distance=0.7cm](n19){8};
\node[rectangle,draw,right of=n19,node distance=0.7cm](n110){};
\node[rectangle,draw, right of=n110](n111){4};
\node[rectangle,draw,right of=n111,node distance=0.7cm](n112){5};
\node[rectangle,draw, right of=n112,node distance=0.7cm](n113){$\wedge$};
\draw[-latex] (n11.center) -- (n12.west);
\draw[-latex] (n14.center) -- (n15.west);
\draw[-latex] (n17.center) -- (n18.west);
\draw[-latex] (n110.center) -- (n111.west);
\node(2)[node distance=0.8cm,below of=1]{2};
\node[draw,rectangle,node distance=0.7cm,right of=2,minimum height=0.8cm](n20){$V_3$} ;
\node[rectangle,draw,right of=n20,node distance=0.7cm,minimum height=0.8cm](n21){};
\node[rectangle,draw,right of=n21](n22){1};
\node[rectangle,draw, right of=n22,node distance=0.7cm](n23){15};
\node[rectangle,draw,right of=n23,node distance=0.7cm](n24){};
\node[rectangle,draw, right of=n24](n25){3};
\node[rectangle,draw, right of=n25,node distance=0.7cm](n26){7};
\node[rectangle,draw,right of=n26,node distance=0.7cm](n27){};
\node[rectangle,draw, right of=n27](n28){4};
\node[rectangle,draw, right of=n28,node distance=0.7cm](n29){30};
\node[rectangle,draw, right of=n29,node distance=0.7cm](n210){$\wedge$};
\draw[-latex] (n21.center) -- (n22.west);
\draw[-latex] (n24.center) -- (n25.west);
\draw[-latex] (n27.center) -- (n28.west);
\node(3)[node distance=0.8cm,below of=2]{3};
\node[draw,rectangle,node distance=0.7cm,right of=3,minimum height=0.8cm](n30){$V_4$} ;
\node[rectangle,draw,right of=n30,node distance=0.7cm,minimum height=0.8cm](n31){};
\node[rectangle,draw,right of=n31](n32){0};
\node[rectangle,draw, right of=n32,node distance=0.7cm](n33){4};
\node[rectangle,draw,right of=n33,node distance=0.7cm](n34){};
\node[rectangle,draw, right of=n34](n35){1};
\node[rectangle,draw, right of=n35,node distance=0.7cm](n36){8};
\node[rectangle,draw,right of=n36,node distance=0.7cm](n37){};
\node[rectangle,draw, right of=n37](n38){2};
\node[rectangle,draw, right of=n38,node distance=0.7cm](n39){7};
\node[rectangle,draw,right of=n39,node distance=0.7cm](n310){};
\node[rectangle,draw, right of=n310](n311){4};
\node[rectangle,draw,right of=n311,node distance=0.7cm](n312){6};
\node[rectangle,draw, right of=n312,node distance=0.7cm](n313){$\wedge$};
\draw[-latex] (n31.center) -- (n32.west);
\draw[-latex] (n34.center) -- (n35.west);
\draw[-latex] (n37.center) -- (n38.west);
\draw[-latex] (n310.center) -- (n311.west);
\node(4)[node distance=0.8cm,below of=3]{4};
\node[draw,rectangle,node distance=0.7cm,right of=4,minimum height=0.8cm](n40){$V_5$} ;
\node[rectangle,draw,right of=n40,node distance=0.7cm,minimum height=0.8cm](n41){};
\node[rectangle,draw,right of=n41](n42){0};
\node[rectangle,draw, right of=n42,node distance=0.7cm](n43){12};
\node[rectangle,draw,right of=n43,node distance=0.7cm](n44){};
\node[rectangle,draw, right of=n44](n45){1};
\node[rectangle,draw, right of=n45,node distance=0.7cm](n46){5};
\node[rectangle,draw,right of=n46,node distance=0.7cm](n47){};
\node[rectangle,draw, right of=n47](n48){2};
\node[rectangle,draw, right of=n48,node distance=0.7cm](n49){30};
\node[rectangle,draw,right of=n49,node distance=0.7cm](n410){};
\node[rectangle,draw, right of=n410](n411){3};
\node[rectangle,draw,right of=n411,node distance=0.7cm](n412){6};
\node[rectangle,draw, right of=n412,node distance=0.7cm](n413){$\wedge$};
\draw[-latex] (n41.center) -- (n42.west);
\draw[-latex] (n44.center) -- (n45.west);
\draw[-latex] (n47.center) -- (n48.west);
\draw[-latex] (n410.center) -- (n411.west);
\end{tikzpicture}
\end{document}
# 排列树
n=3的排列树
点击查看
\documentclass[dvisvgm]{standalone} %生成使用dvisvgm生成SVG,需要配合standalone(文档类使用)
\usepackage{tikz} %导言区调用tikz宏包
\usetikzlibrary{calc,matrix,decorations.markings,decorations.pathreplacing}
\usetikzlibrary{arrows,shapes,chains}
\begin{document}
\begin{tikzpicture}[level/.style={sibling distance=40mm/#1}]
\node [circle,draw]{$A$}
child{node[circle,draw]{$B$}child{node[circle,draw]{$E$}child{node[circle,draw]{$K$}}}child{node[circle,draw]{$F$}child{node[circle,draw]{$L$}}}}
child{node[circle,draw]{$C$}child{node[circle,draw]{$G$}child{node[circle,draw]{$M$}}}child{node[circle,draw]{$H$}child{node[circle,draw]{$N$}}}}
child{node[circle,draw]{$D$}child{node[circle,draw]{$I$}child{node[circle,draw]{$J$}}}child{node[circle,draw]{$O$}child{node[circle,draw]{$P$}}}};
\end{tikzpicture}
\end{document}
# 图
# 无向图
点击查看
\documentclass[dvisvgm]{standalone} %生成使用dvisvgm生成SVG,需要配合standalone(文档类使用)
\usepackage{tikz } %导言区调用tikz宏包
\usetikzlibrary{graphs, arrows}
\begin{document}
\begin{tikzpicture}[> = stealth, % arrow head style
shorten > = 1pt, % don't touch arrow head to node
auto,
node distance = 3cm, % distance between nodes
semithick % line style
,scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
\node (n1) at (0,5) {1};
\node (n2) at (5,5) {2};
\node (n3) at (2.5,2.5) {3};
\node (n4) at (0,0) {4};
\node (n5) at (5,0) {5};
\draw (n1)--(n2);
\draw (n1)--(n4);
\draw (n2)--(n3);
\draw (n2)--(n5);
\draw (n3)--(n4);
\draw (n3)--(n5);
\end{tikzpicture}
\end{document}
# 有向图
点击查看
\documentclass[dvisvgm]{standalone} %生成使用dvisvgm生成SVG,需要配合standalone(文档类使用)
\usepackage{tikz } %导言区调用tikz宏包
\usetikzlibrary{graphs, arrows}
\begin{document}
\begin{tikzpicture}[> = stealth, % arrow head style
shorten > = 1pt, % don't touch arrow head to node
auto,
node distance = 3cm, % distance between nodes
semithick % line style
,scale=.8,auto=left,every node/.style={circle,fill=blue!20}]
\node (n1) at (0,5) {1};
\node (n2) at (5,5) {2};
\node (n3) at (0,0) {3};
\node (n4) at (5,0) {4};
\draw [->](n1)--(n2);
\draw [->](n4)--(n1);
\draw [->](n1)--(n3);
\draw [->](n3)--(n4);
\end{tikzpicture}
\end{document}
\end{document}
# 完全图
点击查看
\documentclass[dvisvgm]{standalone} %生成使用dvisvgm生成SVG,需要配合standalone(文档类使用)
\usepackage{tikz} %导言区调用tikz宏包
\usetikzlibrary{graphs,graphs.standard} %调用graphs和graphs.standard库
\begin{document}
\begin{tikzpicture}[thick]
\graph[n=12,clockwise,radius=3cm,empty nodes,%表示该完全图有12个顶点,将它们顺时针均匀排列在半径为3cm的圆周上,顶点为空的点,即不显示表示顶点的数字;
nodes={draw,circle,fill=green!70!black}]% 表示用顶点的形状化成圆形,并用70%绿色混合30%黑色来填充顶点。
{
subgraph K_n
};
\end{tikzpicture}
\end{document}
# 空图
点击查看
\documentclass[dvisvgm]{standalone} %生成使用dvisvgm生成SVG,需要配合standalone(文档类使用)
\usepackage{tikz} %导言区调用tikz宏包
\usetikzlibrary{graphs,graphs.standard} %调用graphs和graphs.standard库
\begin{document}
\tikz[thick]\graph[nodes={draw,circle,
inner sep=0pt,minimum size=3.1mm,
fill=red!20,as=},radius=0.8cm,clockwise,n=5]
{
subgraph I_n[name=inner]--[complete bipartite]
subgraph I_n [name=outer]
};
\end{document}
# 轮图
点击查看
\documentclass[dvisvgm]{standalone} %生成使用dvisvgm生成SVG,需要配合standalone(文档类使用)
\usepackage{tikz} %导言区调用tikz宏包
\usetikzlibrary{graphs,graphs.standard} %调用graphs和graphs.standard库
\begin{document}
\tikz[thick]\graph[nodes={draw,circle,
fill=red!20},clockwise,radius=0.75cm,
empty nodes,n=8]
{
subgraph C_n[name=inner]<->[shorten <=1pt,shorten >=1pt]
subgraph C_n[name=outer]
};
\end{document}
# 流程图
点击查看
\documentclass[dvisvgm]{standalone} %生成使用dvisvgm生成SVG,需要配合standalone
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.geometric}
\begin{document}
\begin{tikzpicture}[node distance=10pt]
\node[draw, rounded corners] (start) {Start};
\node[draw, below=of start] (step 1) {Step 1};
\node[draw, below=of step 1] (step 2) {Step 2};
\node[draw, diamond, aspect=2, below=of step 2] (choice) {Choice};
\node[draw, right=30pt of choice] (step x) {Step X};
\node[draw, rounded corners, below=20pt of choice] (end) {End};
\draw[->] (start) -- (step 1);
\draw[->] (step 1) -- (step 2);
\draw[->] (step 2) -- (choice);
\draw[->] (choice) -- node[left] {Yes} (end);
\draw[->] (choice) -- node[above] {No} (step x);
\draw[->] (step x) -- (step x|-step 2) -> (step 2);
\end{tikzpicture}
\end{document}
点击查看
上次更新: 2022/09/12, 23:05:31