The Gantt chart latex features are really complicated. I just want a simple little thing like this, for visualizing scheduling algorithm
How should I do that?
ETA: I took the the code from here and added colors in.
\definecolor{p1}{HTML}{5780dc}
\definecolor{p2}{HTML}{dc0404}
\definecolor{p3}{HTML}{1ec81e}
\definecolor{p4}{HTML}{8424ac}
\definecolor{p5}{HTML}{e68142}
\begin{tikzpicture}[
node distance = 0pt,
G/.style = {draw, color=white, text width=2*#1mm, align=center,
inner xsep=0pt, outer sep=0pt,
anchor=south west},
tck/.style = {font=\scriptsize, below}
]
\newlength{\prev}
\foreach \n/\i [remember=\i as \j (initially 0),
evaluate=\i as \k using \i-\j] in {
1/2, 2/3, 3/11, 4/15, 5/20
}
{
\node[G=\k, fill=p\n] at (\j/5,0) {$P_\n$};
\node[tck] at (\i/5,0) {\i};
\ifnum\j=0
\node[tck] at (0,0) {\j};
\fi
}
\end{tikzpicture}
This is mostly good, but what about one that's only 1 wide? It's too narrow, and the text gets cut off.
How can I alter it to avoid that? I want to make the whole thing wider, rather than making the text smaller.
Also, is there any way to have a sum variable? Something the number could be added to each time, so that the variable is the sum of the previous numbers? Something so that the input could be:
{p2/2, p1/1, p4/4, p5/5, p3/8}
Best Answer
This is a suggestion for a quite customisable simple gantt chart (maybe a bit overkill though). You can define a set of colors to cycle through, customise the width and height and the position of the ticks, and you can set a threshold that decides whether the label should be placed inside the node or as a pin. One current shortcoming is that the definition of colors cannot be scoped.
Scoping the colors is much easier using something like
color cycle/.list={}
. However, for proper cycling through the colors, I need the length of this list, which I find difficult to store properly. Maybe, it would be easier to define the color lists prior to the rest using IDs and for eachpic
reference to one of these lists using an ID.Anyways, I found a way how to somehow scope the color lists, but I am quite sure that this is not the simplest and most straightforward way: