4

Is there a way to center an image about the enumerated text, rather than with respect to the document itself? So instead of the image being equidistant from the counter and the other side of the text, have it be centered within the (indented/enumerated) paragraph. An example is given below, and a MWE is given as well.:

\documentclass[]{article}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage[margin=3cm]{geometry}
\begin{document}
\begin{enumerate}
\item \lipsum[5]
\begin{figure}[!h]
\centering
\includegraphics[scale = 1.5]{test}
\end{figure}
\end{enumerate}
\end{document}

enter image description here

  • Note that a float goes to some lengths not to inherit the current line settings as the whole point of floats is that they may be moved to a different location (even with [!ht] which most often generates a warning and is changed to [!ht]) – David Carlisle Feb 17 '15 at 0:39
  • Nonetheless, I need to both keep the figure environment (I need a caption/ figure label!) and also need to center my image with respect to the text... (I suppose I should have written that in my example- I had forgotten.) – user41692 Feb 17 '15 at 0:40
  • 1
    No, if the image needs to be in that position then it needs not to be a float which is the same as saying it shouldn't be a figure. You can use \caption and \label anyway using \captionof{figure}{..} – David Carlisle Feb 17 '15 at 0:42
  • Oh I can? And I see. I submit! Thank you for your help. – user41692 Feb 17 '15 at 0:42
2

enter image description here

That is the default behaviour for centering of material within the item.

\documentclass[]{article}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage[margin=3cm]{geometry}
\begin{document}
\begin{enumerate}
\item \lipsum[5]
\begin{center}
\includegraphics[width=.5\linewidth]{example-image}
\end{center}
\end{enumerate}
\end{document}
  • Ah, but what if I want to keep my figure environment? – user41692 Feb 17 '15 at 0:38
  • @Anthony Why would you want to do that? – Gonzalo Medina Feb 17 '15 at 0:39
  • @Anthony you don't. That was an error. – David Carlisle Feb 17 '15 at 0:40
  • @DavidCarlisle I commented on the question- I actually still need the caption and figure label. – user41692 Feb 17 '15 at 0:42
  • 1
    @Anthony If you don't want another package you could copy the contents of capt-of.sty into your document (it's one line long:-) – David Carlisle Feb 17 '15 at 0:47
1

Instead of figure, you can use a minipage of width equal to \linewidth; an eventual caption can be provided using \captionof from the caption or capt-of packages; \centering can be replaced with a center environment to add some vertical spacing:

\documentclass[]{article} 
\usepackage{graphicx} 
\usepackage{lipsum} 
\usepackage[margin=3cm]{geometry} 
\begin{document} 
\begin{enumerate} 
\item \lipsum[5] 
\begin{minipage}{\linewidth} 
\centering 
\includegraphics[scale = 0.8]{example-image-a} 
\end{minipage} 
\end{enumerate} 
\end{document}

enter image description here

An example with \caption and \label to cross-reference:

\documentclass[]{article} 
\usepackage{graphicx} 
\usepackage{caption} 
\usepackage{lipsum} 
\usepackage[margin=3cm]{geometry} 
\begin{document}
As we see in Figure~\ref{fig:test}... 
\begin{enumerate} 
\item \lipsum[5] 
\begin{minipage}{\linewidth} 
\centering 
\includegraphics[scale = 0.8]{example-image-a} 
\captionof{figure}{test figure}
\label{fig:test}
\end{minipage} 
\end{enumerate} 
\end{document}

enter image description here

And without additional packages (adding directly the definition of \captionof from capt-of):

\documentclass[]{article} 
\usepackage{graphicx} 
\usepackage{lipsum} 
\usepackage[margin=3cm]{geometry} 

\makeatletter
\newcommand\captionof[1]{\def\@captype{#1}\caption}
\makeatother

\begin{document}
As we see in Figure~\ref{fig:test}... 
\begin{enumerate} 
\item \lipsum[5] 
\begin{minipage}{\linewidth} 
\centering 
\includegraphics[scale = 0.8]{example-image-a} 
\captionof{figure}{test figure}
\label{fig:test}
\end{minipage} 
\end{enumerate} 
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy