垂直对齐文本和 tikZ 图片

垂直对齐文本和 tikZ 图片

这是我现在的幻灯片: 在此处输入图片描述

\documentclass{beamer}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{backgrounds}

\begin{document}

\begin{frame}
\frametitle{My slide}

\begin{tikzpicture}[framed, background rectangle/.style={thick, draw=black, top color=blue!50, rounded corners}]
\node (step1) at (0, 0) {step 1};
\node (step2) at (0, -3) {step 2};
\end{tikzpicture}
\end{frame}

\end{document}

我想在“步骤 1”旁边写一些内容,在“步骤 2”旁边写一些其他内容。我想写这两件事超出范围。 你能帮助我吗?

答案1

您还可以使用库pgfonlayer中提供的功能backgrounds。加载positioning库,然后您可以执行类似下面的操作。

\documentclass{beamer}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{backgrounds,positioning,fit}

\begin{document}

\begin{frame}
\frametitle{My slide}

\begin{tikzpicture}
\node (step1) at (0, 0) {step 1};
\node (step2) at (0, -3) {step 2};
\begin{pgfonlayer}{background}
\node [fit = (step1) (step2),framed, thick, draw=black, top color=blue!50, rounded corners] {};
\end{pgfonlayer}
\node [right=0.2cm of step1, anchor = west] {Text beside step1};
\node [right=0.2cm of step2, anchor = west] {Text beside step2};
\end{tikzpicture}
\end{frame}

\end{document}

答案2

通过fit库,您可以在step1和周围绘制一个框架step2。然后,您可以使用base锚点来对齐一些文本:

在此处输入图片描述

\documentclass{beamer}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{fit,backgrounds}

\begin{document}

\begin{frame}
  \frametitle{My slide}

  \begin{tikzpicture}
    \node (step1) at (0, 0) {step 1};
    \node (step2) at (0, -3) {step 2};

    \begin{scope}[on background layer]
      \node[fit=(step1)(step2),thick,draw=black,top
      color=blue!50,rounded corners] (frame set){};
    \end{scope}

    \node[anchor=base west] at (frame set.east |- step1.base)
    {something right next to step1};

    \node[anchor=base west] at (frame set.east |- step2.base)
    {something right next to step2};

  \end{tikzpicture}
\end{frame}

\end{document}

答案3

一种解决方案是简单地将文本添加到节点并使用,\rlap这样不会影响边界框:

在此处输入图片描述

代码:

\documentclass{beamer}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{backgrounds}

\begin{document}

\begin{frame}
\frametitle{My slide}

\begin{tikzpicture}[framed, background rectangle/.style={thick, draw=black, top color=blue!50, rounded corners}]
\node (step1) at (0,  0) {step 1 \rlap{\hspace*{0.5cm} Details of Step 1}};
\node (step2) at (0, -3) {step 2 \rlap{\hspace*{0.5cm} Details of Step 2}};
\end{tikzpicture}
\end{frame}

\end{document}

相关内容