Tikz:精确的标注定位

Tikz:精确的标注定位

代码:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,shapes}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
[
  node distance=0.05cm,
  note/.style={draw,fill=white,rectangle callout,minimum height=4ex},
  content/.style={draw,fill=white, ellipse, }
 ]

 %internal margin of the bordering box    
 \newlength\height
 \setlength\height{10pt}

 % nodes
 \node[content] (1) {V};
 \node[content, right = of 1] (2) {$\alpha$};

 % callout - here I don't like hard-coded values 6pt and 0.55
  \node[note, below = \height+6pt of 2.south, 
  callout relative pointer={(0,0.55)}] (2-1) {important coefficient};

  % background
  \begin{scope}[on background layer]
    \draw[fill=gray!0] ($(1.south west)+(-2\height,-\height)$) 
    rectangle ($(2.north east)+(2\height,\height)$);
  \end{scope}

 \end{tikzpicture}
\end{document}

给出这个:

在此处输入图片描述

  1. 是否可以将“重要系数”标注箭头附加到 的南面\alpha?目前,它以一种丑陋的硬编码方式完成,使用(0, 0.55)。如果我更改圆的高度\alpha,它就会断裂。
  2. 我怎样才能将标注“重要系数”\height距离置于边框底线下方?目前我使用硬编码值:below = \height+6pt of 2.south

答案1

您可以使用 确保调出指针最终位于节点底部\alphacallout absolute pointer={(2.south)}要将调出框定位在框下方的某个垂直距离处,我会coordinate在框的底部边缘引入一个新的,并在调出的位置使用它:如果您at=(2.south|-box), anchor=north, yshift=-\height在调出选项中说,north调出的锚点将放置\height在 x 位置为(2.south)和 y 位置为 的下方box

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,shapes}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
[
  node distance=0.05cm,
  note/.style={draw,fill=white,rectangle callout,minimum height=4ex},
  content/.style={draw,fill=white, ellipse, }
 ]

 %internal margin of the bordering box    
 \newlength\height
 \setlength\height{10pt}

 % nodes
 \node[content] (1) {V};
 \node[content, right = of 1] (2) {$\alpha$};



  % background
  \begin{scope}[on background layer]
    \draw[fill=gray!0] ($(1.south west)+(-2\height,-\height)$) coordinate (box)
    rectangle ($(2.north east)+(2\height,\height)$);
  \end{scope}

  % If you're using the CVS version of TikZ, you can use the more convenient callout absolute pointer...
  %\node[note, callout absolute pointer={(2.south)}, at={(2.south|-box)}, yshift=-\height, anchor=north] (2-1)  {important coefficient};
  % ...otherwise, you'll have to use callout relative pointer with a calc expression
    \node[note, callout relative pointer={($(2.south)-(2.south|-box)+(0,\height)$)}, at={(2.south|-box)}, yshift=-\height, anchor=north] (2-1)  {important coefficient};
 \end{tikzpicture}
\end{document}

相关内容