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 am trying to draw an automaton using TikZ and \foreach statement. Below is the sample of what I have. Now, two questions I have is,

  1. Is there any way to use curly braces {,} instead of (,) as I have now to label some states of the automaton? I would like to have A{A}, not A(A).
  2. \foreach statement does not let me draw arrows in some situations. I want to draw arrows from A to A(A) (ideally, A{A} after the fix) and from A to A'(A) as well, but for some reason, it does not like how I name those states with parentheses.

Is there anybody who can help me with this? I greatly appreciate it.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\[\begin{tikzpicture}[shorten >=1pt,->]
\tikzstyle{vertex}=[circle,fill=black!25,minimum size=17pt,inner sep=0pt]
\foreach \name/\a in {A/90, A''/180, A(A)/270, A'(A)/0}
\node[vertex] (\name) at (\a:3cm) {$\name$};
\foreach \from/\to in {A/A'', A/A(A), A/A'(A)}
\draw (\from) -- (\to);
\end{tikzpicture}\]
\end{document}

enter image description here

share|improve this question
    
Welcome to TeX.SX! –  Adam Liter Apr 9 at 22:14

1 Answer 1

up vote 7 down vote accepted

I assume you want the curly braces printed in the nodes. To print backslashes you have to use \{ and \}, but these cannot be used in node names. That is, you can't do something like \node (\{A\}) at (0,0) {A};. As a workaround you can use a different string for the node name and node content, something like

\foreach \name/\word/\a in {A/A/90, A''/A''/180, A[A]/A\{A\}/270, A'[A]/A'\{A\}/0}
  \node[vertex] (\name) at (\a:3cm) {$\word$};

With regard to your second question, I think this is because the parenthesis confuses the parsing of the node name. For example, with A(A) as the name, you get \node (A(A)) .... I guess the first closing paren is taken as the end of the name, giving the error No shape named A(A is known.

Two working versions of your code, one with brackets, one with braces, and the above mentioned workaround.

\documentclass[tikz,border=5mm]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[shorten >=1pt,->]
\tikzset{vertex/.style={circle,fill=black!25,minimum size=25pt,inner sep=0pt}}
\foreach \name/\a in {A/90, A''/180, A[A]/270, A'[A]/0}
\node[vertex] (\name) at (\a:3cm) {$\name$};
\foreach \from/\to in {A/A'', A/A[A], A/A'[A]}
\draw (\from) -- (\to);
\end{tikzpicture}

\begin{tikzpicture}[shorten >=1pt,->]
\tikzset{vertex/.style={circle,fill=black!25,minimum size=30pt,inner sep=0pt}}
\foreach \name/\word/\a in {A/A/90, A''/A''/180, A[A]/A\{A\}/270, A'[A]/A'\{A\}/0}
\node[vertex] (\name) at (\a:3cm) {$\word$};
\foreach \from/\to in {A/A'', A/A[A], A/A'[A]}
\draw (\from) -- (\to);
\end{tikzpicture}
\end{document}

enter image description hereenter image description here

share|improve this answer
    
That is beautiful! Thank you very much for your quick response. –  BzTAK178 Apr 9 at 22:24

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.