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 produced the following output using the tikz code shown below. What I want is for the arrow on the right to have a fixed length relative to the rightmost symbol, not relative to the center of the node. How do I accomplish this? I'm new to tikz, and could not figure out how to do it using mechanisms like xshift or +(x,y) coordinates.

Basically I want to be able to specify the position of the right-hand node (tip of the arrow) as something like

n0.east+(1em,0)

enter image description here

\documentclass{article}
\RequirePackage{tikz}
\begin{document}

\pgfdeclarelayer{nodelayer}
\pgfdeclarelayer{edgelayer}
\pgfsetlayers{edgelayer,nodelayer,main}
\tikzstyle{arrow}=[draw=black,arrows=-latex]

\newcommand{\foo}[1]{%
  \begin{tikzpicture}[baseline=(n1.base),thick]
    \begin{pgfonlayer}{nodelayer}
      \node (n0) at (0, 0) {$#1$};           
      \node (n1) at +(2em, 0) {};                  
    \end{pgfonlayer}
    \begin{pgfonlayer}{edgelayer}
      \draw [style=arrow] (n0) to (n1);
    \end{pgfonlayer}
  \end{tikzpicture}
}

\foo{x}

\foo{xy}

\end{document}
share|improve this question
1  
If you want to draw an horizontal arrow with length 1em starting at node.east, you can use \draw[->] n0.east--++(1em,0). If you want a node there, you can use \draw[->] n0.east--++(1em,0) coordinate (n1). I think you don't need calc library nor so many layers, but may be I don't understand your question. –  Ignasi Feb 12 '13 at 8:09
    
@Ignasi: This is very helpful. My example was more complicated than it needed to be. But I think you have an error in syntax; you need parens around the n0.east. –  Ben Crowell Feb 12 '13 at 23:03
add comment

1 Answer

up vote 2 down vote accepted

You can use tikz's calc library for coordinate calculations. So with usetikzlibrary{calc} desired coordinate calculation could be performed as:

($(n0.east)+(1em,0)$)

Alternatively you can apply a shift, which has the advantage that it does not require the calc library, as follows

([xshift=1em]n0.east)

Either of these two methods yields:

enter image description here

Code:

\documentclass{article}
\RequirePackage{tikz}

\begin{document}

\pgfdeclarelayer{nodelayer}
\pgfdeclarelayer{edgelayer}
\pgfsetlayers{edgelayer,nodelayer,main}
\tikzstyle{arrow}=[draw=black,arrows=-latex]

\newcommand{\foo}[1]{%
  \begin{tikzpicture}[baseline=(n1.base),thick]
    \begin{pgfonlayer}{nodelayer}
      \node (n0) at (0, 0) {$#1$};           
      \node (n1) at ([xshift=1em]n0.east) {};                  
    \end{pgfonlayer}
    \begin{pgfonlayer}{edgelayer}
      \draw [style=arrow] (n0) to (n1);
    \end{pgfonlayer}
  \end{tikzpicture}
}

\foo{x}

\foo{xy}

\end{document}
share|improve this answer
    
Perfect! That's exactly what I needed. –  Ben Crowell Feb 12 '13 at 1:47
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.