Just add yticklabels={,,}
to the options for the axis
environment. Your example then looks like shown below.
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
title={Test Axis},
xlabel={Test X Label},
ylabel={Test Y Label},
yticklabels={,,}
]
\end{axis}
\end{tikzpicture}
\end{document}
This feature is documented in Section 4.14.2 (Tick Alignment: Positions and Shifts) on page 180 of the pgfplots 1.4.1 manual. Quite hidden in the last example of the mentioned section.
I guess the reason that your first example doesn't give you the right length is that \pgfmathresult
is overwritten somewhere before it is applied to the option (also you forgot subtracting the inner sep
, this is the reason for the incorrect length in your edit). However, the node is placed correctly below (A1), as the default node alignment is centering.
First step: fix the \pgfmathresult
. The \pgfmathparse
isn't really needed here, we can simply do the following (the default inner sep
between the text and the border is 0.3333em, so we need to subtract twice that for the text width
):
\begin{tikzpicture}[font=\tt]
\node (A1) [shape=circle,draw] {A1};
\node (A2) [shape=circle,draw,right=of A1] {A2};
% draw a rectangular node
\draw let \p1 = (A1.west), \p2 = (A2.east) in
node[draw,right,below=of A1,text width={\x2-\x1-0.6666em}]{test};
\end{tikzpicture}
Second step: fix the alignment. The right
option doesn't do anything, so we can simply delete it. By default, nodes are anchored at their center. Actually, for below=of ..
, they are anchored at the north (center). So we have to set anchor=north west
to have the node to the right. But then it is to the right of A1.center (concretely, node distance
below A1.south). So we need to specify below=of A1.south west
. Unfortunately, that doesn't quite work as A1 is bounded by a circle (so south west
is on the circle and not as far west and south as we would like). A1.west is a first approximation:
\begin{tikzpicture}[font=\tt]
\node (A1) [shape=circle,draw] {A1};
\node (A2) [shape=circle,draw,right=of A1] {A2};
% draw a rectangular node
\draw let \p1 = (A1.west), \p2 = (A2.east) in
node[draw,below={of A1.west},anchor=north west,text width={\x2-\x1-0.6666em}]{test};
\end{tikzpicture}
This isn’t quite perfect, since the third node is a bit too high now. The circle
shape doesn't provide the correct anchor, so we have to calculate its position (it’s easy: A1.west gives the correct x-coordinate and A1.south the correct y-coordinate). Also, let’s add align=center
to center the text in the node:
\begin{tikzpicture}[font=\tt]
\node (A1) [shape=circle,draw] {A1};
\node (A2) [shape=circle,draw,right=of A1] {A2};
% draw a rectangular node
\draw let
\p1 = (A1.west),
\p2 = (A2.east),
\p3 = (A1.south)
in node [
draw,
below={of (\x1,\y3)},
anchor=north west,
text width={\x2-\x1-0.6666em},
align=center
] {test};
\end{tikzpicture}
To get your second example to compile, you need to add \makeatletter
and \makeatother
in the appropriate places. By default, @ is in class “other” and cannot be used in command names. However, it is typically used in internal commands that the user should not access. \makeatletter
makes @ a ”letter”, so that it can be used in command names. See also Why do LaTeX internal commands have an @ in them?. However the code seems to have other problems too and adding \makeatletter
merely changes the error. I'm not yet sufficiently familiar with the ways TeX and LaTeX handle dimensions and lengths to give you advice how that code should be corrected.
Best Answer
The
right of
key isn't described in the manual at all (at least I couldn't find it). In fact, those keys are deprecated. The filepgf/frontendlayer/tikz/tikz.code.tex
contains the following code:That is, the center of the new node is placed
node distance
away from the center anchor of the old node (where only the first number innode distance
is used). You can see why this option is deprecated if you try a wide node:On the other hand
right=of
would measure thenode distance
(defaulting to 1cm) from the east anchor of node a to the west anchor of node b:Note that in order to use the
right=of ⟨node⟩
syntax, you need to include the TikZ librarypositioning
via\usetikzlibrary{positioning}
.