In principle this is just a matter of redefining the printed representation of the figure number by e.g.
\renewcommand{\thefigure}{Q\theenumi(\theenumii)}
(assuming you have just one figure per second level enumeration item, so the actual value of figure
is irrelevant). However, if you have figures elsewhere in you document you will get strange numbering of those. So firstly this change should just be applied at the start of enumerate
.
However, now the number of the other figures (outside enumerate
) jumps over some values. One way around this is to define a newcounter
\newcounter{curfigure}
save the original value of the figure counter in this at the beginning of the enumerate
environment
\setcounter{curfigure}{\value{figure}}
and then restore it at the end via the corresponding \setcounter{figure}{\value{curfigure}}
.
with cross references
As you don't want your figures to float, you should use a center
environment and \captionof{figure}{....}
from the caption
package.
The wide figure numbers mean that labels in the list of figures overlap the text in the standard settings for report
, so in the code below I have adjusted that too.
\documentclass[10pt,a4paper]{report}
\usepackage{graphicx,caption}
\renewcommand\labelenumi{Q\theenumi.}
\newcounter{curfigure}
\makeatletter
\renewcommand{\l@figure}{\@dottedtocline{1}{1.5em}{3em}}
\makeatother
\begin{document}
\listoffigures
\clearpage
\begin{figure}
\centering
Test figure.
\caption{Test figure.}
\label{fig:test}
\end{figure}
\begin{enumerate}
\setcounter{curfigure}{\value{figure}}
\renewcommand{\thefigure}{Q\theenumi(\theenumii)}
\item
\begin{enumerate}
\item Question 1 Part (a)
\item Question 1 Part (b)
\begin{center}
\centering
\includegraphics[width=0.2\linewidth]{example-image-a}
\captionof{figure}{The caption appears as Figure
Q1(b): instead of Figure 1:}\label{fig:1b}
\end{center}
\item Question 1 Part (c)
\begin{center}
\centering
\includegraphics[width=0.2\linewidth]{example-image-b}
\captionof{figure}{The caption appears as Figure Q1(c): instead
of Figure 2:}\label{fig:1c}
\end{center}
\end{enumerate}
\item
\begin{enumerate}
\item Question 2 Part(a)
\begin{center}
\centering
\includegraphics[width=0.2\linewidth]{example-image-a}
\captionof{figure}{The caption appears Figure Q2(a): instead of
Figure 3:}\label{fig:2a}
\end{center}
\item Question 2 Part(b)
\end{enumerate}
\end{enumerate}
\setcounter{figure}{\value{curfigure}}
\begin{figure}
\centering
Test figure two.
\caption{Test figure two.}
\label{fig:test-2}
\end{figure}
\begin{figure}
\centering
Test figure three.
\caption{Test figure three.}
\label{fig:test-3}
\end{figure}
The figures in the questions are \ref{fig:1b}, \ref{fig:1c}
and~\ref{fig:2a}.
The other figures are \ref{fig:test}, \ref{fig:test-2}
and~\ref{fig:test-3}.
\end{document}
A possible, very manual solution:
\documentclass[]{article}
\usepackage{multicol}
\usepackage{duckuments}% for dummy content
\usepackage[]{graphicx}
\usepackage{capt-of}% if you load the caption package you don't need this
\begin{document}
\begin{multicols}{2}
\blindduck[-]
\end{multicols}
\begin{figure}[htp]% >>>
\centering
\includegraphics[width=.7\linewidth]{example-image-duck}%
\caption
{%
A happy duck%
\label{fig:duck}%
}%
\end{figure}% <<<
\begin{multicols}{2}
\blindduck[-]
\end{multicols}
\clearpage
\begin{multicols}{2}
\blindduck[1-4]
\vskip\intextsep
\noindent\begin{minipage}{\linewidth}
\centering
\includegraphics[width=.7\linewidth]{example-image-duck}%
\captionof{figure}
{%
A happy canard with a long caption being placed correctly%
\label{fig:canard}%
}%
\end{minipage}
\vskip\intextsep
\blindduck[full]
\end{multicols}
\end{document}
Output of the full width figure:
Output of the single column figure:
Best Answer
Floating environments defined with
\newfloat
do not respect the position of the\caption
command but always use the selected float style instead which have a fixed, pre-defined caption position. They behave differently regarding this aspect thanfigure
andtable
. (BTW: To makefigure
andtable
behave like environments defined with\newfloat
, thefloat
package offers\restylefloat
.)So if you want to have a floating environment which behaves like
figure
andtable
and let you place the\caption
where you want to, do not use\newfloat
but\DeclareFloatingEnvironment
(or\DeclareCaptionType
) offered by thenewfloat
package, or\DeclareNewTOC
offered by the KOMA-Script document classes.For example:
Please note that I've added the
caption
package since (according your comment) you use it anyway. If you don't use thecaption
package, the straight-ahead way would be loading thenewfloat
package and using\DeclareFloatingEnvironment
instead.BUT: If all
infoboxes
should be framed a different (and IMHO better) approach would be using theboxed
style of thefloat
(orfloatrow
) package:(The
\restylefloat*
is necessary so the caption will be placed inside the frame. Without it the caption would always been outside the frame.)