Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

LaTeX code generated from MarkDown by Pandoc:

\documentclass{article}
\usepackage{mwe}

\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}

\setlength{\parindent}{0pt}

% begin custom preamble
\usepackage{enumitem}
\setlist[description]{style=multiline, leftmargin=4.2cm}

\renewcommand{\descriptionlabel}[1]{%
    \begin{minipage}[t]{4cm}
    \vspace{-\fontcharht\font`(}#1
    \end{minipage}
}
% end custom preamble

\begin{document}
\begin{description}
\itemsep1pt\parskip0pt\parsep0pt
\item[\includegraphics{example-image}]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis
sem. Nullam nec mi et neque pharetra sollicitudin.
\end{description}

\blindtext
\end{document}

Results in: next paragraph overlaps with description label image

Question

I would like to have automatic vertical separation with the next paragraph, only by changing the preamble, not the main document. (Remember, it is code automatically generated by Pandoc!)

share|improve this question

3 Answers 3

It would be possible to make the list environment aware of the image depth, but it is easier to use wrapfig I show two variants, carrying the indent into the following paragraph, or moving the following paragraph down,

enter image description here

\documentclass{article}
\usepackage{mwe,wrapfig}

\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}

\setlength{\parindent}{0pt}

\begin{document}

% Solution 1    
\begin{wrapfigure}{l}{4cm}
\includegraphics{example-image}
\end{wrapfigure}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis
sem. Nullam nec mi et neque pharetra sollicitudin.

\blindtext

\bigskip
\hrule
\bigskip

% Solution 2
\begin{wrapfigure}{l}{4cm}
\includegraphics{example-image}
\end{wrapfigure}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis
sem. Nullam nec mi et neque pharetra sollicitudin.

\blindtext

\end{document}
share|improve this answer
    
I like the first solution. The problem is my LaTeX file is generated by Pandoc. Hence, I can only change the preamble. I am now trying to put your solution inside a \renewenvironment{description}, but I am struggling. –  Serge Stroobandt Aug 19 '13 at 17:58
    
Because of the limitations imposed by the use of Pandoc, a solution where the list environment is made aware of the image depth sounds very interesting. As a matter of fact, this is what I originally hoped for. By the way, Pandoc is needed since it also generates a nice HTML version starting from the same MarkDown source. –  Serge Stroobandt Aug 19 '13 at 20:19
    
What a pity that the picins package is not distributed with the TeXLive distribution. \parpic is namely the only wrapping command fully compatible with list environments. It probably would have been a nice and easy solution. –  Serge Stroobandt Aug 20 '13 at 8:47
    
@on4aa -- perhaps you could persuade the developer of picins to modify it to use the lppl, and provide complete documentation. those appear to be the two criteria that prevent it from being included in tex live. –  barbara beeton Aug 20 '13 at 17:49
up vote 1 down vote accepted

At the end, perseverance pays off. Here is a solution based on floatflt that does wrap the next paragraph properly by only changing the preamble. One of the tricks is in the \hspace{0pt}.

The issue of clearing the float is dealt with here and here.

\documentclass{article}
\usepackage{mwe}

\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}

\setlength{\parindent}{0pt}

% begin preamble.tex
\usepackage{floatflt}
\renewenvironment{description}{%
    \renewcommand{\includegraphics}[1]{\vspace{-1ex}\Oldincludegraphics[width=4cm]{##1}}
    \renewcommand{\item}[1][]{##1\end{floatingfigure}}%
    \hspace{0pt}%
    \begin{floatingfigure}[l]{4cm}}%
    {}
% end preamble.tex

\begin{document}
\begin{description}
\itemsep1pt\parskip0pt\parsep0pt
\item[\includegraphics{example-image-a}]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis
sem. Nullam nec mi et neque pharetra sollicitudin.
\end{description}

\blindtext

\begin{description}
\itemsep1pt\parskip0pt\parsep0pt
\item[\includegraphics{example-image-b}]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis
sem. Nullam nec mi et neque pharetra sollicitudin.
\end{description}

\blindtext
\end{document}

floatflt solution

Remark

It took me (on and off) almost a week to come up with this answer. Compare that to the mere three seconds to issue a {float: left} in order to achieve the same with CSS for the HTML document generated from the same Pandoc MarkDown. This made me really appreciative of questions like these:

share|improve this answer
    
The solution is not compatible (yet?) with \usepackage[nobottomtitles*]{titlesec} in the preamble. –  Serge Stroobandt Aug 29 '13 at 14:31

Here is a solution exclusively based on minipages, height measuring and preamble gymnastics. The only limitation is that it does not wrap, but properly clears space for the images and following paragraph. Nevertheless, I posed a follow-up question in an attempt to achieve real wrapping under these constraints.

\documentclass{article}
\usepackage{mwe}

\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}

\setlength{\parindent}{0pt}

% begin preamble.tex
\usepackage{calc}
\newlength\imgheight

\renewenvironment{description}{%
    \renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=4cm]{##1}}
    \renewcommand{\item}[1][]{%
        \settototalheight\imgheight{##1}%
        \global\imgheight=\imgheight%
        ##1%
        \end{minipage}
        \hfill
        \begin{minipage}[t][\imgheight][s]{\dimexpr\linewidth-4.2cm}
        }
    \begin{minipage}[t]{4cm}
    \vspace{-\fontcharht\font`(}%
    }%
    {%
    \par\vfill%
    \end{minipage}}
% end preamble.tex

\begin{document}
\begin{description}
\itemsep1pt\parskip0pt\parsep0pt
\item[\includegraphics{example-image-a}]
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis
sem. Nullam nec mi et neque pharetra sollicitudin.
\end{description}

\blindtext

\begin{description}
\itemsep1pt\parskip0pt\parsep0pt
\item[\includegraphics{example-image-b}]
\blindtext
\end{description}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.