Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm new to that forum but it already helped a lot, thanks for this!

But now I really got stuck. Basically I'm looking for a possiblity to reference the xlabel of an axis in a TikZ picture. The intention is to read out the xlabel coordinates. Later on I would like to use them to position another node in a specific way with respect to the these coordinates.

With xlabel style={name=xlabel} I tried to assign the xlabel name in the axis options. Within the axis I wanted to point to it with xlabel.north (like it is possible to point to the axis itself with current axis.north).

Unfortunately it didn't work. I was told:

no shape named xlabel is known

So I guess, that naming the xlabel in the axis options is wrong. Is there a way to solve this problem?

I hope the question is stated such that one can understand what I'm trying to say...

share|improve this question
    
Welcome to TeX.sx! No need to add thanks, simply use upvoting to acknowledge good answers. –  Peter Jansson Feb 2 '13 at 15:58
add comment

2 Answers

up vote 2 down vote accepted

You're probably trying to access the xlabel node before it's created (hard to tell without an example document).

If you put the drawing command inside the axis, the label won't exist yet (it gets placed only after the axis is finished). You'll have to put it outside the axis:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xlabel=X label,
    xlabel style={name=xlabel}
  ]
  \addplot {rnd};
  \end{axis}
  \draw [ultra thick, latex-] (xlabel.south east) -- ++(1,-1);
\end{tikzpicture}
\end{document}
share|improve this answer
    
That is exactly what I was looking for. I think case is closed :-) –  caroussell Feb 3 '13 at 11:13
add comment

Assuming that you are using "pure" tikz (i.e: no pgfplots which would be a completely different issue), the idea is to name some coordinates at the ends of the line, and then build a node which contains both (using fit library). This node can be named as you required. You can only give names to nodes (and coordinates which are a particular type of dimensionless node).

Following is a MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fit}
\begin{document}

\begin{tikzpicture}
\coordinate (start) at (0,0);
\coordinate (end) at (3,0);
\draw[->] (start) -- (end);
\node[fit=(start) (end), draw=none, inner sep=1pt] (axis) {};

% The line is contained in node "axis" which we can use
\draw (axis.south) node[below] {Foo}
      (axis.east)  node[right] {Bar}
      (axis.west)  node[left]  {XX};
\end{tikzpicture}
\end{document}

And produces:

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.