5

这个问题是由这里的问题引起的

我想制作一个跨越一些文本行的花括号。问题是我必须手动对齐 x 坐标,这不是一个干净的解决方案。

目前我使用

\begin{frame}{Example}

\begin{itemize}
\item The long Issue 1
\tikz[remember picture] \node[coordinate,yshift=0.7em] (n1) {}; \\
spanning 2 lines


\item Issue 2
  \tikz[remember picture] \node[coordinate, xshift=1.597cm] (n2) {};
\item Issue 3

\end{itemize}

\visible<2->{
\begin{tikzpicture}[overlay,remember picture]
  \draw[thick,decorate,decoration={brace,amplitude=5pt}]
        (n1) -- (n2) node[midway, right=4pt] {One and two are cool};
\end{tikzpicture}
 } % end visible

\end{frame}

这会产生所需的结果:

tikz 示例1

不满意的是,我不得不通过反复试验(或多或少)计算出 1.597cm 的 xshift 值

如果没有 xshift 参数,结果是:

tikz 示例 1

我想有一种优雅的方法可以避免显式的 xshift 值。

恕我直言,最好的方法是计算两个节点的最大 x 值并使用它,(正如Geoff已经建议的那样)

但是,能够显式定义两个节点的绝对 x 值同时保持它们当前的 y 值已经非常方便了。这将避免调整小数点后第三位以确保大括号看起来垂直的繁琐程序。

4

2 回答 2

6

这需要\usetikzlibrary{calc}. 不过,可能有更清洁的方法。

xshift从节点中删除“ ” n2,然后使用:

\begin{tikzpicture}[overlay,remember picture]
  \path (n2) -| node[coordinate] (n3) {} (n1);
  \draw[thick,decorate,decoration={brace,amplitude=5pt}]
        (n1) -- (n3);
  \node[right=4pt] at ($(n1)!0.5!(n3)$) {One and two are cool};
\end{tikzpicture}
于 2010-05-06T14:42:22.683 回答
1

这是一个使用 fit 库的版本,它不需要您担心哪条线最长,但会以标记每条线为代价。

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{fit}

\newcommand{\bracemark}[1]{\tikz[remember picture] \node[inner sep=0pt] (#1) {\vphantom{X}};}

\begin{document}
\begin{frame}{Example}

\begin{itemize}
\item The long Issue 1        \bracemark{n1} \\
gratuitious long line of text \bracemark{n2} \\
spanning 3 lines              \bracemark{n3}

\item Issue 2                 \bracemark{n4}
\item Issue 3

\end{itemize}

\visible<2->{
\begin{tikzpicture}[overlay,remember picture]
  \node [inner sep=0pt, fit=(n1) (n2) (n3) (n4)] (bracemarks) {};
  \draw[thick,decorate,decoration={brace,amplitude=5pt}]
        (bracemarks.north east) -- (bracemarks.south east) node[midway, right=4pt] {One and two are cool};
\end{tikzpicture}
 } % end visible

\end{frame}

\end{document}

输出图像

通过使节点成为具有零宽度 X 作为文本的实际节点(而不是坐标)来避免 OP 样本中所需的 yshift。

于 2017-02-06T03:13:37.603 回答