0

I have a problem with the LaTeX. I have to put in the same picture a tikzpicture and a table (in ambient tabular) side-by-side, with the same caption.

Below you find my code:

\begin{figure}
\centering
\begin{subfigure}[b]{0.5\textwidth}
 \begin{tikzpicture}[inner sep=0.6mm, placew/.style={circle,draw=black!100,fill=white!100,thick}]
\node (v1) at (-1,-1) [placew,label=270:{\footnotesize$v_1$}] {};
\node (v2) at (1,-1) [placew,label=270:{\footnotesize$v_2$}] {};
\node (v3) at (1,1) [placew,label=90:{\footnotesize$v_3$}] {};
\node (v4) at (-1,1) [placew,label=45:{\footnotesize$v_4$}] {};
\node (v5) at (-1,2) [placew,label=45:{\footnotesize$v_5$}] {};

\draw[thick] (v1) -- (v2);
\draw[thick] (v2) -- (v3);
\draw[thick] (v3) -- (v4);
\draw[thick] (v1) -- (v4);
\draw[thick] (v4) -- (v5);
\end{tikzpicture}
\end{subfigure}%

\begin{subfigure}[b]{0.6\textwidth}
\centering
 \begin{tabular}{| l | l | l | l | l | l | p{0.2cm} |}
 \hline
 & $v_1$ & $v_2$ & $v_3$ & $v_4$ & $v_5$ \\ \hline
 $v_1$ & 0 & 1 & 0 & 1 & 0  \\ \hline
 $v_2$ & 1 & 0 & 1 & 0 & 0 \\ \hline
 $v_3$ & 0 & 1 & 0 & 1 & 0 \\ \hline
 $v_4$ & 1 & 0 & 1 & 0 & 1 \\ \hline
 $v_5$ & 0 & 0 & 0 & 1 & 0 \\ \hline
\end{tabular}
\end{subfigure}
\caption{The Graph of Example \ref{RemAttr2} and its Adjacence Matrix.}\label{fig:Graph1}
\end{figure}

However, LaTeX reports the following error:

! Missing number, treated as zero. } l.1298 \begin{subfigure}[b]{0.5\textwidth}

How to solve it?

1
  • You should provide MWE, not ončy code fragment ...
    – Zarko
    Apr 27, 2023 at 16:27

1 Answer 1

2

I guess, that you after following:

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

\begin{document}
    \begin{figure}
    \centering
 \begin{tikzpicture}[baseline,
 inner sep=0.6mm, 
 placew/.style={circle,draw=black!100,fill=white!100,thick}
                    ]
\node (v1) at (-1,-1) [placew,label=270:{\footnotesize$v_1$}] {};
\node (v2) at (1,-1) [placew,label=270:{\footnotesize$v_2$}] {};
\node (v3) at (1,1) [placew,label=90:{\footnotesize$v_3$}] {};
\node (v4) at (-1,1) [placew,label=45:{\footnotesize$v_4$}] {};
\node (v5) at (-1,2) [placew,label=45:{\footnotesize$v_5$}] {};

\draw[thick] (v1) -- (v2);
\draw[thick] (v2) -- (v3);
\draw[thick] (v3) -- (v4);
\draw[thick] (v1) -- (v4);
\draw[thick] (v4) -- (v5);
\end{tikzpicture}
\hfil
 \begin{tabular}{| l | l | l | l | l | l | p{0.2cm} |}
 \hline
 & $v_1$ & $v_2$ & $v_3$ & $v_4$ & $v_5$ \\ \hline
 $v_1$ & 0 & 1 & 0 & 1 & 0  \\ \hline
 $v_2$ & 1 & 0 & 1 & 0 & 0 \\ \hline
 $v_3$ & 0 & 1 & 0 & 1 & 0 \\ \hline
 $v_4$ & 1 & 0 & 1 & 0 & 1 \\ \hline
 $v_5$ & 0 & 0 & 0 & 1 & 0 \\ \hline
\end{tabular}
\caption{The Graph of Example \ref{RemAttr2} and its Adjacence Matrix.}\label{fig:Graph1}
\end{figure}
\end{document}

enter image description here

Addendum:
with use of tblr table and redrawing tikzpicture:

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

\usepackage{tabularray}
\UseTblrLibrary{amsmath,booktabs}

\begin{document}
    \begin{figure}
    \centering
 \begin{tikzpicture}[baseline,
node distance = 17mm and 17mm, on grid,
     C/.style = {circle, draw, thick, inner sep=1pt,
                 label = #1,
                 node contents = {}},
every label/.append style = {font=\footnotesize}
                    ]
\node (v1)  [C=270:$v_1$];
\node (v2)  [C=270:$v_2$, right=of v1];
\node (v3)  [C= 90:$v_3$, above=of v2];
\node (v4)  [C= 45:$v_4$, above=of v1];
\node (v5)  [C= 45:$v_5$, above=of v4];

\draw[thick]    (v1) -- (v2) -- (v3) -- (v4) -- (v5)
                (v1) -- (v4);
\end{tikzpicture}
\hfil
 \begin{tblr}[b]{hlines, vlines,
                 colspec = { *{6}{Q[c, wd=2em, mode=math]} }
                 }
    & v_1   & v_2   & v_3   & v_4   & v_5   \\
v_1 & 0     & 1     & 0     & 1     & 0     \\
v_2 & 1     & 0     & 1     & 0     & 0     \\
v_3 & 0     & 1     & 0     & 1     & 0     \\
v_4 & 1     & 0     & 1     & 0     & 1     \\
v_5 & 0     & 0     & 0     & 1     & 0     \\
\end{tblr}
\caption{The Graph of Example \ref{RemAttr2} and its Adjacence Matrix.}
\label{fig:Graph1}
\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 .