7

I would like to wrap the text in an enumerate environment around a table, this is my actual situation (sorry for including so much code, but I wanted to give a precise idea of the number of lines in the enumerate environment):

\subsection{Given the following data set where “Target 2” represent the class attribute, 
compute the naive Bayesian classification for the instance $<L,white>$ and $<XS,?>$.}
\begin{table}[h!t]
\centering
\begin{tabular}{ccc}
    \toprule    
    Size        &   Color   &   Target2 \\
    \midrule
    XS      &   green   &   Yes     \\
    L       &   green   &   Yes     \\
    XS      &   white   &   No      \\
    M       &   black   &   No      \\
    XL      &   green   &   Yes     \\
    XS      &   white   &   Yes     \\
    L       &   black   &   No      \\
    M       &   green   &   Yes     \\
    \bottomrule
\end{tabular}
\end{table}
\begin{enumerate}
    \item In this case the experience $E$ is made up of $e_{1} = L$ and $e_{2} = white$, 
        which in Naive Bayes are to be considered as independent, therefore we have:
        \begin{align*}
            P(yes|E) &= P(L|yes)\cdot P(white|yes) \cdot P(yes)     \\
                     &= \sfrac{1}{5}\times \sfrac{1}{5} \times \sfrac{5}{8} \\
                     &= 0.025
        \end{align*}
        \begin{align*}
            P(no|E) &= P(L|no) \cdot P(white|no) \cdot P(no) \\
                    &= \sfrac{1}{3} \times \sfrac{1}{3} times \sfrac{3}{8}  \\
                    &= 0.041
        \end{align*}
        Then we normalize:
        \begin{align*}
            P(yes) &= \frac{0.025}{0.066}  
                    \simeq 0.38 
        \end{align*}
        \begin{align*}
            P(no) &= \frac{0.041}{0.066} 
                   \simeq 0.62
        \end{align*}
        As $P(no) > P(yes)$, we label $<L,white>$ as ``no''.
    \item Now we have to classify a sample with a missing value. During the testing phase 
        we simply omit the attribute\footnote{Classification Other Methods, slide 24}:
        \begin{align*}
            P(yes|XS) &= P(XS|yes) \cdot P(yes) = \sfrac{2}{5} \times \sfrac{5}{8}
                      = 0.25
        \end{align*}
        \begin{align*}
            P(no|XS) &= P(XS|no) \cdot P(no) 
                     = \sfrac{1}{3} \times \sfrac{3}{8}
                     = 0.125
        \end{align*}
        Let us normalize
        \begin{align*}
            P(yes) &= \sfrac{0.25}{0.375} \simeq 0.7 \\
            P(no)  &= \sfrac{0.125}{0.375} \simeq 0.3
        \end{align*}
        Bottom line this sample is classified as ``yes''.
\end{enumerate}

I have tried using the wrapfig and the floatftl package unsuccessfully, the table was moved to the end of the list in both cases. I have considered using two minipage environments, but I would like the text to actually wrap around the table.

12

It helps when you post questions to make complete documents including loading all the packages you need, I guessed

\usepackage{booktabs,xfrac,amsmath}

in this case. Also I fixed a few font issues (for multi-letter identifiers and angle brackets)

Changing margins within a LaTeX list is a bit delicate, but this is I think the layout you want

enter image description here

\documentclass{article}

\usepackage{booktabs,xfrac,amsmath}

\begin{document}

\subsection{Given the following data set where “Target 2” represent the class attribute, 
compute the naive Bayesian classification for the instance $\langle L,white\rangle$ and $\langle \mathit{XS},?\rangle$.}

\savebox0{%
\begin{tabular}{ccc}
    \toprule    
    Size        &   Color   &   Target2 \\
    \midrule
    XS      &   green   &   Yes     \\
    L       &   green   &   Yes     \\
    XS      &   white   &   No      \\
    M       &   black   &   No      \\
    XL      &   green   &   Yes     \\
    XS      &   white   &   Yes     \\
    L       &   black   &   No      \\
    M       &   green   &   Yes     \\
    \bottomrule
\end{tabular}}

\begin{enumerate}
\makeatletter
\dimen@\wd0
\advance\dimen@2em
\advance\rightmargin-\dimen@
\advance\linewidth-\dimen@
\parshape \@ne \@totalleftmargin \linewidth
\hbox to \textwidth{\hfill\vtop to \z@{\vskip1em \box\z@\vss}}
   \item

 In this case the experience $E$ is made up of $e_{1} = L$ and $e_{2} = \mathit{white}$, 
        which in Naive Bayes are to be considered as independent, therefore we have:
        \begin{align*}
            P(\mathit{yes}|E) &= P(L|\mathit{yes})\cdot P(\mathit{white}|\mathit{yes}) \cdot P(\mathit{yes})     \\
                     &= \sfrac{1}{5}\times \sfrac{1}{5} \times \sfrac{5}{8} \\
                     &= 0.025
        \end{align*}
        \begin{align*}
            P(\mathit{no}|E) &= P(L|\mathit{no}) \cdot P(\mathit{white}|\mathit{no}) \cdot P(\mathit{no}) \\
                    &= \sfrac{1}{3} \times \sfrac{1}{3} \times \sfrac{3}{8}  \\
                    &= 0.041
        \end{align*}

\advance\rightmargin\dimen@
\advance\linewidth\dimen@
\parshape \@ne \@totalleftmargin \linewidth

        Then we normalize:
        \begin{align*}
            P(\mathit{yes}) &= \frac{0.025}{0.066}  
                    \simeq 0.38 
        \end{align*}
        \begin{align*}
            P(\mathit{no}) &= \frac{0.041}{0.066} 
                   \simeq 0.62
        \end{align*}
        As $P(\mathit{no}) > P(\mathit{yes})$, we label $\langle L,\mathit{white}\rangle$ as ``no''.



    \item Now we have to classify a sample with a missing value. During the testing phase 
        we simply omit the attribute\footnote{Classification Other Methods, slide 24}:
        \begin{align*}
            P(\mathit{yes}|\mathit{XS}) &= P(\mathit{XS}|\mathit{yes}) \cdot P(\mathit{yes}) \\
&= \sfrac{2}{5} \times \sfrac{5}{8}\\
                      &= 0.25
        \end{align*}
        \begin{align*}
            P(\mathit{no}|\mathit{XS}) &= P(\mathit{XS}|\mathit{no}) \cdot P(\mathit{no})\\ 
                     &= \sfrac{1}{3} \times \sfrac{3}{8}\\
                     &= 0.125
        \end{align*}
        Let us normalize
        \begin{align*}
            P(\mathit{yes}) &= \sfrac{0.25}{0.375} \simeq 0.7 \\
            P(\mathit{no})  &= \sfrac{0.125}{0.375} \simeq 0.3
        \end{align*}
        Bottom line this sample is classified as ``yes''.
\end{enumerate}


\end{document}
  • Not quite right: note the "therefore we have:" is stretched out. That's probably fixable but a workaround is to put a blank line after that line, before the following align. – David Carlisle Apr 29 '12 at 13:27
  • I had noticed that, but I guess that a \hfill should do the job. Still it is a great answer, even though I hoped there was some package to manage these situations, thank you very much again. – gcedo Apr 29 '12 at 13:30
  • @DavidCarlisle I have faced the same problem, but with documentclass tikzposter. Using your solution, I get a bunch of errors. Is there any short modification of your solution? – Antoine Oct 10 '16 at 14:32
  • @Antoine See the first line of this answer, no way I can address that and in anycase best not to add new questions on comments of 4 year old answers. Ask a new question with a complete example that demonstrates the problem, you can link to this answer in your question. – David Carlisle Oct 10 '16 at 14:47
  • @DavidCarlisle I did not know, how to link the answer, but nevertheless, here is a new question. – Antoine Oct 11 '16 at 11:30

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.