I am trying to write exam papers which include graphical elements. I have been able to make the figure reference match the question number but when there are two figures in a question I would like to reference each figure with the format eg 2.1 and 2.2. for figures in question 2. I need this to be automatic to give me the option of moving questions for a best fit. I feel that I probably need to use sections and subsections but have had no success. In the simple code below you will see Q3 has two figures which are currently Fig.3 and Fig.4 - I would like them to be Fig.3.1 and Fig.3.2.
\documentclass[12pt,a4paper]{article}
\usepackage[left=12mm, top=12mm, right=12mm, bottom=12mm]{geometry}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{enumerate}
\usepackage[shortlabels]{enumitem}
\usepackage[figurename=Fig.]{caption}
\usepackage{float}
\usepackage{pgfplots}
\usepackage{tkz-euclide}
\begin{document}
\begin{enumerate}
\item Question 1
\setcounter{figure}{\value{enumi}}%
\item Fig.\ref{A1} shows triangle \textit{ABC}.
\begin{figure}[H]
\centering{\begin{tikzpicture}[scale = 0.4]
\draw [line width = 0.5mm] (0,0) coordinate(A) node[left]{A}--++(0:3) coordinate(B) node[right]{B}--++(64:4) coordinate(C) node[above]{C}--cycle;
\end{tikzpicture}
\caption{} \label{A1} }
\end{figure}
\item Fig.\ref{A2} shows a sector of a circle of radius 8 cm.\\[2mm]
The angle of the sector is 2.1 radians.
\begin{figure}[H]
\centering{ \begin{tikzpicture}[scale=0.4]
\draw [line width = 0.5mm,fill=gray!30] (0,0) -- (220:4) arc(220:120:4) -- cycle ;
\end{tikzpicture}
\caption{} \label{A2} }
\end{figure}
Fig.\ref{A3} shows a sector of a circle of radius 8 cm.\\[2mm]
The angle of the sector is 2.1 radians.
\begin{figure}[H]
\centering{ \begin{tikzpicture}[scale=0.4]
\draw [line width = 0.5mm,fill=gray!30] (0,0) -- (220:4) arc(220:120:4) -- cycle;
\end{tikzpicture}
\caption{} \label{A3} }
\end{figure}
\setcounter{figure}{\value{enumi}}%
\item Another Question. Fig \ref{A4}
\begin{figure}[H]
\centering{ \begin{tikzpicture}[scale=0.4]
\draw [line width = 0.5mm,fill=gray!30] (0,0) -- (220:4) arc(220:120:4) -- cycle;
\end{tikzpicture}
\caption{} \label{A4} }
\end{figure}
\end{enumerate}
\end{document}
\section
s, and then simply\numberwithin{figure}{section}
. Unrelated: I seriously doubt you are really usinglatin1
encoding.