tikz:为节点设置适当的x值 [英] tikz: set appropriate x value for a node

查看:159
本文介绍了tikz:为节点设置适当的x值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题来自问题此处

我想产生一个跨大括号的花括号. 问题是我必须手动对齐x坐标,这不是一个干净的解决方案.

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.

我目前使用

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

产生预期的结果:

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

The unsatisfying thing is, that I had to figure out the xshift value of 1.597cm by trial and error (more or less)

没有xshift参数,结果是:

Without xshift argument the result is:

我想有一种避免显式xshift值的好方法.

I guess there is an elegant way to avoid the explicit xshift value.

最好的方法是计算两个节点的最大x值并使用它,(如 Geoff )

The best way would it imho be to calculate the maximum x value of two nodes and use this, (as already suggested by Geoff)

但是能够显式定义两个节点的绝对x值同时保留其当前y值已经非常方便了.这样可以避免繁琐的调整小数点后第三位以确保括号垂直的过程.

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.

推荐答案

这需要\usetikzlibrary{calc}.不过,也许有一种更清洁的方法.

This requires \usetikzlibrary{calc}. There may be a cleaner way, though.

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

Remove the "xshift" from node n2 and then use:

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

这篇关于tikz:为节点设置适当的x值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆