tufte-latex:全宽 algorithm2e 块,无 minipage

tufte-latex:全宽 algorithm2e 块,无 minipage

我正在使用 tufte-latex 书中的 algorithm2e 块,我想尝试使其全宽。我知道这里已经有人问过这个问题: tufte-latex:全宽 algorithm2e 块

但使用 minipage 对我来说不是一个选择,因为它会弄乱所有浮动。有没有办法创建一个跨越整个宽度的算法环境版本,而不会弄乱浮动?

最小(非工作)示例

\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}

非常感谢,Daniele

答案1

您不能使用 {p} 版本的算法,全宽浮动也根本不行。但是,您可以使用 afterpage 包实现与 {p} 相同的效果。

\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}

相关内容