1

I just picked code from What's the best way to include graphics in an enumerated list? to include a graphic in an enumerated list. But the code causes a overfull \hbox if I use it in the first enumeration item. How can I solve this?

MWE:

\documentclass{scrartcl}

\usepackage[demo]{graphicx}
\usepackage{adjustbox}

\begin{document}
\begin{enumerate}
\item 
\begin{minipage}[t]{\textwidth}
          \raggedright
          \adjustbox{valign=t}{%
            \includegraphics[width=\textwidth]{E53a}%
          }
    \end{minipage}
\end{enumerate}

\end{document}

Edit: Another MWE using \linewidth but still doesn't work:

\documentclass{scrartcl}

\usepackage{graphicx}
\usepackage[export]{adjustbox}

\newcounter{mycounter}
\setcounter{mycounter}{1}

\newenvironment{myenv}[1]{
\section{Title}
}{\stepcounter{mycounter}}

\newtheorem{myth}{}[mycounter]

\begin{document}

\begin{myenv}

\begin{myth}
\begin{enumerate}
\item  \includegraphics[width=\linewidth,valign=t]{E53a}%
\end{enumerate}
\end{myth}

\end{myenv}

\end{document}
ATW
  • 395
  • An overfull box is just a warning, if you think the output is ok then you can safely ignore the warning. That said, width=\textwidth within an enumerate is slightly too wide, you could try width=0.9\textwidth to make it fit better. – Marijn May 23 '20 at 19:19
  • Hmm, I actually do not want to ignore the warning. – ATW May 23 '20 at 19:23
  • @Marijn there is no need to guess like that. – David Carlisle May 23 '20 at 19:32
  • the line width in an indented list is \linewidth not \textwidth – David Carlisle May 23 '20 at 19:33
  • \linewidth doesn't work either @DavidCarlisle. – ATW May 23 '20 at 19:34
  • 2
    unrelated but if you use the export option when loading adjustbox you can use teh nicer syntax \includegraphics[valign=t]{...} ratther than needing teh adjustbox wrapper (and you do not need the minipagein any case. – David Carlisle May 23 '20 at 19:34
  • yes \linewidth does work:-) I posted some code as an answer – David Carlisle May 23 '20 at 19:38
  • you are defining myenv to take an argument #1 which it discards, so it is discarding the blank line hrere but if you didn't have a blank lien after \begin it would discard teh \begin or \begin{myth} is that the intended behaviour??? – David Carlisle May 23 '20 at 20:03
  • Of course not. The argument was only a leftover, thanks. But that does "unfortunately" not affect the overfull \hbox. – ATW May 23 '20 at 20:06
  • it's the usual wacky behaviour of an enumerate at the start of a theorem. If you add \item zzz after it you will see that the 2 is in the usual place then \linewidth will work but for the first item 1 is inlined after the theorem heading so not in line with the other labels that's intentional in the latex code (but I never liked it:-) if you want that you need to account for the theorem heading o simply use \begin{myth}\mbox{} so the label 1. goes in line with 2. and then \linewidth is the right thing. – David Carlisle May 23 '20 at 20:11
  • Is there no other, "right" way? That would work of course - but for consistency purposes I would highly appreciate a solution where the image could sit next to the label and not causing a badbox. Maybe I'm a bit difficult :o) – ATW May 23 '20 at 20:16

1 Answers1

1

You want \linewidth not \textwidth in an indented list.

enter image description here

\documentclass{scrartcl}

\usepackage[demo]{graphicx}
\usepackage[export]{adjustbox}

\begin{document}
\begin{enumerate}
\item 
 \includegraphics[width=\linewidth,valign=t]{E53a}%
\end{enumerate}

\end{document}

one way of tackling enumerate in a theorem is to make sure it isn't first (add \mbox{} if no actual text

enter image description here


\documentclass{scrartcl}

\usepackage[demo]{graphicx}
\usepackage[export]{adjustbox}

\newcounter{mycounter}
\setcounter{mycounter}{1}

\newenvironment{myenv}[1]{%
\section{Title}%
}{\stepcounter{mycounter}}%


\newtheorem{myth}{}[mycounter]

\begin{document}

\begin{myenv}

\begin{myth}\mbox{}
\begin{enumerate}
\item  \includegraphics[width=\linewidth,valign=t]{E53a}%
\item zzz
\end{enumerate}
\end{myth}

\end{myenv}

\end{document}
David Carlisle
  • 757,742
  • Weird - it works in a dummy file but in my document, it is still ~32pt too wide (\textwidth was ~60pt too wide). How can it come? – ATW May 23 '20 at 19:44
  • @Thomas start from your document where it is wrong and delete everything you can delete until you get a small enough example to add to your question. – David Carlisle May 23 '20 at 19:53
  • I added another working non-working example including more of my document's structure. – ATW May 23 '20 at 19:57