如何以特殊的方式将这些算法并列在一起

如何以特殊的方式将这些算法并列在一起

我有以下问题:我想将算法并排放置,使得具有相同编号的行位于相同的高度。不幸的是,到目前为止,它看起来像这样 在此处输入图片描述

我不喜欢的是,它们占用的空间比可用的空间要少得多(这很可能是由于我对 \setstretch 的不熟练),线条经常在不好的地方断开,而且线条不同步(例如,左侧算法中的行号 1 和右侧算法中的行号 1 位于同一高度并彼此相邻。有人能帮我修复它吗?提前谢谢!MWE 如下

梅威瑟:

    \documentclass{beamer}
    \usepackage{tikz}
    \usetikzlibrary{arrows,automata}
    \usepackage[ruled,linesnumbered]{algorithm2e}
    \usepackage{setspace}
    \SetKwInOut{Input}{Input}\SetKwInOut{Output}{Output}
    
        \begin{document}
        \begin{frame}[t]{}
            \begin{minipage}{.45\textwidth}
                \centering
                \scalebox{.7}{
                    \SetAlgoNoLine
                    \begin{algorithm}[H]
                        \setstretch{0.7}
                        \Input{$ S = (S_+, S_-) $}
                        \Output{DFA $ \mathcal{A}(S) $}
                        %                       \Output{DFA $ \mathcal{A} $ which is consistent with $ S $}
                        \BlankLine
                        $ T := PTA(S_+) $\; % noch abändern zu passender Definition
                        $ \sim := \{(u,u) | u \in Q_+\} $\;
                        \For{$ w \in Pref(S_+) $ in llex-order}{
                            \If{$ w \not\sim v $ for all $ v <_{llex} w $}{\label{RPNI-if-check}
                                \For {$ \{v \in S_+ | v <_{llex} w \} $ in llex order}{
                                    $ \sim_{test} :=  $ smallest congruence containing $ \sim $ and $ (v, w) $\;
                                    $ \mathcal{B} := \mathcal{A}(S_+)/\sim_{test} $\;
                                    \If{$ L(\mathcal{B}) \cap S_- = \emptyset $}{
                                        $ \sim := \sim_{test} $\;
                                        GoTo line \ref{rpni-e-exitInnerFor}\;
                                        %exit inner for-loop\;
                                    }
                                }\label{rpni-e-exitInnerFor}
                            }
                        }
                    \Return{$\mathcal{A} := (T, F)$ }\;
                        \caption{RPNI on llex-order}\label{RPNI-eigenFormal}
                    \end{algorithm}
                }
            \end{minipage}
            \begin{minipage}{.45\textwidth}
                \centering
                \scalebox{.7}{
                    \SetAlgoNoLine
                    \begin{algorithm

}[H]
                    \setstretch{0.7}
                    \Input{$S = (S_+, S_-) $}
                    %$ S_+ \neq \emptyset $ eigentlich nicht nötig, wenn man als Automaten, der alles abweist den \varepsilon-Automat sieht
                    \Output{DFA $ \mathcal{A}(S) $}
                    %\Output{DFA $ \mathcal{A} $ which is consistent with $ S $}
                    \BlankLine
                    $ Q := \{\varepsilon\} $; $ \delta := \emptyset $; $ q_0 := \varepsilon $; $ T := (Q, \Sigma, \varepsilon, \delta) $;\\
                    \While {$ Escapes(S_+, T) $}{\label{sprLL-while}
                        $ ua := min_{llex}(Escapes(Pref(S_+), T)) $\;
                        \For {$ \{v | v < w \land v \in S_+\} $ in llex order}{                             
                            \If{$ IsConsistent (T + (\delta^*(u), a, \delta^*(v)), S) $} {
                                $ \delta := \delta \cup \{(\delta^*(u), a, \delta^*(v))\} $\;
                                KwGoTo while (line \ref{sprLL-while})
                            }
                        }
                        
                        $ Q := Q \cup \{ua\} $\;
                        $ \delta :=  \delta \cup \{(\delta^*(u), a, ua)\}$\;
                    }
                    $ F := ComputeAcc (T, S) $\;
                    \Return{$\mathcal{A} := (T, F)$ }\;
                    \caption{Sprout on llex-order}\label{SprG-llex}
                \end{algorithm}
            }
        \end{minipage}
        
    \end{frame} 
    \end{document}

答案1

不要用于\scalebox包含文本的内容。而是选择合适的字体大小:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[ruled,linesnumbered]{algorithm2e}
\usepackage{setspace}
\SetKwInOut{Input}{Input}\SetKwInOut{Output}{Output}
\renewcommand\AlCapFnt{\scriptsize}
\renewcommand\AlCapNameFnt{\AlCapFnt}

\begin{document}
\begin{frame}[t]{}
\begin{columns}[onlytextwidth,T]
  \begin{column}{.48\textwidth}
      \centering
          \scriptsize
          \SetAlgoNoLine
          \begin{algorithm}[H]
              \setstretch{0.7}
              \Input{$ S = (S_+, S_-) $}
              \Output{DFA $ \mathcal{A}(S) $}
                                     \Output{DFA $ \mathcal{A} $ which is consistent with $ S $}
              \BlankLine
              $ T := PTA(S_+) $\; % noch abändern zu passender Definition
              $ \sim := \{(u,u) | u \in Q_+\} $\;
              \For{$ w \in Pref(S_+) $ in llex-order}{
                  \If{$ w \not\sim v $ for all $ v <_{llex} w $}{\label{RPNI-if-check}
                      \For {$ \{v \in S_+ | v <_{llex} w \} $ in llex order}{
                          $ \sim_{test} :=  $ smallest congruence containing $ \sim $ and $ (v, w) $\;
                          $ \mathcal{B} := \mathcal{A}(S_+)/\sim_{test} $\;
                          \If{$ L(\mathcal{B}) \cap S_- = \emptyset $}{
                              $ \sim := \sim_{test} $\;
                              GoTo line \ref{rpni-e-exitInnerFor}\;
                              %exit inner for-loop\;
                          }
                      }\label{rpni-e-exitInnerFor}
                  }
              }
          \Return{$\mathcal{A} := (T, F)$ }\;
              \caption{RPNI on llex-order}\label{RPNI-eigenFormal}
          \end{algorithm}
  \end{column}
      \begin{column}{.48\textwidth}
          \centering
              \SetAlgoNoLine
              \scriptsize
              \begin{algorithm}[H]
              \setstretch{0.7}
              \Input{$S = (S_+, S_-) $}
              %$ S_+ \neq \emptyset $ eigentlich nicht nötig, wenn man als Automaten, der alles abweist den \varepsilon-Automat sieht
              \Output{DFA $ \mathcal{A}(S) $}
              %\Output{DFA $ \mathcal{A} $ which is consistent with $ S $}
              \BlankLine
              $ Q := \{\varepsilon\} $; $ \delta := \emptyset $; $ q_0 := \varepsilon $; $ T := (Q, \Sigma, \varepsilon, \delta) $;\\
              \While {$ Escapes(S_+, T) $}{\label{sprLL-while}
                  $ ua := min_{llex}(Escapes(Pref(S_+), T)) $\;
                  \For {$ \{v | v < w \land v \in S_+\} $ in llex order}{                             
                      \If{$ IsConsistent (T + (\delta^*(u), a, \delta^*(v)), S) $} {
                          $ \delta := \delta \cup \{(\delta^*(u), a, \delta^*(v))\} $\;
                          KwGoTo while (line \ref{sprLL-while})
                      }
                  }
                  
                  $ Q := Q \cup \{ua\} $\;
                  $ \delta :=  \delta \cup \{(\delta^*(u), a, ua)\}$\;
              }
              $ F := ComputeAcc (T, S) $\;
              \Return{$\mathcal{A} := (T, F)$ }\;
              \caption{Sprout on llex-order}\label{SprG-llex}
          \end{algorithm}
  \end{column}
\end{columns}
\end{frame} 
\end{document}

在此处输入图片描述

相关内容