tikz:为节点设置适当的x值
这个问题源于问题这里
我想生成一个跨越一些行的大括号的文本。 问题是我必须手动对齐 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}
它产生所需的结果:
令人不满意的是,我必须计算出 xshift 值1.597cm 通过反复试验(或多或少)
没有 xshift 参数,结果是:
我猜有一个避免显式 xshift 值的优雅方法。
恕我直言,最好的方法是计算两个节点的最大 x 值并使用它(正如 Geoff 已经建议的那样) )
但是如果能够显式定义两个节点的绝对 x 值,同时保留它们当前的 y 值,那就已经非常方便了。这将避免调整小数点后第三位以确保大括号看起来垂直的繁琐过程。
This question resulted from the question here
I want to produce a curly brace which spans some lines of text.
The problem is that I have to align the x coordinate manually, which is not a clean solution.
Currently I use
\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}
which produces the desired result:
The unsatisfying thing is, that I had to figure out the xshift value of 1.597cm by trial and error (more or less)
Without xshift argument the result is:
I guess there is an elegant way to avoid the explicit xshift value.
The best way would it imho be to calculate the maximum x value of two nodes and use this, (as already suggested by Geoff)
But it would already be very handy to be able to explicitly define the absolute xvalues of both nodes while keeping their current y values. This would avoid the fiddly procedure of adapting the third post decimal position to ensure that the brace looks vertical.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这需要
\usetikzlibrary{calc}
。不过,可能有一种更清洁的方法。从节点
n2
中删除“xshift
”,然后使用:This requires
\usetikzlibrary{calc}
. There may be a cleaner way, though.Remove the "
xshift
" from noden2
and then use:这是一个使用 fit 库的版本,它不需要您担心哪一行最长,但需要标记每行。
通过将节点设为实际节点(而不是坐标)并使用零宽度 X 作为文本,可以避免 OP 示例中所需的 yshift。
Here's a version using the fit library which doesn't require you to worry about which line is longest, at the expense of marking each line.
The yshift needed in the OP's sample is avoided by making the nodes actual nodes (as opposed to coordinates) with a zero-width X as text.