What would be the best way to draw something like this?

Gantt Chart for CPU Scheduling

I'm not sure if I should use pdfgantt package, or if I should do this like a single row table. Please advise.


For a simple diagram like this, you can just code it up easily in TikZ. Note that if you want to make more complicated diagrams, I would look into automating some of these aspects, but here's a start nonetheless.

\documentclass[tikz, border=10pt]{standalone}

  gray box/.style={
    minimum width={2*#1ex},
    minimum height={2em},
\begin{tikzpicture}[node distance=-0.5pt]
  \node [gray box=24] (p1) {\(P_{1}\)};
  \node [gray box=3, right=of p1] (p2) {\(P_{2}\)};
  \node [gray box=3, right=of p2] (p3) {\(P_{3}\)};

  \node [annotation] at (p1.south west) {0};
  \node [annotation] at (p1.south east) {24};
  \node [annotation] at (p2.south east) {27};
  \node [annotation] at (p3.south east) {30};


  • I'm surprised I didn't think of that. In this case TikZ is a really nice and easy solution. Thanks! – nland Feb 29 '16 at 2:35
\documentclass [tikz,border=2pt] {standalone}
\begin{tikzpicture}[line width=.7pt]
  \draw[fill=gray!20] (0,0)node[below]{0} rectangle(5,1);
  \draw[fill=gray!20] (5,0)node[below]{24}rectangle(6,1);
  \draw[fill=gray!20] (6,0)node[below]{27}rectangle (7,1)node[below,yshift=-1cm]{30};
  \path (2.5,.5)node{$P_1$} (5.5,.5)node{$P_2$} (6.5,.5)node{$P_3$};

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.