TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to draw several boxes with vertical line split but so far have not been very successful.

Here's the code I attempted so far


\tikzstyle{block} = [draw, rectangle,color=gray, fill=gray!50, minimum height=4mm]
\tikzstyle{block1} = [draw, rectangle,minimum height=4mm, minimum width=40mm]
\tikzstyle{block2} = [draw, rectangle,minimum height=4mm, minimum width=45mm]
\node [block, minimum width=5mm] (11) {};
\node [block2, minimum width=45mm, right of =11,xshift=10mm] (12) {};

\node [block1, minimum width=5mm, below of =11] (21) {};
\node [block, minimum width=5mm, right of =21,xshift=-5mm] (22) {};
\node [block1, minimum width=40mm, right of =21,xshift=17.5mm] (20) {};

\node [block1, minimum width=10mm, below of =21] (31) {};
\node [block, minimum width=5mm, right of =31,xshift=-5mm] (32) {};
\node [block1, minimum width=35mm, right of =31, xshift=15mm] (30) {};

\node [block1, minimum width=15mm, below of =31] (41) {};
\node [block, minimum width=5mm, right of =41,xshift=-5mm] (42) {};
\node [block1, minimum width=30mm, right of =41, xshift=12.5mm] (40) {};

\node [block1, minimum width=20mm, below of =41] (51) {};
\node [block, minimum width=5mm, right of =51,xshift=2mm] (52) {};
\node [block1, minimum width=25mm, right of =51, xshift=17mm] (50) {};


The attached figure is what I hope to achieve as the result !

enter image description here

Is there anyone who can help me with this? Or is there a better way to doing it? Many thanks in advance.

[Edited] I have updated the image to clarify some details. Perhaps figure itself is not clearly shown that all the boxes should be of the same length with same alignment to each other. The shaded small portion in each of the bar (box) should be position in such a way that it seems to be sliding from one slot to another without space in between or overlapping. I would like to show that the shaded portion is continuously sliding across them in the following bars with the same small steps. Thanks!

share|improve this question
up vote 3 down vote accepted

Some of the other solutions seem rather complicated. All you need is a loop. Use \Slider{<number>} to draw <number>+1 bars with the moving slider; the width and height of the bar can be changed using \BarWd and \BarHt (resp.); the width of the slider is given by \SliderWd and the vertical separation between consecutive bars is given by \BarSep.



  \foreach \i in {0,1,...,#1}
    \draw[fill=gray] (\i*\SliderWd,-\i*\BarHt-\i*\BarSep) rectangle +(\SliderWd-\pgflinewidth,\BarHt);
    \draw (0,-\i*\BarHt-\i*\BarSep) rectangle +(\BarWd-\pgflinewidth,\BarHt);






enter image description here

share|improve this answer
thanks for your help! This is exactly what I intended to get. – user46182 Feb 15 '14 at 1:10

Another try, with MetaPost code included in a LuaLaTeX file, making use of the most recent luamplib package available on CTAN.

Like Gonzalo Medina, I'm using a simple loop and three parameters, namely the width and the height of the part, and the length of the shaded part of the bar. Moreover, I'm assuming that I must draw as many bars as the maximal number of shaded parts possible. For example, if the bar length is 7 and the slider length is 2, it will draw 3 = 7 div 2 bars.

        u := 1cm; % Scale
        % Macro creating the bars
        def bars(expr width, height, shaded_width) =
            path bar, shaded_part;
            numeric n; n := width div shaded_width;
            for i=1 upto n:
                shaded_part := unitsquare xyscaled ((shaded_width, height)*u) 
                    shifted ((shaded_width, -1.5height)*(i-1)*u);
                fill shaded_part  withcolor 0.8white; 
                bar := unitsquare xyscaled ((width, height)*u) 
                    shifted (0, -1.5height*(i-1)*u);
                draw bar;
                % for not drawing the same lines twice
                if point 0 of bar <> point 0 of shaded_part:
                    draw point 0 of shaded_part -- point 3 of shaded_part;
                if point 1 of bar <> point 1 of shaded_part:
                    draw point 1 of shaded_part -- point 2 of shaded_part;

        bars(8, 0.75, 2);
         bars(5.5, 0.5, 1);

The bars

share|improve this answer
thanks for your suggestion too. it helps a lot! – user46182 Feb 15 '14 at 1:11

Taking this timeline maker (Timeline in Beamer presentation) out of the box, without any changes, nor tikz:

\yrsfboxrule .4\fboxrule

enter image description here

share|improve this answer

Your Answer


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.