1

My goal is to make a small box in the top-right of the page that holds a small table. This serves as an "infobox" much like the ones seen on wikipedia pages.

I've implemented this using wrapfigure and it works well except in cases where a verbatim block is near the top of the page:

Wrapfigure conflict with verbatim

Question: What can I do to avoid verbatim blocks colliding with the wrapfigure? I'm open to using something other than wrapfigure.

Constraint: Our authors write in Markdown. Pandoc generates the Latex using a custom template I've written. To solve this I'll need to find a method that doesn't require manually inserting Latex commands to adjust the page layout.

Minimal example:

\documentclass[]{article}
\usepackage{wrapfig}
\newenvironment{infobox}{\wrapfigure{r}{5cm}}{\endwrapfigure}

\begin{document}

\begin{infobox}
BOX

BOX

BOX

BOX

BOX
\end{infobox}

Amet elit esse cupidatat consequat cillum do do sit pariatur dolore minim labore.

\begin{verbatim}
Occaecat veniam nulla elit aute officia sunt culpa exercitation.
\end{verbatim}

Occaecat sunt quis nulla veniam esse elit Lorem minim velit elit. Id ad eu eiusmod sint eu elit minim. Eiusmod culpa commodo aliquip dolor. Est nulla consectetur aliqua tempor. Laborum irure velit sunt dolor fugiat eiusmod elit Lorem minim quis.

\end{document}
  • 1
    I'm afraid you're out of luck: wrapfig uses \parshape, whereas verbatim refers to \linewidth which is not updated (and it would be at least very difficult to do it). – egreg Nov 2 '18 at 13:46
  • Does it have to be verbatim? Here, \sloppy\texttt{...} would suffice. In other cases, \sloppy\texttt{\detokenize{...}} would work. – Steven B. Segletes Nov 2 '18 at 13:51
  • there isn't really anything special about wrapfig here, if you just had a normal paragraph and the verbatim text was wider than the linewidth then it would over-flow as there is no wrapping, so the linewidth is smaller still here but the same would be true in a quote or minipage or enumerate etc... – David Carlisle Nov 2 '18 at 13:52
  • Steven: It probably does need to be verbatim. I can't easily control how Pandoc maps markdown to Latex. It is possible to propose a patch to Pandoc but that would take time and may not succeed, of course. – Brad Dixon Nov 2 '18 at 14:05
2

1. Floating your verbatim

One solution would be to put the verbatim text inside a wrapfigure as well. Float it left and set the width to linewidth. This will make it interact with the infobox.

\documentclass[]{article}
\usepackage{wrapfig}
\newenvironment{infobox}{\wrapfigure{r}{5cm}}{\endwrapfigure}
\begin{document}
\begin{infobox}
BOX\\BOX\\BOX\\BOX\\BOX
\end{infobox}
Amet elit esse cupidatat consequat cillum do do sit pariatur dolore minim labore.
\begin{wrapfigure}{l}{\linewidth}
\begin{verbatim}
Occaecat veniam nulla elit aute officia sunt culpa exercitation.
\end{verbatim}
\end{wrapfigure}
Occaecat sunt quis nulla veniam esse elit Lorem minim velit elit. Id ad eu eiusmod sint eu elit minim. Eiusmod culpa commodo aliquip dolor. Est nulla consectetur aliqua tempor. Laborum irure velit sunt dolor fugiat eiusmod elit Lorem minim quis.
\end{document}

Output:

verbatim text floating

2. Placing verbatim inside a table & minipage (see here)

This allows for more control over when the verbatim is placed, but it's drawback is that you still need to place the text carefully. For example, leaving out the linebreak after the table will cause the verbatim/table to overlap with the text.

\documentclass[]{article}
\usepackage{wrapfig}
\newenvironment{infobox}{\wrapfigure{r}{5cm}}{\endwrapfigure}
\begin{document}
Amet elit esse cupidatat consequat cillum do do sit pariatur dolore minim labore. Occaecat sunt quis nulla veniam esse elit Lorem minim velit elit. Id ad eu eiusmod sint eu elit minim.

\begin{infobox}BOX BOX BOX BOX BOX\\BOX\\BOX\\BOX\\BOX\end{infobox}

\begin{tabular}{ ll }
 &  \begin{minipage}{0.5\linewidth}
    \begin{verbatim}
    Occaecat veniam nulla elit aute officia sunt culpa exercitation.
    \end{verbatim}
    \end{minipage}
\end{tabular}
%THIS LINE MUST BE EMPTY
Eiusmod culpa commodo aliquip dolor. Est nulla consectetur aliqua tempor. Laborum irure velit sunt dolor fugiat eiusmod elit Lorem minim quis.
\end{document}

Output:

verbatim inside table

  • FLonLon... did you notice how this reordered the paragraphs? The order was paragraph, verbatim, paragraph. In your example it is rendered as paragraph, paragraph, verbatim. That is unexpected! I tried it on my end and experienced the same behavior. – Brad Dixon Nov 2 '18 at 17:52
  • @BradDixon yes I did- this behaviour is expected, because floats will behave this way. I didn't realize that the paragraph ordering was important. I've added another option to my answer. – FLonLon Nov 2 '18 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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