2

I have drawn several graphs using tikz. Right now I am getting the vertex label inside the vertex. But I want the labels of vertices outside it.

Also I want to draw two tickz pictures in one line. Please help. I am using the following code.

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{caption}

\begin{document}

\begin{figure}[h]
\centering
\begin{tikzpicture}
\begin{scope}[every node/.style={fill=white,circle,thick,draw}]
    \node(A) at (1,1) {1};
    \node(B) at (0,0) {2};
    \node(C) at (1,-1) {3};
\end{scope}
\begin{scope}
            [every edge/.style={draw=black,very thick}]
    \path[-](A)edge node {} (B);
    \path[-](B) edge node {} (C);
\end{scope}
\end{tikzpicture}
\caption*{Figure 1}
\end{figure}

\medskip

\begin{figure}[h]
\centering
\begin{tikzpicture}
\begin{scope}[every node/.style={fill=white,circle,thick,draw}]
    \node(A) at (0,0) {2};
    \node(B) at (-1,1) {4};
    \node(C) at (1,1) {6};
    \node(D) at (1,-1) {8};
    \node(E) at (-1,-1) {10};
\end{scope}
\begin{scope}
            [every edge/.style={draw=black,very thick}]
    \path[-](A)edge node {} (B);
    \path[-](A) edge node {} (C);
    \path[-](A) edge node {} (D);
    \path[-](A) edge node {} (E);
\end{scope}
\end{tikzpicture}
\caption*{Figure 2}
\end{figure}
\end{document}
0

2 Answers 2

1

An alternative, based on assumption,that you wish two figures side by side and not subfigures:

enter image description here

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{caption}
\usepackage{tabularx}

    \begin{document}  
\begin{figure}[h]
\centering
    \begin{tabularx}{0.8\textwidth}{*{2}{>{\centering\arraybackslash}X}}
\begin{tikzpicture}[
every edge/.style = {draw=black,very thick},
 vrtx/.style args = {#1/#2}{% 
      circle, draw, thick, fill=white,
      minimum size=5mm, label=#1:#2}
                    ]
\node(A) [vrtx=left/1] at (1, 1) {};
\node(B) [vrtx=left/2] at (0, 0) {};
\node(C) [vrtx=left/3] at (1,-1) {};
%
\path   (A) edge (B)
        (B) edge (C);
\end{tikzpicture}
    \caption*{Figure 1}  
    &   
\begin{tikzpicture}[
every edge/.style = {draw=black,very thick},
 vrtx/.style args = {#1/#2}{%
      circle, draw, thick, fill=white,
      minimum size=5mm, label=#1:#2}
                    ]
\node (A) [vrtx=left/2]     at ( 0, 0) {};
\node (B) [vrtx=left/4]     at (-1, 1) {};
\node (C) [vrtx=right/6]    at ( 1, 1) {};
\node (D) [vrtx=right/8]    at ( 1,-1) {};
\node (E) [vrtx=left/10]    at (-1,-1) {};
 %
\path   (A) edge (B)
        (A) edge (C)
        (A) edge (D)
        (A) edge (E);
\end{tikzpicture}
\caption*{Figure 2}  
    \end{tabularx}
\end{figure} 
\end{document}

I also slightly change code to make it more concise and easy to use (omit are scopes, defined node for simple settings their labels, omitted are not used nodes ad edges. Figures are placed in tabularx table.

Addendum: In case, that you like to organize figures in one line as sub figures:

\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}[h]
\centering
    \begin{subfigure}[b]{0.4\textwidth}\centering
\begin{tikzpicture}[
every edge/.style = {draw=black,very thick},
 vrtx/.style args = {#1/#2}{%
      circle, draw, thick, fill=white,
      minimum size=5mm, label=#1:#2}
                    ]
\node(A) [vrtx=left/1] at (1, 1) {};
\node(B) [vrtx=left/2] at (0, 0) {};
\node(C) [vrtx=left/3] at (1,-1) {};
%
\path   (A) edge (B)
        (B) edge (C);
\end{tikzpicture}
    \caption{}
    \end{subfigure}
\hfil    
    \begin{subfigure}[b]{0.4\textwidth}\centering
\begin{tikzpicture}[
every edge/.style = {draw=black,very thick},
 vrtx/.style args = {#1/#2}{%
      circle, draw, thick, fill=white,
      minimum size=5mm, label=#1:#2}
                    ]
\node (A) [vrtx=left/2]     at ( 0, 0) {};
\node (B) [vrtx=left/4]     at (-1, 1) {};
\node (C) [vrtx=right/6]    at ( 1, 1) {};
\node (D) [vrtx=right/8]    at ( 1,-1) {};
\node (E) [vrtx=left/10]    at (-1,-1) {};
 %
\path   (A) edge (B)
        (A) edge (C)
        (A) edge (D)
        (A) edge (E);
\end{tikzpicture}
\caption{}
    \end{subfigure}
\caption{Common caption}
    \label{fig:figure-3}
\end{figure}
    \end{document}

enter image description here

In above MWE is used environments subfigure from package subcaption.

0
\documentclass[11pt]{article}
\usepackage{fontspec} % lualatex engine
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}

\begin{figure}[!h]
        \centering
     \begin{minipage}[t]{.45\linewidth}
        \centering
\begin{tikzpicture}[every edge/.style = {draw,very thick},
                    vertex/.style args = {#1 #2}{circle, 
                                                draw, thick,
                                                minimum size=5mm, 
                                                label=#1:#2}]
\path node(A) [vertex=left 1] at (1, 1) {} 
      node(B) [vertex=left 2] at (0, 0) {} 
      node(C) [vertex=left 3] at (1,-1) {} 
      (A) edge (B)                         
      (B) edge (C);
\end{tikzpicture}
        \caption{graph}
        \end{minipage}
    \begin{minipage}[t]{.45\linewidth}
        \centering
\begin{tikzpicture}[every edge/.style = {draw,very thick},
                    vertex/.style args = {#1 #2}{circle, 
                                                 draw, 
                                                 thick,
                                                 minimum size=5mm, 
                                                 label=#1:#2}]
\path   node (A) [vertex=left 2]     at ( 0, 0) {} 
        node (B) [vertex=left 4]     at (-1, 1) {} 
        node (C) [vertex=right 6]    at ( 1, 1) {} 
        node (D) [vertex=right 8]    at ( 1,-1) {} 
        node (E) [vertex =left 10]   at (-1,-1) {}
       (A) edge (B)
       (A) edge (C)
       (A) edge (D)
       (A) edge (E);
\end{tikzpicture}
    \caption{graph bis}
    \end{minipage}
    \end{figure}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .