0

I'm using an algorithm2e block in the tufte-latex book and I would like to try to make it full width. I know that the question has been asked here: tufte-latex: Full-width algorithm2e blocks

but using a minipage is not an option for me because it messes up with all the floats. Is there a way to create a version of the algorithm environment that spans the full width without messing with the floats?

Minimum (non-working) example

\documentclass[a4paper,justified]{tufte-book}
\usepackage[ruled,vlined,linesnumbered]{algorithm2e}

\begin{document}
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt, ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? [33] At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio, cumque nihil impedit, quo minus id, quod maxime placeat, facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet, ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat

%\begin{fullwidth}
%\begin{minipage}{\linewidth}
\begin{algorithm}[p]

\KwIn{$N$: number of intervals, $S$: space size, $d_1$: first interval, $P$: number of iteration (precision)}
\KwOut{The ratio $r$}
$m \gets S/d_1$\;


  \uIf{$m=N$}{
    \tcc{There is no solution in this case, we can perhaps throw an error!}
  }
  \uElseIf{$m < N$}{
    \tcc{There is one solution between 0 and 1. We unleash the bisection algorithm!}
    xleft $\gets 0$\;
    xright $\gets 1$\;
    \For{$i \gets 1$ \textbf{to} $P$}{
    xcandidate $\gets 0.5*(\textrm{xright} + \textrm{x\_left})$\;
    ymonomial $\gets pow(\textrm{xcandidate}, N)$\;
    yline $\gets \textrm{xcandidate}\cdot m/2 -m+1$\;
    \eIf{$\textrm{ymonomial} \geq \textrm{yline}$}{
       xleft $\gets \textrm{xcandidate}$\;
    }{
       xright $\gets \textrm{xcandidate}$\;
    }
   }
   \tcc{We have narrowed down the search to the interval between `left' and `right'. The best we can do now is to output the middle point.}
   \KwRet{$0.5 \cdot \textrm{xright} + \textrm{xleft}$}
  }
  \Else{
      \tcc{There is one solution greater than 1. The first thing we can do is to find a x far enough so that the line is below the monomial. We do that by considering exponentially larger steps: first x=2, then x=4, then x=8, and so on.}
      xleft $\gets 1$\;
      xright $\gets 2$\;
      \While{$pow(\textrm{xright}, N)  < \textrm{xright}\cdot m/2 -m+1$} {
        xright $\gets 2\cdot \textrm{xright}$
      }
      
      \tcc{Now we unleash the very same bisection algorithm as before, paying attention that the extremes are now switched: the right one has the monomial above the line.}

    \For{$i \gets 1$ \textbf{to} $P$}{
    xcandidate $\gets 0.5*(\textrm{xright} + \textrm{x\_left})$\;
    ymonomial $\gets pow(\textrm{xcandidate}, N)$\;
    yline $\gets \textrm{xcandidate}\cdot m/2 -m+1$\;
    \eIf{$\textrm{ymonomial} \geq \textrm{yline}$}{
       xright $\gets \textrm{xcandidate}$\;
    }{
       xleft $\gets \textrm{xcandidate}$\;
    }
   }
   \tcc{Once again, we have narrowed down the search to the interval between `left' and `right'. The best we can do now is to output the middle point.}
   \KwRet{$0.5 \cdot \textrm{xright} + \textrm{xleft}$}
  }
\caption{Find the ratio of a geometric difference progression via bisections}
\label{algo:geometricratio}
\end{algorithm}
%\end{minipage}
%\end{fullwidth} 

Something else that should be in the same page as the stuff before, but goes to the next one if I uncomment the fullwidth/minipage solution, as proposed in https://tex.stackexchange.com/questions/553891/tufte-latex-full-width-algorithm2e-blocks

\end{document}

Thank you very much in advance, Daniele

0

1 Answer 1

0

You can't use the {p} version of algorithm, nor does fullwidth float at all. You can achieve the same effect as {p} using the afterpage package, however.

\documentclass[a4paper,justified]{tufte-book}
\usepackage[ruled,vlined,linesnumbered]{algorithm2e}
\usepackage{afterpage}

\begin{document}
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam eaque ipsa, quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt, explicabo. Nemo enim ipsam voluptatem, quia voluptas sit, aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos, qui ratione voluptatem sequi nesciunt, neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt, ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit, qui in ea voluptate velit esse, quam nihil molestiae consequatur, vel illum, qui dolorem eum fugiat, quo voluptas nulla pariatur? [33] At vero eos et accusamus et iusto odio dignissimos ducimus, qui blanditiis praesentium voluptatum deleniti atque corrupti, quos dolores et quas molestias excepturi sint, obcaecati cupiditate non provident, similique sunt in culpa, qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio, cumque nihil impedit, quo minus id, quod maxime placeat, facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet, ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat

\afterpage{\clearpage\vspace*{0pt plus 1fil}
\begin{fullwidth}
\begin{minipage}{\linewidth}
\begin{algorithm}[H]
\KwIn{$N$: number of intervals, $S$: space size, $d_1$: first interval, $P$: number of iteration (precision)}
\KwOut{The ratio $r$}
$m \gets S/d_1$\;


  \uIf{$m=N$}{
    \tcc{There is no solution in this case, we can perhaps throw an error!}
  }
  \uElseIf{$m < N$}{
    \tcc{There is one solution between 0 and 1. We unleash the bisection algorithm!}
    xleft $\gets 0$\;
    xright $\gets 1$\;
    \For{$i \gets 1$ \textbf{to} $P$}{
    xcandidate $\gets 0.5*(\textrm{xright} + \textrm{x\_left})$\;
    ymonomial $\gets pow(\textrm{xcandidate}, N)$\;
    yline $\gets \textrm{xcandidate}\cdot m/2 -m+1$\;
    \eIf{$\textrm{ymonomial} \geq \textrm{yline}$}{
       xleft $\gets \textrm{xcandidate}$\;
    }{
       xright $\gets \textrm{xcandidate}$\;
    }
   }
   \tcc{We have narrowed down the search to the interval between `left' and `right'. The best we can do now is to output the middle point.}
   \KwRet{$0.5 \cdot \textrm{xright} + \textrm{xleft}$}
  }
  \Else{
      \tcc{There is one solution greater than 1. The first thing we can do is to find a x far enough so that the line is below the monomial. We do that by considering exponentially larger steps: first x=2, then x=4, then x=8, and so on.}
      xleft $\gets 1$\;
      xright $\gets 2$\;
      \While{$pow(\textrm{xright}, N)  < \textrm{xright}\cdot m/2 -m+1$} {
        xright $\gets 2\cdot \textrm{xright}$
      }
      
      \tcc{Now we unleash the very same bisection algorithm as before, paying attention that the extremes are now switched: the right one has the monomial above the line.}

    \For{$i \gets 1$ \textbf{to} $P$}{
    xcandidate $\gets 0.5*(\textrm{xright} + \textrm{x\_left})$\;
    ymonomial $\gets pow(\textrm{xcandidate}, N)$\;
    yline $\gets \textrm{xcandidate}\cdot m/2 -m+1$\;
    \eIf{$\textrm{ymonomial} \geq \textrm{yline}$}{
       xright $\gets \textrm{xcandidate}$\;
    }{
       xleft $\gets \textrm{xcandidate}$\;
    }
   }
   \tcc{Once again, we have narrowed down the search to the interval between `left' and `right'. The best we can do now is to output the middle point.}
   \KwRet{$0.5 \cdot \textrm{xright} + \textrm{xleft}$}
  }
\caption{Find the ratio of a geometric difference progression via bisections}
\label{algo:geometricratio}
\end{algorithm}
\end{minipage}
\end{fullwidth}\newpage}

Something else that should be in the same page as the stuff before, but goes to the next one if I uncomment the fullwidth/minipage solution, as proposed in https://tex.stackexchange.com/questions/553891/tufte-latex-full-width-algorithm2e-blocks

\end{document}
1
  • Fantastic, thanks so much. Dec 14, 2020 at 8:35

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.