1

I have a document with a set of paragraphs where each paragraph has a label/caption.
I need an unusual behavior:

  • The label should be on the same line as the first line of the paragraph
  • The paragraph should be indented, but the label should be not indented (ie. placed on the left of the paragraph some distance)
  • If the label is larger than the indent, it should bump the first line a bit to fit (and there should be a space between the two)

So far I'm doing this with a description list env:

\begin{description}[leftmargin=3em,style=nextline,itemsep=1ex]

This works really well, but there's one problem: I can't use wrapfig, because wrapfig doesn't play with lists.

Is there a way to do the same thing without the environment description so that I can use wrapfig too?

projetmbc
  • 13,315
kralyk
  • 145
  • 5
  • There should (hopefully) be a way without wrapfig: with the plain TeX macropackage insbox. – Bernard Mar 26 '21 at 23:50
  • @Bernard hmm... I've looked into how that's done (here) and honestly that seems pretty complex... – kralyk Mar 27 '21 at 00:13
  • 1
    There are other examples on this site, as far as I remember. However, maybe I've misunderstood your problem: You do have to insert an image? – Bernard Mar 27 '21 at 00:26
  • Yes, I would like to insert an image :-) – kralyk Mar 27 '21 at 08:44
  • Well, to be fair, hacking into the list-like environments is hard, so yes, the solution with at least some degree of auto-spacing using insbox is complicated (and has to be adapted differently for the different list environments). Faking a description is certainly possible, but I'm not sure how well this plays with wrapfig either. Can you please create a minimal example? – Skillmon Mar 27 '21 at 10:48
  • I have since figured I can emulate the list with a \tabto, like this. It's not particularly elegant as there needs to be a \tabto on each line, but I actually generate that TeX with a script so that's not an issue, if it can't be done more elegantly. Sorry, I'm not very experienced with TeX. – kralyk Mar 27 '21 at 11:24
  • Why not do this with a sectioning command instead of a list? – Alan Munn Mar 27 '21 at 15:47

1 Answers1

2

The following defines a very simple minded fakedescription environment (one could further enhance it by instead of defining custom lengths for the spacing pick up the spaces defined by LaTeX (or enumitem) for the real description environment). It should work with wrapfig (the following has a small demonstration using wrapfig, but I did no extensive testing whatsoever).

\documentclass[]{article}

\usepackage{wrapfig}

\makeatletter \newlength\fakedescription@indent \newlength\fakedescription@labelsep \newlength\fakedescription@itemsep \newlength\fakedescription@topsep \newcommand\fakeitem[1][] {% \GenericError{} {Error: Usage of \string\fakeitem\space outside of fakedescription} {} {}% } \AtBeginDocument {% setting AtBeginDocument since earlier we can't rely on em being correct \fakedescription@indent=3em \fakedescription@labelsep=1em \fakedescription@itemsep=\smallskipamount \fakedescription@topsep=\medskipamount } \newenvironment{fakedescription} {% \par \vspace\fakedescription@topsep \renewcommand\fakeitem[1][] {% \par \vskip\fakedescription@itemsep \noindent\kern-\fakedescription@indent \sbox0{\textbf{##1}}% \ifdim\wd0>\dimexpr \fakedescription@indent-\fakedescription@labelsep\relax \usebox0\kern\fakedescription@labelsep \else \makebox[\fakedescription@indent][l]{\usebox0}% \fi \ignorespaces }% \advance\leftskip\fakedescription@indent \ignorespaces } {% \par \vspace\fakedescription@topsep @endpetrue } \makeatother

\usepackage[]{graphicx}

\usepackage{duckuments}

\begin{document} \blindduck[-] \begin{wrapfigure}{r}[0pt]{5cm} \includegraphics[width=5cm]{example-image-duck} \end{wrapfigure} \begin{fakedescription} \fakeitem[A] the first one letter of the Latin alphabet \fakeitem[AB] the first two letters of the Latin alphabet \fakeitem[ABC] the first three letters of the Latin alphabet \fakeitem[ABCD] the first four letters of the Latin alphabet \fakeitem[ABCDE] the first five letters of the Latin alphabet \fakeitem[story] \blindduck[-] \end{fakedescription} \blindduck[-] \end{document}

enter image description here

Skillmon
  • 60,462