Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to make the algorithm2e environments wider in a beamer document. Indeed I must you a \scalebox to see all of my algorithm. Is there a way to have wider algorithms with smaller size font than the standard text WITHOUT using scalebox ? The size in my M(merely not)WE looks good for me.

OUTPUT

enter image description here

M(merely not)WE

\documentclass{beamer}
    \usepackage[utf8]{inputenc}

    \usepackage[french]{babel}

    \usepackage[french, lined]{algorithm2e}

    \usepackage{beamerthemesplit}


\begin{document}

\frame{
    \frametitle{Premier algorithme}

\scalebox{0.65}{
\begin{algorithm}[H]
    \Begin{
        \ForEach{Case $C$ de la grille $G$}{
            \If{$| poss(C) | \geq 2$}{
                \ForEach{$p \in poss(C)$}{
                    $isole \leftarrow Vrai$
                    \\
                    \ForEach{Bloc $B$ contenant la case $C$}{
                        \ForEach{Case $C_B \neq C$ du bloc $B$}{
                            \If{$p \in poss(C_B)$}{
                                $isole \leftarrow Faux$
                                \\
                                Ne plus tester d'autres cases $C_B$.
                            }
                        }
                        \If{$isole = Vrai$}{
                            $g_{ij} \leftarrow \{ p \}$ où $(i,j) = coord(C)$
                            \\
                            $G \leftarrow \texttt{MettreAJour}(G)$
                            \\
                            Ne plus tester les blocs $B$ contenant $C$
                        }
                    }
                    \If{$isole = Vrai$}{
                        Ne plus tester les possibilités restantes de la case $C$
                    }
                }
            }
        }
        \Return $G$
    }
\end{algorithm}
}   
}

\end{document}
share|improve this question

1 Answer 1

up vote 4 down vote accepted

The problem here is obvious... :)

You're scaling down the regularly allowed \textwidth algorithm to 65% of its original size. Since this scaling is done after setting the algorithm, the traditional line breaks still remain, making it seem like the algorithm is "cut short" on the right hand side.

Here's an abbreviated version of your algorithm showing the traditional line break:

enter image description here

Here's an update, where the algorithm is first set in a minipage of width 1.53846\textwidth, which makes \scalebox{0.65} result in a box of width \textwidth (that is, 1.53846 x 0.65 ~ 1):

enter image description here

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage[lined]{algorithm2e}
\usepackage{beamerthemesplit}
\begin{document}

\begin{frame}
  \frametitle{Premier algorithme}

  \scalebox{0.65}{%
  \begin{algorithm}[H]
    \Begin{
      \ForEach{Case $C$ de la grille $G$}{
        \If{$| poss(C) | \geq 2$}{
          \ForEach{$p \in poss(C)$}{
            $isole \leftarrow Vrai$
            \If{$isole = Vrai$}{
              Ne plus tester les possibilités restantes de la case $C$
            }
          }
        }
      }
      \Return $G$
    }
  \end{algorithm}}
\end{frame}   

\begin{frame}
  \frametitle{Premier algorithme}

  \scalebox{0.65}{\begin{minipage}{1.53846\textwidth}
  \begin{algorithm}[H]
    \Begin{
      \ForEach{Case $C$ de la grille $G$}{
        \If{$| poss(C) | \geq 2$}{
          \ForEach{$p \in poss(C)$}{
            $isole \leftarrow Vrai$
            \If{$isole = Vrai$}{
              Ne plus tester les possibilités restantes de la case $C$
            }
          }
        }
      }
      \Return $G$
    }
  \end{algorithm}%
  \end{minipage}}
\end{frame}   

\end{document}

If you wish to retain the natural look of the algorithm without using \scalebox, algorithm2e provides \SetAlFnt{<font>} where you can set the font size (or other font formatting options) for the entire algorithm. For example, \SetAlFnt{\footnotesize} will decrease the font size to \footnotesize.

share|improve this answer
    
I know that. I've put in my question. The problem is that other algorithms are longer. So I would like to have a wider algorithm together with a smaller size for font in algorithms WITHOUT using scalebox. –  projetmbc Mar 7 '13 at 21:55
    
Perhaps you're after \SetAlFnt, which you can use to set the font size of the algorithm. I've added that to my answer. –  Werner Mar 7 '13 at 22:04
    
That will do the job (I hope). –  projetmbc Mar 7 '13 at 22:17
    
@projetmbc: In addition to setting the font, perhaps you can modify the indent as well. This is done using \SetInd{<before rule>}{<after rule>}. Default is \SetInd{0.5em}{1em}. –  Werner Mar 7 '13 at 22:20
    
Is it christmas ? Thanks for this 2nd indication. :-) –  projetmbc Mar 7 '13 at 22:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.