1

This is a follow-up question to Create enumerate like indented nesting environment. The accepted solution to that question works well but it can not handle float environment like \begin{table}-\end{table} and \begin{figure}-\end{figure}. What is the way to indent such float environments?

2
  • Is there something stopping you from embedding a quotation environment inside a figure or table environment?
    – Mico
    Commented Jan 11, 2022 at 12:29
  • 1
    You can replace figure and table with minipage {\linewidth} and \captionof (caption package). Commented Jan 11, 2022 at 16:38

2 Answers 2

1

If you want floats to conform to the width of the current environment, it seems more likely that you don't want them to float at all. The following code assumes that by redefining figure to be a minipage, setting the regular \caption using capt-of's \captionof{figure}:

enter image description here

\documentclass{article}

\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{changepage,etoolbox}
\usepackage{environ,capt-of}

\newenvironment{enumlike}[1][15pt]{%
  \begin{adjustwidth}{#1}{0pt}% Only indent on left side
}{%
  \end{adjustwidth}%
}

\let\oldfigure\figure% Store original figure float environment
\let\endoldfigure\endfigure
\RenewEnviron{figure}[1][H]{% Update figure environment
  \par\vspace{\intextsep}% Assume in-text placement, so insert appropriate vertical spacing
  \noindent
  % \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
  \patchcmd{\BODY}{\caption}{\captionof{figure}}{}{}% Replace \caption with \captionof{figure} inside \BODY
  % Set "figure"
  \begin{minipage}{\linewidth}
    \BODY
  \end{minipage}
  \par\vspace{\intextsep}% Assume in-text placement, so insert appropriate vertical spacing
}

\begin{document}

\lipsum[1]

\begin{enumlike}

  \lipsum[2]

  \begin{figure}[h]
    \includegraphics[height=40mm,width=\linewidth]{example-image}
    \caption{An indented figure}
  \end{figure}    

\end{enumlike}

\lipsum[3]

\end{document}

A similar redefinition can be made for the table float.

1
  • Awesome! much appreciated, thanks! Great learning on how powerful and customizable LaTeX is!
    – aaryan
    Commented Jan 12, 2022 at 12:48
0

You can use the solution given in the linked question, but you have to place the enumlike environment inside figure and table environments.

\documentclass{article}

\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{changepage}
\usepackage{tabularx}

\newenvironment{enumlike}[1][15pt]{%
    \begin{adjustwidth}{#1}{0pt}% Only indent on left side
    }{%
    \end{adjustwidth}%
}

\begin{document}
    
\lipsum[1][1-5]
\begin{figure}[h]
    \begin{enumlike}
        \includegraphics[height=40mm, width=\linewidth]{example-image}
        \caption{An indented figure}
    \end{enumlike}
\end{figure}    
\lipsum[1][1-5]
\begin{table}[h]
    \begin{enumlike}[50pt]
        \begin{tabularx}{\linewidth}{|X|X|X|} \hline
            some & meaningless & text \\ \hline
            some & meaningless & text \\ \hline
            some & meaningless & text \\ \hline
        \end{tabularx}
        \caption{An even more indented table}
    \end{enumlike}
\end{table}

\end{document}

indented figure and table

However, I would suggest, that you stick to \centering and use things like width=0.9\linewidth when including graphics. Only left side indentation looks odd to me.

2
  • This works but is there any way that the float environments can inherit this from the parent command itself? The whole point of creating enum like environment is that it should work without modifying/customizing anything else inside it.
    – aaryan
    Commented Jan 11, 2022 at 14:36
  • @aaryan don't know, there exists \AtToHook{env/figure/begin}{\begin{enumlike}} and \AtToHook{env/figure/end}{\end{enumlike}}, but they don't work. Maybe someone more familiar with hooks can help?
    – marv
    Commented Jan 11, 2022 at 15:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .