字幕位置不正确

字幕位置不正确

我正在写作业。TikZ 图片标题没有出现在正确的位置。请参阅下面的代码:

\documentclass{article}    
 % added tikz libraries
\usepackage{tikz}

\usetikzlibrary{positioning}

\开始{文档}

Question 1 : Prove that a complete graph with n vertices contains $\frac{n \times (n-1)}{2}$ edges. A complete graph is a simple undirected graph in which every pair of distinct vertices is connected by a unique edge.For an example see the diagram below for complete graph on six vertices.

\begin{center}    
\begin{tikzpicture}[scale=.5,auto=left,every node/.style={circle,fill=black!20}]      
        \foreach \x in {1,...,6}    
        {   \node (n\x) at (\x*60:3) {\x};    
        }
    \foreach \x in {1,...,5}    
    {   \pgfmathtruncatemacro{\lowerbound}{\x+1}   
        \foreach \y in {\lowerbound,...,6}    
        {   \draw (n\x) -- (n\y);    
            % for labelled edges
            %\draw (n\x) -- (n\y) node[sloped,pos=0.39,fill=white,fill opacity=0.3,above=0.1mm,rectangle, inner sep=0.1mm] {\tiny \x-\y};  
        }
    }
\caption{Complete graph on six vertices} \label{fig:M1}    
\end{tikzpicture}    
\end{center}

答案1

标题不是其中的一部分tikzpicture!使用caption包,你有两种方式可以向图形添加标题:

\documentclass{article}
\usepackage{caption}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

Question 1 : Prove that a complete graph with n vertices contains $\frac{n \times (n-1)}{2}$ edges. A complete graph is a simple undirected graph in which every pair of distinct vertices is connected by a unique edge.For an example see the diagram below for complete graph on six vertices.

\begin{center}
\begin{tikzpicture}[scale=.5,auto=left,every node/.style={circle,fill=black!20}]
        \foreach \x in {1,...,6}
        {   \node (n\x) at (\x*60:3) {\x};}
    \foreach \x in {1,...,5}
    {   \pgfmathtruncatemacro{\lowerbound}{\x+1}
        \foreach \y in {\lowerbound,...,6}
        {   \draw (n\x) -- (n\y);}
    }
\end{tikzpicture}
\captionof{figure}{Complete graph on six vertices} \label{fig:M1}
\end{center}
%
or with figure environment
%
\begin{figure}[htb]
    \centering
\begin{tikzpicture}[scale=.5,auto=left,every node/.style={circle,fill=black!20}]
        \foreach \x in {1,...,6}
        {   \node (n\x) at (\x*60:3) {\x};}
    \foreach \x in {1,...,5}
    {   \pgfmathtruncatemacro{\lowerbound}{\x+1}
        \foreach \y in {\lowerbound,...,6}
        {   \draw (n\x) -- (n\y);}
    }
\end{tikzpicture}
\caption{Complete graph on six vertices} \label{fig:M1}
\end{figure}
\end{document}

在此处输入图片描述

caption注意:您也可以使用包 来代替capt-of包。

相关内容