0

So I am fairly new to Latex and I am a bit clueless. I am trying to make text wrap around a table and I found useful packages, however I can't seem to make it work. My wraptable environment always seems to end up at the end of the text instead of where I place it. I suspect it has something to do with the \justify command that I specify at the beginning, because removing it makes it actually work just fine. However, this doesn't seem like a solution because I need my text to be justified.

So my question is, how do I get wrapfigure to work? Here are some working examples:

\documentclass{article}

\usepackage{threeparttable}
\usepackage{ragged2e}
\usepackage{wrapfig}
\usepackage{lipsum}
\usepackage{floatflt}

\begin{document}
\justify
\section{Introduction} 

   \lipsum[1] 

\begin{wraptable}{l}{5cm}
\caption{Multilevel Linear Regression - Main Model Results}
\label{Table1}
\begin{tabular}{l c }
\hline
 & Model A1 \\
\hline
(Intercept)            & $\mathbf{43.53} \; (2.36)^{***}$  \\
Male (0/1)             & $\mathbf{-1.74} \; (0.39)^{***}$  \\
Age                    & $\mathbf{-4.59} \; (0.98)^{***}$  \\
\hline
\end{tabular}
 \begin{tablenotes}
      \scriptsize
  \item $^{***}p<0.001$, $^{**}p<0.01$, $^*p<0.05$, $^{\dagger}p<0.1$. 
    \end{tablenotes}
\end{wraptable} 

\lipsum[1] 

\section{Theory} 

\lipsum[1] 


\end{document}

Which leaves the table at the end of the text.

1
  • Don't mix floatflt and wrapfig, as they wind up fighting eash other. BTW, the LaTeX command for justify is \fussy or \sloppy. Apr 3, 2017 at 2:07

1 Answer 1

1

Here is a solution with the plain TeX macro package insbox. It often works where wrapfig doesn't work well. There are problems to add a caption, for some reason I do not understand,but it is circumvented putting the table/figure in a minipage, and using \captionof instead of \caption.

We have to use the \InsertBoxL command, which uses two mandatory arguments: the number of lines that remain untouched before inserting the box, and the contents of the box. We can use (lat argument) an optional argument, which is the number of supplementary lines to shorten, in case Tex does not calculate adequately the vertical space required for the insertion.

\documentclass{article}
\usepackage[utf8]{inputenc} 
\usepackage{ragged2e}
\usepackage{wrapfig}
\usepackage{lipsum, caption, booktabs, threeparttable}
\input{insbox.tex}

\begin{document}
\justify
\section{Introduction}

\lipsum[1]

\InsertBoxL{0}{
  \begin{minipage}{5.25cm}
    \captionsetup{skip=6pt, font=small}
    \begin{threeparttable}
      \captionof{table}{Multilevel Linear Regression – Main Model Results}\label{Table1}
      \begin{tabular}{l c }
        \toprule
                    & Model A1 \\
        \midrule
        (Intercept) & $\mathbf{43.53} \; (2.36)^{***}$ \\
        Male (0/1) & $\mathbf{-1.74} \; (0.39)^{***}$ \\
        Age & $\mathbf{-4.59} \; (0.98)^{***}$ \\
        \bottomrule
      \end{tabular}
      \begin{tablenotes}[flushleft]
        \smallskip \scriptsize
        \item $^{***}p<0.001$, $^{**}p<0.01$, $^*p<0.05$, $^{\dagger}p<0.1$.
      \end{tablenotes}
    \end{threeparttable}
  \end{minipage}}[4]

Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi
auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et,
tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna,
vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis. Suspendisse
ut massa. Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatibus et
magnis dis parturient montes, nascetur ridiculus mus. Aliquam tincidunt urna.
Nulla ullamcorper vestibulum turpis. Pellentesque cursus luctus mauris.
Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at,
tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy
pellentesque ante. Phasellus adipiscing semper elit. Proin fermentum massa
ac quam. Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. Mae-
cenas lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, ipsum.
Morbi blandit ligula feugiat magna. Nunc eleifend consequat lorem. Sed lacinia
nulla vitae enim. Pellentesque tincidunt purus vel magna. Integer non enim.
Praesent euismod nunc eu purus. Donec bibendum quam in tellus. Nullam cur-
sus pulvinar lectus. Donec et mi. Nam vulputate metus eu enim. Vestibulum
pellentesque felis eu massa.

\section{Theory}

\lipsum[1]

\end{document} 

enter image description here

7
  • If I remember correctly insbox expects a box as its argument. \caption wouldn't be inside a box with tabular so it breaks insbox's assumption. Therefore minipage (or something other which puts everything into a box) is required if you want a caption.
    – Skillmon
    Apr 1, 2018 at 20:51
  • That's right. It also can be a \parbox or a tabularx – anything which allows line breaking.
    – Bernard
    Apr 1, 2018 at 21:01
  • I just noted this because you wrote "for some reason I do not understand..."
    – Skillmon
    Apr 1, 2018 at 21:03
  • Oh! yes. You can't use caption (which is associated to floats). I don't know the details, but you have to use use \captionof.
    – Bernard
    Apr 1, 2018 at 21:07
  • That's because figure and table define \@captype and \caption checks whether this is defined. If not, it fails because it knows it's not used inside of a float. \captionof does only circumvent that by first defining \@captype and then calling \caption.
    – Skillmon
    Apr 1, 2018 at 21:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .