8

Code:

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

Gives this:

enter image description here

  1. Is it possible to attach the "Important coefficient" callout arrow to the south of \alpha? Currently it is done in an ugly hard-coded way, using (0, 0.55). If I change the height of \alpha circle, it will break.
  2. How can I put the callout "important coefficient" \height distance below the bottom line of the bordering box? Currently I use the hard coded value: below = \height+6pt of 2.south.
user4035
  • 5,035
  • 6
  • 40
  • 57

1 Answers1

5

You can make sure that the callout pointer ends up at the bottom of the \alpha node by using callout absolute pointer={(2.south)}. To position the callout box a certain vertical distance below the box, I would introduce a new coordinate on the bottom edge of the box, and use that in the placement of the callout: If you say at=(2.south|-box), anchor=north, yshift=-\height in the callout options, the north anchor of the callout will be placed \height below the at the x-position of (2.south) and the y-position of 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}
Jake
  • 232,450
  • 2
    I think you are on CVS version. This is not patched on v2.10. http://tex.stackexchange.com/questions/31921/callout-and-beamer/31934#31934 . Relative works but absolute is problematic if I remember correctly. – percusse May 31 '13 at 15:10
  • @percusse: Ah, oops. Thanks for the note, I've edited the answer to include an approach that works with callout relative. – Jake May 31 '13 at 15:15
  • Interesting, why the callout end slightly overlaps the circle border? – user4035 May 31 '13 at 17:49
  • 1
    @user4035: That's because the edge is so sharp. If you use line join=bevel, the tip won't protrude into the circle. – Jake May 31 '13 at 17:53
  • 1
    @Jake Did that. Now it's perfect. – user4035 May 31 '13 at 18:10