[Tex/LaTex] how to get a newline in \fbox

boxesline-breaking

I am trying to have two lines in inside \fbox but is not working. Below is my code

\documentclass{beamer}
\usepackage{vietnam}
\begin{document}
\begin{frame}
\frametitle{Exhaustive Search}
{\centering\fbox{ One billion searches per second $\Rightarrow 36 yrs \newline All this to recover only $10$ bits !}}
\end{frame}
\end{document}

Update:

enter image description here

Best Answer

A \fbox doesn't admit line breaks. You have, however, several posiibilities:

Use a \parbox (or a minipage) inside the \fbox:

\documentclass{beamer}
\usepackage{vietnam}
\begin{document}
\begin{frame}
\frametitle{Exhaustive Search}
\fbox{\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule\relax}{\centering One billion searches per second $\Rightarrow$ 36 yrs  \\ All this to recover only $10$ bits !}}%
\end{frame}
\end{document}

enter image description here

Inside the \fbox, Use a varwidth environment from the varwidth package if you want the width to adjust automatically:

\documentclass{beamer}
\usepackage{vietnam}
\usepackage{varwidth}

\begin{document}
\begin{frame}
\centering
\fbox{\begin{varwidth}{\textwidth}
\centering
One billion searches per second $\Rightarrow$ 36 yrs  \\ All this to recover only $10$ bits !
\end{varwidth}}
\end{frame}
\end{document}

enter image description here

Or use a box defined using tcolorbox:

\documentclass{beamer}
\usepackage{vietnam}
\usepackage[most]{tcolorbox}
\tcbuselibrary{fitting}

\begin{document}
\begin{frame}
\frametitle{Exhaustive Search}
\begin{tcolorbox}[minipage,colback=white,arc=0pt,outer arc=0pt]
\centering
One billion searches per second $\Rightarrow$ 36 yrs \\ All this to recover only $10$ bits !
\end{tcolorbox}
\end{frame}
\end{document}

enter image description here

Or a TikZ \node with the align key:

\documentclass{beamer}
\usepackage{vietnam}
\usepackage{tikz}

\begin{document}
\begin{frame}
\frametitle{Exhaustive Search}
\centering
\tikz
  \node[draw,align=center]
  {One billion searches per second $\Rightarrow$ 36 yrs \\ All this to recover only $10$ bits !};
\end{frame}
\end{document}

enter image description here

Or...