1

This is a follow-up to the answer from https://tex.stackexchange.com/a/412010/221716

As with the original question, I'd like to include the source text under the image. However, the URL is longer than the image's width, and the environment is a wrapfigure.

Latex source:

\documentclass{book}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{stackengine}
\usepackage{xurl}
\usepackage{lipsum}

\begin{document}

\begin{wrapfigure} {r}{.25\textwidth} \centering \def\stackalignment{r}\stackunder{ % \includegraphics[width=.25\textwidth]{example-image-b} % }{\tiny Source: \url{https://www.example.org/very/very/very/very/very/very/very/long/url}} \caption{My Caption} \end{wrapfigure}

\lipsum \end{document}

As a result, the URL does not take into account the width of the environment. As a result, the picture is misaligned, and the URL is not wrapped inside the appropriate width: Result

Surprisingly, removing \stackalignment{r} correctly wraps the URL but removes the picture: Result_2

Is it feasible to have the picture and the source aligned and wrapped correctly? Furthermore, because the text is so small, may the vertical space of the URL be reduced? Thanks

1 Answers1

1

Like this?

enter image description here

\documentclass{book}
\usepackage[skip=1ex, font=small, labelfont=bf,
            justification=raggedright]{caption}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{stackengine}
\usepackage{xurl}

\usepackage{etoolbox} \BeforeBeginEnvironment{wrapfigure}{% \setlength{\intextsep}{0pt}} % remove superfluous vertical space above/below wrapfigure

\usepackage{lipsum}

\begin{document}

\begin{wrapfigure}{r}{.25\textwidth} \def\stackalignment{r}\stackunder{% \includegraphics[width=\linewidth]{example-image-duck}%{image.png} % }{\scriptsize \parbox[t]{\linewidth}{% <... needed Source: \url{https://www.example.org/very/very/very/very/very/very/very/long/url}} } \caption{Caption of wrapfigure} \end{wrapfigure}

\lipsum \end{document}

Zarko
  • 296,517