将图号格式化以与问题编号相匹配,包括问题内的不同图形,例如图 2.1 和图 2.2

将图号格式化以与问题编号相匹配,包括问题内的不同图形,例如图 2.1 和图 2.2

我正在尝试编写包含图形元素的试卷。我已经能够使图形引用与问题编号相匹配,但是当问题中有两个图形时,我希望以格式(例如 2.1 和 2.2)引用每个图形。对于问题 2 中的图形。我需要自动执行此操作,以便我可以选择移动问题以获得最佳匹配。我觉得我可能需要使用章节和小节,但没有成功。在下面的简单代码中,您将看到 Q3 有两个图形,目前是图 3 和图 4 - 我希望它们是图 3.1 和图 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}

答案1

你也可以\thefigure随意重新定义。它们属于群组(环境),但\item不是一个群组。你可以创建一个需要\item你回答的问题环境(如考试课)。

\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}
\renewcommand{\thefigure}{\theenumi}% reverts after \end{enumerate}
\item Question 1
\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]
  \renewcommand{\thefigure}{\theenumi.A}% reverts after figure
    \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]
  \renewcommand{\thefigure}{\theenumi.B}% reverts after figure
    \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}

\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}

相关内容