Graphics, Figures & TablesTrying to replicate this Gantt chart

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
ncant
Posts: 2
Joined: Mon Jun 03, 2024 9:58 pm

Trying to replicate this Gantt chart

Post by ncant »

Hello everyone,
I want to replicate some Gantt charts shown in the book “Operating System Concepts” to demonstrate how CPU scheduling algorithms work, like this one:

Image

I tried to replicate it using the pgfgantt package and this is what I got:

Code: Select all

\documentclass{article}
\usepackage{pgfgantt}

\begin{document}

\begin{figure}
\centering
\begin{ganttchart}[%
inline, 
bar inline label anchor=west,
bar inline label node/.append style={anchor=west, text=black},
bar/.append style={fill=white!!black,}, 
bar height=.8,]{0}{30}
\ganttbar{$P_1$}{0}{24}
\ganttbar{$P_2$}{24}{27}
\ganttbar{$P_3$}{27}{30}
\end{ganttchart}
\end{figure}

\end{document}

which results in the following figure:

Image

What I want to do (but am unable to despite reading the package documentation) is the following:
  • - remove the top white bar
    - center the text of the respective blocks
    - make sure that the content of the figure does not exceed the allowed area on the page, at the same time keeping the numeric indices I used to define the “length” of each segment
    - have numerical indices, just like in the original figure.
Can someone help me (or in case propose an alternative method) please?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10320
Joined: Mon Mar 10, 2008 9:44 pm

Trying to replicate this Gantt chart

Post by Stefan Kottwitz »

Hi ncant,

welcome to the forum!

How about making it a simple TikZ picture? Just three rectangular nodes and four labels.

Stefan
LaTeX.org admin
Post Reply