如何减少图的顶点?

如何减少图的顶点?

我想画出图形。但是它的顶点太粗了。如何才能减小顶点的尺寸?

按照代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,chains,fit,shapes,calc}
\begin{document}
\begin{tikzpicture} [every node/.style={draw,circle},
every fit/.style={ellipse,draw,inner sep=-2pt,text width=1.5cm},
shorten >= 3pt,shorten <= 3pt]

% the vertices of U_2
\begin{scope}[start chain=going below, node distance=4mm]
\foreach \i in {1,2,...,3}
\node[
fill=black,
on chain] (f\i) [label=left: \i] {};
\end{scope}

% the vertices of U_2
\begin{scope}[xshift=4cm,yshift=-0.5cm,start chain=going below,node distance=5mm]
\foreach \i in {4,5}
\node
[
fill=black,
on chain]
(s\i) [label=right: \i] {};
\end{scope}

% the set U_1
\node [fit=(f1) (f3),label=above:$U_1$] {};
% the set U_2
\node [fit=(s4) (s5),label=above:$U_2$] {};

% the edges
\draw[red] (f1) -- (s4);
\draw (f1) -- (s5);

\draw (f3) -- (s4);
\draw[red] (f3) -- (s5);

\end{tikzpicture}
\end{document}

按照生成的图所示:

数字

答案1

您可以通过设置为零来确定顶点大小inner sep,然后设置minimum size=<desired circle diameter>

%\documentclass{article}
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,chains,fit,shapes,calc}
\begin{document}
    \begin{tikzpicture}[
node distance = 6mm,
     V/.style = {circle,  fill, minimum size= 4pt, % <--- vertice size
                 inner sep= 0pt, outer sep=2pt, on chain},
     F/.style = {ellipse, draw, fit=#1, inner xsep=-2pt, text width=12mm},
                        ]
% the vertices of U_1    
\begin{scope}[start chain = going below]
\foreach \i in {1,2,...,3}
\node[V] (f\i) [label=left: \i] {};
\end{scope}
% the vertices of U_2
\begin{scope}[shift={(33mm,-3mm)}, start chain = going below]
\foreach \i in {4,5}
\node[V] (s\i) [label=right: \i] {};
\end{scope}

% the set U_1
\node [F=(f1) (f3), label=above:$U_1$] {};
% the set U_2
\node [F=(s4) (s5), label=above:$U_2$] {};

% the edges
\draw[red]  (f1) -- (s4)
            (f3) -- (s5);
\draw       (f1) -- (s5)
            (f3) -- (s4);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

正如您所见,我采取了一些措施,使您的代码变得更短一些并且更加一致。

答案2

它只是以下参数的组合——你可以根据自己的喜好进行实验

node style: inner sep
fit style: inner sep, text width, shorten(for the connecting arrows/lines)
label: tiny
scope: x-shift=2cm instead of 4cm

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,chains,fit,shapes,calc}
\begin{document}
    \begin{tikzpicture} [every node/.style={draw,circle, inner sep=1pt},
        every fit/.style={ellipse,draw,inner sep=-2pt,text width=2ex},
        shorten >= 1pt,shorten <= 1pt]
        
        % the vertices of U_2
        \begin{scope}[start chain=going below, node distance=4mm]
            \foreach \i in {1,2,...,3}
            \node[
            fill=black,
            on chain] (f\i) [label=left: \tiny {\i}] {};
        \end{scope}
        
        % the vertices of U_2
        \begin{scope}[xshift=2cm,yshift=-0.5cm,start chain=going below,node distance=5mm]
            \foreach \i in {4,5}
            \node
            [
            fill=black,
            on chain]
            (s\i) [label=right: \tiny{\i}] {};
        \end{scope}
        
        % the set U_1
        \node [fit=(f1) (f3),label=above:\tiny{$U_1$}] {};
        % the set U_2
        \node [fit=(s4) (s5),label=above:\tiny{$U_2$}] {};
        
        % the edges
        \draw[red] (f1) -- (s4);
        \draw (f1) -- (s5);
        
        \draw (f3) -- (s4);
        \draw[red] (f3) -- (s5);
        
    \end{tikzpicture}
\end{document}

相关内容