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.

Code:

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}

\def\names{{"1", "2"}}
\foreach \i in {0,1} {%
  \ifnum\i=0\relax
      \node (\i) [draw] {\pgfmathparse{\names[\i]}\pgfmathresult};
  \else
      \pgfmathparse{int(\i-1)}
      \node (\i) [draw,right= 1cm of \pgfmathresult]
            {\pgfmathparse{\names[\i]}\pgfmathresult};

      %this doesn't work:
      %\draw[dotted] ($\pgfmathresult.south east !.5! (\i.south east)$)
      %      -- ($\pgfmathresult.south east !.5! (\i.south east) + (0,1cm)$);
  \fi
}
\end{tikzpicture}
\end{document}

Creates this:

enter image description here

How can I create a dotted line between the blocks 1cm long? I tried to do it, using the commented code, but it doesn't work, gives an error:

Runaway argument?

\pgfmathresult .south east !.5! (\i .south east)$) -- ($\pgfmathresult \ETC.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Essentially your only error is not placing brackets () around your coordinate expression including \pgfmathresult.south east. However, your code for the dotted line can be simplified by only calculating the start point and specifiying the end via the relative coordinate expression -- +(0,1cm). Below I have made slightly different choice of the start position for the line to be halfway between the right edge of the previous node and the left edge of the current one; I am not sure what your actual application is.

Sample output

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\begin{document}

\begin{tikzpicture}
  \def\names{{"1", "2"}}
  \foreach \i in {0,1} {%
    \ifnum\i=0\relax
      \node (\i) [draw] {\pgfmathparse{\names[\i]}\pgfmathresult};
    \else
      \pgfmathparse{int(\i-1)}
      \node (\i) [draw,right= 1cm of \pgfmathresult]
            {\pgfmathparse{\names[\i]}\pgfmathresult};
      \draw[dotted] ($(\pgfmathresult.south east) !.5! (\i.south west)$)
            -- +(0,1cm);
  \fi
}
\end{tikzpicture}
\end{document}
share|improve this answer

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.