如何画三个有节点的平面图形

如何画三个有节点的平面图形

我对 Latex 还比较陌生,因此请求有人协助提供绘制三个图形的代码(见附图):
在此处输入图片描述

以下是 MWE:

\documentclass[12pt]{article}
\usepackage{syntonly}
\usepackage{geometry}
\usepackage{graphicx,color}
\usepackage{epstopdf,bm}
\usepackage{fancyhdr,multirow,array,tikz,color,rotating}
\usetikzlibrary{arrows.meta,arrows,positioning}
\tikzset{main node/.style={circle,fill=blue!20,draw,minimum size=1cm,inner sep=0pt},}

\begin{document}
\begin{tikzpicture}
\node[main node] (i) {$i$};
\node[main node] (j) [below left = 2.3cm and 1.5cm of i]  {$j$};
\node[main node] (k) [below right = 2.3cm and 1.5cm of i] {$k$};

\path[draw,thick]
%(i) edge node {} (j)
(j) edge node {} (k)
;
%%
\begin{scope}[xshift=5.9cm]
\node[main node] (k) {$k$};
\node[main node] (j) [below left = 2.3cm and 1.5cm of k]  {$j$};
\node[main node] (i) [below right = 2.3cm and 1.5cm of k] {$i$};

\path[draw,thick]
(j) edge node {} (i)
;
\end{scope}

\begin{scope}[xshift=11.9cm]
\node[main node] (j) {$j$};
\node[main node] (i) [below left = 2.3cm and 1.5cm of j]  {$i$};
\node[main node] (k) [below right = 2.3cm and 1.5cm of j] {$k$};

\path[draw,thick]
(i) edge node {} (k)
;
\end{scope}

\end{tikzpicture}
\end{document}

答案1

编辑: 像这样?

可能的期望输出

使用subcaption包和交叉点坐标进行线路驱动(% <---在代码中用 标记)。使用quotes现在添加了边标签$x_i$$y_i$

\documentclass[12pt]{article}
\usepackage{syntonly}
\usepackage{geometry}

\usepackage{caption}
\usepackage{subcaption}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning,
                quotes}             % <--- added
\tikzset{node distance = 13mm and 11mm,
           C/.style = {circle,draw, fill=blue!20,
                       minimum size=1cm, inner sep=0pt},
         dot/.style = {circle, fill=black, inner sep=2pt,
                       node contents={} },,
         every edge quotes/.style = {auto, font=\small} % <--- added
        }

\begin{document}
    \begin{figure}[ht]
    
\begin{subfigure}[b]{0.3\textwidth}
\caption{}
\label{subfig:1}
    \begin{tikzpicture}
\node (j) [C, label=$j$] {};
\node [dot];
\node (i) [C, below right = of j, label=below:$i$] {};
\node (k) [C, above right = of i, label=$k$] {};
%
\draw[thick]    (i |- j) to ["$y_i$"] (i)               % <--- changed
                (j.center) to [pos=0.6, "$x_i$"] (k);   % <--- changed
    \end{tikzpicture}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\caption{}
\label{subfig:2}
    \begin{tikzpicture}
\node (j) [C, label=$j$] {};
\node [dot];
\node (i) [C, below right = of j, label=below:$i$] {};
\node (k) [C, above right = of i, label=$k$] {};
%
\draw[thick]    (i |- j) to ["$y_i$"] (i)               % <--- changed
                (j.center) to [pos=0.6, "$x_i$"] (k);   % <--- changed
    \end{tikzpicture}
\end{subfigure}
\hfill
\begin{subfigure}[b]{0.3\textwidth}
\caption{}
\label{subfig:3}
    \begin{tikzpicture}
\node (j) [C, label=$j$] {};
\node [dot];
\node (i) [C, below right = of j, label=below:$i$] {};
\node (k) [C, above right = of i, label=$k$] {};
%
\draw[thick]    (i |- j) to ["$y_i$"] (i)               % <--- changed
                (j.center) to [pos=0.6, "$x_i$"] (k);   % <--- changed
    \end{tikzpicture}
\end{subfigure}

\caption{Three graphs}
\label{fig:figure}
    \end{figure}
\end{document}

相关内容