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 want to draw a simple diagram using tikz to show the structure of a compiler front end.

The compiler is being represented with a node using rectangle split shape containing three parts. The input and output are being represented by rectangles node and should connect to the left of the first and to the right of the last parts of the split shape, respectively.

I have written the document below, but it is not working.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.multipart,positioning}

\begin{document}

\begin{tikzpicture}[thick, data/.style={rectangle,fill=red!12}]
  \node[rectangle split,rectangle split parts=3,draw,anchor=center] (compiler) {
    lexical analysis\nodepart{two}
    syntatic analysis\nodepart{three}
    semantic analysis
  };

  \node[data] (src) [left=of compiler.text,align=center] {source code};
  \node[data] (obj) [right=of compiler.three,align=center] {intermediate code};

  \draw [->] (src.east) -- (compiler.text west);
  \draw [->] (compiler.three east) -- (obj.west);
\end{tikzpicture}

\end{document}

compiler front end

How should it be modified to work as expected?

share|improve this question
    
Does saying \node[data] (obj) [right=of compiler.three east,align=center] {intermediate code}; do what you want? –  Torbjørn T. Mar 4 '12 at 0:50
    
@TorbjørnT. Yes. And how to force the arrow from "source code" to be horizontal? –  Romildo Mar 4 '12 at 0:57
    
Use the -| syntax, such as \draw [->] (src.east) -- (src.east-|compiler.text west); –  Stefan Kottwitz Mar 4 '12 at 1:01
    
Same thing, see my answer. –  Torbjørn T. Mar 4 '12 at 1:02
add comment

1 Answer

up vote 4 down vote accepted

Simply changing from left=of compiler.text and right=of compiler.three to left=of compiler.text west and right=of compiler.three east for the src and obj nodes improves the output.

enter image description here

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.multipart,positioning}

\begin{document}

\begin{tikzpicture}[thick, data/.style={rectangle,fill=red!12}]
  \node[rectangle split,rectangle split parts=3,draw,anchor=center] (compiler) {
    lexical analysis\nodepart{two}
    syntatic analysis\nodepart{three}
    semantic analysis
  };

  \node[data] (src) [left=of compiler.text west,align=center] {source code};
  \node[data] (obj) [right=of compiler.three east,align=center] {intermediate code};

  \draw [->] (src.east) -- (compiler.text west);
  \draw [->] (compiler.three east) -- (obj.west);
\end{tikzpicture}

\end{document}
share|improve this answer
    
Is there any command like circle split and circle split parts=3? –  Harish Kumar Mar 4 '12 at 9:18
    
@HarishKumar There is a circle split shape, but it has as far as I can see only two parts, text and? lower. See the section Shapes with Multiple Text Parts in the Shape Library chapter of the PGF manual. (In my CVS version it is chapter 53.6 on page 497.) –  Torbjørn T. Mar 4 '12 at 9:25
    
Thank you. I will look into it. –  Harish Kumar Mar 4 '12 at 15:14
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.