2

I would like to be able to create a sort of group, like a div in html, that will let me put paragraphs and an image on the side. Something like this:

Edit:

I need

  1. For the images to be by the side of the corresponding paragraph. (image A).
  2. For the paragraph to be the whole text width if there is no image (second paragraph)
  3. For the paragraph to start below the previous image if the image is too big (image C)

If there is no way of doing this with current styles and classes, can someone point me on a direction to do it myself?

enter image description here

  • 2
    Use the wrapfigure environment. It works fine as long as there's no list environment near it. – Bernard Feb 12 '17 at 16:49
  • 1
    There are other tricks one can use (\hangindent, \rightskip, minipages) for special cases, but wrapfigure is the most general solution. – John Kormylo Feb 12 '17 at 20:55
  • @Bernard there will be a list environment. I begin an enumerate and then each item has a text and an image. – lesolorzanov Feb 13 '17 at 12:46
  • 1
    If there is a list environment, you can play with the right margin of the list (easy with enumitem) and the plain TeX macro package insbox. – Bernard Feb 13 '17 at 12:53

1 Answers1

3

Although you can do this with a wrapfigure or simply two minipages, for a document with several margin figures, this is the normal look & fell for the peculiar but elegant tufte-hadout or tufte-book class, as they left a wide right margin to provide room for figures, tables or sidenotes.

For images, simply use the marginfigure instead of the figure environment. Note that you can adjust the vertical position of the figures and put text than extent to the right margin, making fake wrappings.

If you do not want the style of tufte classes in another aspects (not justified text, not numbered sections, etc.), at some extent they can be easily tuned to look more like standard classes, so give them a try. An example resembling a bit some standard class:

mwe

\documentclass[justified,twoside]{tufte-handout} 
\title{A Minimal Working Example}
\usepackage{lipsum,blindtext}
\usepackage{graphicx}
\setcounter{secnumdepth}{1}
\setcaptionfont{\sffamily}
\titleformat{\section}{\bfseries\Large}{\thesection}{1em}{}[]
\begin{document}
\section{Research}
\lipsum[1]
\begin{marginfigure}[-25em]
\includegraphics[width=\textwidth]{example-image}
\caption{A tiny caption.}
\end{marginfigure}
\lipsum[2]
\begin{marginfigure}[-18em]
\includegraphics[width=\textwidth]{example-image-a}
\caption{The nice image A.}
\end{marginfigure}
\begin{fullwidth}
\lipsum[3]
\end{fullwidth}
\end{document}

Edit: To make like asked in the edited question, here are another ways:

mwe2

\documentclass{article} 
\usepackage[margin=2cm]{geometry}
\usepackage{wrapfig}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{adjustbox}
\def\parimg#1#2#3{\noindent%
\adjustbox{valign=t}{\begin{minipage}[c]{\dimexpr.95\linewidth-.#3\linewidth}#1\end{minipage}}\hfill%
\adjustbox{valign=t}{\begin{minipage}[c]{.#3\linewidth}\includegraphics[width=\linewidth]{#2}\end{minipage}}\par}
\parskip2em plus 1em minus 1em 
\begin{document}

\begin{wrapfigure}[6]{r}[0pt]{3cm} 
\includegraphics[width=\linewidth]{example-image-a}
\end{wrapfigure}

\lipsum[1] 

\lipsum[2]

\parimg{\lipsum[3]}{example-image-b}{4}

\parimg{\lipsum[4]}{example-image-c}{3}

\lipsum[5]

\end{document}
Fran
  • 80,769
  • Thank you. Do you know if minipages are ordered automatically? I mean, if I create 4 minipages of half textwidth do I have two on top and two below? Can I do a minipage inside a minipage? – lesolorzanov Feb 13 '17 at 11:09
  • Also, I am doing a book. and indeed I dont like tha tufte style I think it wastes to much space. – lesolorzanov Feb 13 '17 at 12:31
  • @ZloySmiertniy (1) Ordered minipages? Do you mean with numbered captions? Use \cap­tionof of caption or capt-of packages. (2) Yes, you can have nested minipages, but I do not see the utility here. (3) the margin of tufte class do not waste space, it have a wide \marginparwidth reserving space for figures and so on, but you can change margins as you want, please try for instance \newgeometry{lmargin=1cm,rmargin=5cm} to the preamble of my MWE, and change also the \marginparwidth to see the effect. – Fran Feb 13 '17 at 14:11
  • I reformulated the question and made a new image. Can you help me? – lesolorzanov Feb 13 '17 at 16:57
  • Nice! I didn't know the parimg command. – lesolorzanov Feb 14 '17 at 18:55
  • 1
    @ZloySmiertniy Of course you do not know him, I just made it up. Note that I define it in the preamble. But It's nothing special, it just to type less commands. – Fran Feb 14 '17 at 19:00
  • Silly me, didnt see it before. Interesting, now I ahve to make it work inside an enumerate. Thank you very much. – lesolorzanov Feb 15 '17 at 10:55