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 using a following code to produce an image as shown below. enter image description here

Now I set the node distance to 0 and draw=none in nodes to remove the border. comeback, comein nodes have size of 2.5cm, while handle has 1.75cm and none has size of 0.75cm.

Now, I expected the last none block and comeback block to be aligned vertically, because of the sizes of the block. However it does not. I see that there is a small gap between the placement of nodes, even if node distance=0cm.

How to remove this gap?

Thanks !

\documentclass{article}
\usepackage{tikz}
 \usetikzlibrary{positioning}
   \begin{tikzpicture}[node distance=0cm]
\definecolor{color1}{RGB}{51, 122, 153}
\definecolor{color2}{RGB}{102, 153, 102}
\definecolor{color3}{RGB}{150, 150, 150}
\definecolor{color4}{RGB}{204, 152, 0}

\tikzstyle{comein}=[minimum height=1cm,minimum width=2.5cm,draw=none,text centered,fill=color1,anchor=west]
\tikzstyle{handle}=[minimum height=1cm,minimum width=1.75cm,draw=none,text centered,fill=color2,anchor=west]
\tikzstyle{comeback}=[minimum height=1cm,minimum width=2.5cm,draw=none,text centered,fill=color4,anchor=west]
\tikzstyle{noneStyle}=[minimum height=1cm,minimum width=0.75cm,draw=none,text centered,fill=color3,anchor=west]

\node at (17.5,3.1) {\large s=1};
\draw[dashed] (18.75,-1.15) -- (18.75,3.25);
\draw[dashed] (16.25,-1.15) -- (16.25,3.25);

\node at (11,-1.5) {\LARGE Time};
\draw[->] (-1,-1) -- (22,-1);
\draw (-0.75,-1.25) -- (-0.75,3.5);

\node at (-2,2.25) {Input};
\node at (-2,1) {HANDLE};
\node at (-2,-0.15) {Output};

\begin{scope}[yshift=-0.15cm]
\node[comein]  (P0) at (-0.5,0) {$comein_0$};
\node[comein]  (P1) at (P0.east) {$comein_1$};
\node[comein]  (P2) at (P1.east) {$comein_2$};
\node[comein]  (P3) at (P2.east) {$comein_3$};
\node[comein]  (P4) at (P3.east) {$comein_4$};
\node[comein]  (P5) at (P4.east) {$comein_5$};
\end{scope}

\begin{scope}
\node[noneStyle,minimum width=2.5cm]  (I0) at (-0.5,1) {$none$};
\node[handle]  (C0) at (I0.east) {$handle_0$};
\node[noneStyle]  (I1) at (C0.east) {};
\node[handle]  (C1) at (I1.east) {$handle_1$};
\node[noneStyle]  (I2) at (C1.east) {};
\node[handle]  (C2) at  (I2.east) {$handle_2$};
\node[noneStyle]  (I3) at (C2.east) {};
\node[handle]  (C3) at  (I3.east) {$handle_3$};
\node[noneStyle]  (I4) at (C3.east) {};
\node[handle]  (C4) at  (I4.east) {$handle_4$};
\node[noneStyle]  (I5) at (C4.east) {};
\node[handle]  (C5) at  (I5.east) {$handle_5$};
\node[noneStyle,minimum width=2.5cm]  (I1) at (C5.east) {$none$};
\end{scope}

\begin{scope}[yshift=0.15cm]
\node[comeback]  (W0) at (3.75,2) {$comeback_0$};
\node[comeback]  (W1) at (W0.east) {$comeback_1$};
\node[comeback]  (W2) at (W1.east) {$comeback_2$};
\node[comeback]  (W3) at (W2.east) {$comeback_3$};
\node[comeback]  (W4) at (W3.east) {$comeback_4$};
\node[comeback]  (W5) at (W4.east) {$comeback_5$};
\end{scope}

\coordinate (a) at (-0.5,1.75);
\coordinate (b) at (3.0,1.75);
\draw[<->, black!20!white, line width=2pt]   (-0.5,1.75) to node[black,above]{INIT} (2.0,1.75) ;
\draw[<->, black!20!white, line width=2pt]   (16.25,-0.5) to node[black,above]{FINAL} (18.75,-0.5) ;

\end{tikzpicture}
\end{document}

Thanks,

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You need to kill outer sep (setting it to 0pt):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\definecolor{color1}{RGB}{51, 122, 153}
\definecolor{color2}{RGB}{102, 153, 102}
\definecolor{color3}{RGB}{150, 150, 150}
\definecolor{color4}{RGB}{204, 152, 0}

\begin{document}

\begin{tikzpicture}[
node distance=0cm,
comein/.style={
  minimum height=1cm,
  minimum width=2.5cm,
  draw=none,
  text centered,
  fill=color1,
  anchor=west,
  outer sep=0pt
  },
handle/.style={
  minimum height=1cm,
  minimum width=1.75cm,
  draw=none,
  text centered,
  fill=color2,
  anchor=west,
  outer sep=0pt
  },
comeback/.style={
  minimum height=1cm,
  minimum width=2.5cm,
  draw=none,
  text centered,
  fill=color4,
  anchor=west,
  outer sep=0pt
  },
noneStyle/.style={
  minimum height=1cm,
  minimum width=0.75cm,
  draw=none,
  text centered,
  fill=color3,
  anchor=west,
  outer sep=0pt
  }
]
\node at (17.5,3.1) {\large s=1};
\draw[dashed] (18.75,-1.15) -- (18.75,3.25);
\draw[dashed] (16.25,-1.15) -- (16.25,3.25);

\node at (11,-1.5) {\LARGE Time};
\draw[->] (-1,-1) -- (22,-1);
\draw (-0.75,-1.25) -- (-0.75,3.5);

\node at (-2,2.25) {Input};
\node at (-2,1) {HANDLE};
\node at (-2,-0.15) {Output};

\begin{scope}[yshift=-0.15cm]
\node[comein]  (P0) at (-0.5,0) {$comein_0$};
\node[comein]  (P1) at (P0.east) {$comein_1$};
\node[comein]  (P2) at (P1.east) {$comein_2$};
\node[comein]  (P3) at (P2.east) {$comein_3$};
\node[comein]  (P4) at (P3.east) {$comein_4$};
\node[comein]  (P5) at (P4.east) {$comein_5$};
\end{scope}

\begin{scope}
\node[noneStyle,minimum width=2.5cm]  (I0) at (-0.5,1) {$none$};
\node[handle]  (C0) at (I0.east) {$handle_0$};
\node[noneStyle]  (I1) at (C0.east) {};
\node[handle]  (C1) at (I1.east) {$handle_1$};
\node[noneStyle]  (I2) at (C1.east) {};
\node[handle]  (C2) at  (I2.east) {$handle_2$};
\node[noneStyle]  (I3) at (C2.east) {};
\node[handle]  (C3) at  (I3.east) {$handle_3$};
\node[noneStyle]  (I4) at (C3.east) {};
\node[handle]  (C4) at  (I4.east) {$handle_4$};
\node[noneStyle]  (I5) at (C4.east) {};
\node[handle]  (C5) at  (I5.east) {$handle_5$};
\node[noneStyle,minimum width=2.5cm]  (I1) at (C5.east) {$none$};
\end{scope}

\begin{scope}[yshift=0.15cm]
\node[comeback]  (W0) at (3.75,2) {$comeback_0$};
\node[comeback]  (W1) at (W0.east) {$comeback_1$};
\node[comeback]  (W2) at (W1.east) {$comeback_2$};
\node[comeback]  (W3) at (W2.east) {$comeback_3$};
\node[comeback]  (W4) at (W3.east) {$comeback_4$};
\node[comeback]  (W5) at (W4.east) {$comeback_5$};
\end{scope}

\coordinate (a) at (-0.5,1.75);
\coordinate (b) at (3.0,1.75);
\draw[<->, black!20!white, line width=2pt]   (-0.5,1.75) to node[black,above]{INIT} (2.0,1.75) ;
\draw[<->, black!20!white, line width=2pt]   (16.25,-0.5) to node[black,above]{FINAL} (18.75,-0.5) ;

\end{tikzpicture}
\end{document}

enter image description here

By the way, perhaps you could be interested in changing \tikzstyle to \tikzset (as I did in my answer) and perhaps using chains (with some loops) will simplify your code, as the following example illustrates:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,chains}

\definecolor{color1}{RGB}{51, 122, 153}
\definecolor{color2}{RGB}{102, 153, 102}
\definecolor{color3}{RGB}{150, 150, 150}
\definecolor{color4}{RGB}{204, 152, 0}

\begin{document}

\begin{tikzpicture}[
node distance=0cm,
comein/.style={
  minimum height=1cm,
  minimum width=2.5cm,
  draw=none,
  text centered,
  fill=color1,
  anchor=west,
  outer sep=0pt
  },
handle/.style={
  minimum height=1cm,
  minimum width=1.75cm,
  draw=none,
  text centered,
  fill=color2,
  anchor=west,
  outer sep=0pt
  },
comeback/.style={
  minimum height=1cm,
  minimum width=2.5cm,
  draw=none,
  text centered,
  fill=color4,
  anchor=west,
  outer sep=0pt
  },
noneStyle/.style={
  minimum height=1cm,
  minimum width=0.75cm,
  draw=none,
  text centered,
  fill=color3,
  anchor=west,
  outer sep=0pt
  }
]
\node at (17.5,3.1) {\large s=1};
\draw[dashed] (18.75,-1.15) -- (18.75,3.25);
\draw[dashed] (16.25,-1.15) -- (16.25,3.25);

\node at (11,-1.5) {\LARGE Time};
\draw[->] (-1,-1) -- (22,-1);
\draw (-0.75,-1.25) -- (-0.75,3.5);

\node at (-2,2.25) {Input};
\node at (-2,1) {HANDLE};
\node at (-2,-0.15) {Output};

\begin{scope}[yshift=-0.15cm,start chain,every node/.style={comein,on chain}]
\node  (P0) at (-0.5,0) {$comein_0$};
\foreach \Valor in {1,...,5} 
  \node  (P\Valor) {$comein_\Valor$};
\end{scope}

\begin{scope}[start chain,every node/.style={on chain}]
\node[noneStyle,minimum width=2.5cm]  (I0) at (-0.5,1) {$none$};
\node[handle]  (C0) at (I0.east) {$handle_0$};
\foreach \Valor in {1,...,5}
{
  \node[noneStyle]  (I\Valor) {};
  \node[handle]  (C\Valor) {$handle_\Valor$};
}
\node[noneStyle,minimum width=2.5cm]  (I1) at (C5.east) {$none$};
\end{scope}

\begin{scope}[yshift=0.15cm,start chain,every node/.style={comeback,on chain}]
\node  (W0) at (3.75,2) {$comeback_0$};
\foreach \Valor in {1,...,5}
  \node  (W\Valor) {$comeback_\Valor$};
\end{scope}

\coordinate (a) at (-0.5,1.75);
\coordinate (b) at (3.0,1.75);
\draw[<->, black!20!white, line width=2pt]   (-0.5,1.75) to node[black,above]{INIT} (2.0,1.75) ;
\draw[<->, black!20!white, line width=2pt]   (16.25,-0.5) to node[black,above]{FINAL} (18.75,-0.5) ;
\end{tikzpicture}

\end{document}
share|improve this answer
    
thanks! it works perfect. could you point me to some example of using chains? –  Raj May 2 at 13:03
    
@Raj You're welcome! Sure, I can give you an example with chains (but it will have to wait some hours, since I have to leave right now). –  Gonzalo Medina May 2 at 13:06
    
sure thanks a lot ! –  Raj May 2 at 13:07
    
One can use loop like: \foreach \j [count=\i from 0] in {1,...5}{\node[comeback] (W\j) at (Wi.east) {$comeback_\j$};}` to avoid repeats. –  Tarass May 2 at 17:16
1  
@Tarass one can specify the going option for a chain to change direction; for really complex progressions perhaps chains wouldn't be appropriate, but here they are a valid (even natural, I'd dare to say) option. –  Gonzalo Medina May 2 at 19:23

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.