10

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

16

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...

  • All your solutions are great. However, I am observing something strange in my document. The first time I use any of your solution, it works perfectly. But next time the box, itself, does not appear to be in the middle of slide. In fact it is shifted to the left side of slide. I have added my screen shot in original question – NAASI Aug 7 '15 at 15:16
  • @NAASI your description is not enough. We need to see the actual code you are using to diagnose the problem and find a solution. Please consider opening a fresh new question. – Gonzalo Medina Aug 7 '15 at 15:18
  • Its the first \centering command that is not working properly – NAASI Aug 7 '15 at 15:22
  • @NAASI Code, please. Without it we can only guess. – Gonzalo Medina Aug 7 '15 at 15:26
  • my code is visible in the snap shot that i have added. Its same as yours in solution 2. As per your suggestion, I have posted a new question tex.stackexchange.com/questions/259273/… – NAASI Aug 7 '15 at 15:27
3

If you're going to insert manual line-breaks, you might as well construct a tabular:

enter image description here

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

...or using a pure tabular approach:

enter image description here

\documentclass{beamer}
\begin{document}
\begin{frame}
  \frametitle{Exhaustive Search}
  \centering
  \begin{tabular}{|c|}
    \hline
    One billion searches per second $\Rightarrow 36$ yrs \\
    All this to recover only $10$ bits ! \\
    \hline
  \end{tabular}
\end{frame}
\end{document}
  • 1
    I'd prefer \fbox{\begin{tabular}{@{}c@{}}...\\...\end{tabular}} – egreg Aug 7 '15 at 15:27

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.