使用 TikZ 进行区块

使用 TikZ 进行区块

对于 beamer 演示文稿,我使用TikZ它来创建一个带有一些文本的圆形块。以下是工作示例:

\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}

在此示例中,我尝试在区块内写一个很长的句子,但它超出了页边距。有没有办法调整区块大小,使页边距外的单词在区块内的新段落中开始?

请帮忙。

答案1

您可以使用 :text widthminimum width选项

\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}

在此处输入图片描述

答案2

或者,你可以使用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}

在此处输入图片描述

或者只是一个beamercolorbox(见Framed and Boxed Textbeameruserguide

\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}

在此处输入图片描述

相关内容