我想在乳胶中绘制以下图片。请帮忙。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
[scale=.9,auto=center,every node/.style={circle,fill=blue!20}] % here, node/.style is the style pre-defined, that will be the default layout of all the nodes. You can also create different forms for different nodes.
\node (a1) at (1,2) {1};
\node (a2) at (2,5) {2}; % These all are the points where we want to locate the vertices. You can create your diagram first on a rough paper or graph paper; then, through the points, you can create the layout. Through the use of paper, it will be effortless for you to draw the diagram on Latex.
\node (a3) at (3,7) {3};
\node (a4) at (3,2.5) {4};
\draw (a1) -- (a2); % these are the straight lines from one vertex to another
\draw (a2) -- (a3);
\draw (a2) -- (a4);
\draw (a1) -- (a3);
\draw (a1) -- (a4);
\end{tikzpicture}
\end{document}
答案1
这是我的建议。我使用n
带有参数的样式来表示具有不同颜色的节点。turn
关键是创建坐标O5t
,O6t
用虚线连接。
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\tikzset{
n/.style={circle,fill=#1,inner sep=1.5pt},
n/.default=cyan
}
\path
(0,0) node[n=red] (q) {} node[below=1mm] {$q$}
(1.5,0) node[n] (O6) {} node[below right] {$O_6$}
(.5,2) node[n] (O5) {} node[above right] {$O_5$}
(-1.5,0) node[n] (O4) {} node[below=1mm] {$O_4$}
(-4,0) node[n] (O3) {} node[below left] {$O_3$}
(-3,2) node[n] (O2) {} node[above=2mm] {$O_2$}
(-5,2.5) node[n] (O1) {} node[above left] {$O_1$}
;
\draw[cyan,very thick] (O1)--(O2)--(O3)--(O4)--(O2)--(O5) (O4)--(O5)--(O6);
\foreach \p/\q in {O1/O2,O2/O5,O5/O6} {
\path
(\q)--(\p)--([turn]-90:.2) coordinate (t\p)
(\p)--(\q)--([turn]90:.2) coordinate (t\q);
\draw[cyan,thick,densely dashed,-latex,shorten >=2pt,shorten <=2pt] (t\p)--(t\q);
}
\end{tikzpicture}
\end{document}
答案2
像这样:
\documentclass[margin=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture} [
arr/.style = {-Straight Barb, dashed, shorten >=4mm, shorten <=4mm},
dot/.style = {circle,fill=#1, inner sep=2pt, outer sep=0pt,
node contents={}},
dot/.default = cyan,
every edge/.append style = {draw=cyan, arr},
every label/.append style = {text=black},
xs/.style = {xshift=1mm},
ys/.style = {yshift=1mm}
]
\draw[cyan, semithick]
(0,3) node (a1) [dot, label=$O_1$] --
(2,2) node (a2) [dot, label=$O_4$] --
(5,2) node (a5) [dot, label=$O_5$] --
(6,0) node (a6) [dot, label=below:$O_6$]
(0,0) node (a3) [dot, label=below:$O_3$] --
(3,0) node (a4) [dot, label=below:$O_4$] --
(a5)
(a3) -- (a2) -- (a4);
\path (5,0) node[dot=red, label=below:$q$];
\draw ([ys] a1.north) edge ([ys] a2.north)
([ys] a2.north) edge ([ys] a5.north)
([xs] a5.east) edge ([xs] a6.east);
\end{tikzpicture}
\end{document}