4

For a beamer presentation I am using TikZ for creating a rounded block with some text in it. The following is the working example:

\documentclass{beamer} %
\usetheme{CambridgeUS}
\usepackage[latin1]{inputenc}
\usefonttheme{professionalfonts}
\usepackage{times,textpos}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes}

\author{Author}
\title{Presentation title}

\begin{document}

\begin{frame}{TIkZ}
 \begin{textblock*}{2.50cm}(0.5cm,0.25cm)

    \begin{tikzpicture}
    \node [fill=green!30, rounded corners=6pt] {{\color{blue}How to write a very very very very long sentence in two lines inside this block using tikz}};
    \end{tikzpicture}

  \end{textblock*}
\end{frame}

\end{document}

In this example I am trying to write a very long sentence inside the block, but it goes the outside the page margins. Is there any way to adjust the block size such that words outside the margin start in a new paragraph inside the block.

Please help.

5

You could use : text width and minimum widthoption

\documentclass{beamer} %
\usetheme{CambridgeUS}
\usepackage[latin1]{inputenc}
\usefonttheme{professionalfonts}
\usepackage{times,textpos}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes}

\author{Author}
\title{Presentation title}

\begin{document}

\begin{frame}{TIkZ}
 \begin{textblock*}{2.50cm}(0.5cm,0.25cm)

    \begin{tikzpicture}
      \node [fill=green!30, rounded corners=6pt,
      font=\color{blue}, minimum width=10cm, text width=10cm] {How to write a very very very very long sentence in two lines inside this block using tikz};
    \end{tikzpicture}

  \end{textblock*}
\end{frame}

\end{document}

enter image description here

5

As an alternative, you could use tcolorbox

\documentclass{beamer} %
\usetheme{CambridgeUS}
\usepackage[latin1]{inputenc}
\usefonttheme{professionalfonts}
\usepackage{times,textpos}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes}
\usepackage{tcolorbox}
\author{Author}
\title{Presentation title}

\begin{document}

\begin{frame}{TIkZ}
\begin{tcolorbox}[colback=green!30,notitle,colframe=green!30,colupper=blue]
How to write a very very very very long sentence in two lines inside this block using \texttt{tcolorbox}
\end{tcolorbox}

\begin{tcolorbox}[width=.5\textwidth, colback=blue!30,notitle,colframe=blue!30,colupper=blue]
How to write a very very very very long sentence in two lines inside this block using \texttt{tcolorbox}
\end{tcolorbox}
\end{frame}

\end{document}

enter image description here

or just a beamercolorbox (see Framed and Boxed Text in beameruserguide)

\documentclass{beamer} %
\usetheme{CambridgeUS}
\usepackage[latin1]{inputenc}
\usefonttheme{professionalfonts}
\usepackage{times,textpos}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes}
\author{Author}
\title{Presentation title}

\begin{document}

\begin{frame}{TIkZ}

\setbeamercolor{myboxcolor}{bg=green!30,fg=blue}
\begin{beamercolorbox}[wd=.8\linewidth,rounded=true]{myboxcolor}
How to write a very very very very long sentence in two lines inside this block using \texttt{beamercolorbox}
\end{beamercolorbox}

\end{frame}

\end{document}

enter image description here

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.