1

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tasks}
\usepackage{vmargin}
\usepackage{enumitem}
\usepackage{hhline}
\usepackage{pdflscape}

\usepackage{pgfgantt}

\begin{document}

\begin{ganttchart}[
        bar/.append style={fill=red},  % <-- HERE MAKE SOMETHING WITH THE COLOR
        hgrid=true,
        vgrid={*1{dotted}}
    ]{1}{8}
    \ganttbar{B}{6}{8} \\
    \ganttbar{A}{1}{5} \\
    \gantttitlelist{1,...,8}{1}
\end{ganttchart}

\end{document}

The output is

Original Gantt

I want something like:

Modified Gantt

In the manual I did not find anything that I specified about diagonal lines in the bars and to reduce the space between different objects, in the diagram. Also I would like to insert text besides the two axis.

Is it possible to achieve it in an easy way?

Thanks!

manooooh
  • 3,203
  • 2
  • 21
  • 46

1 Answers1

5

Just to learn something from the package, I found some useful modifiers in the example section 2.10 Style Examples of the manual; then there is the option of name for \garnttbar, which gives the bar a name, which allows working with the coordinates defined for the shape, such as A.center, A.north, etc. then I defined the styles for the bars through the tikz library patterns, which in my case the default definition, generates errors in some readers like firefox, so I included a code to define a new style of pattern.

RESULT: From MWE. enter image description here

RESULT: title height=1,bar height=1,bar top shift=.0, enter image description here

MWE:

\documentclass[border=20pt]{standalone}
\usepackage{pgfgantt}
\usetikzlibrary{patterns}
%Create a new patern for firefox and adobe reader from https://tex.stackexchange.com/a/219808/154390
\pgfdeclarepatternformonly{north east lines b}{\pgfqpoint{0pt}{0pt}}{\pgfqpoint{3.4pt}{3.4pt}}{\pgfqpoint{3.4pt}{3.4pt}}%
{
  \pgfsetlinewidth{1pt}
  %Principal line
  \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
  \pgfpathlineto{\pgfqpoint{3.4pt}{3.4pt}}
  %Complement line north east
  \pgfpathmoveto{\pgfqpoint{-1pt}{2.4pt}}
  \pgfpathlineto{\pgfqpoint{1pt}{4.4pt}}
  %Complement line south west
  \pgfpathmoveto{\pgfqpoint{2.4pt}{-1pt}}
  \pgfpathlineto{\pgfqpoint{4.4pt}{1pt}}
  \pgfusepath{stroke}
}
\begin{document}
\tikzstyle{TextNod}=[
    yshift=0pt,
    fill=white,
    inner sep=0.5pt,
    fill opacity=0.7,
    text opacity=1
]
\begin{ganttchart}[
        bar/.append style={
            pattern=north east lines b,
            pattern color=red,
        },
        bar incomplete/.append style={
            pattern=north east lines b,
            pattern color=blue,
        },
        y unit title=0.5cm,
        y unit chart=0.5cm,
        title height=1,
        bar height=.5,
        bar top shift=.275,
        hgrid=true,
        vgrid={*1{dotted}}
    ]{1}{8}
    \ganttbar[name=B,progress=50]{B}{6}{8} \\
    \ganttbar[name=A]{A}{1}{5} \\
    \gantttitlelist{1,...,8}{1}
    \node[TextNod] at (A.center){\tiny some text};
    \node[TextNod] at (B.center){\tiny some text};

\end{ganttchart}

\end{document}
J Leon V.
  • 11,533
  • 16
  • 47
  • I gave you a positive vote because I appreciate your time spent in answer my question, but this is not I want at all. The diagonal lines are amazing! But I want to reduce space because I have more tasks and the diagram becomes a large table. And then I don't see the axis labels. Could you explain me where is this info please? – manooooh Jul 12 '18 at 04:02
  • I am not clear about the axes, it would be good to include them in the image of the example with the result you want, however you can draw anything between the bars once you have the names of the shapes; On the other hand I changed the environment of the document to standalone, because the original drawing is really small, the scale you see is 340%, it is not pixelized because tikz exports vector graphics. – J Leon V. Jul 12 '18 at 04:19
  • I work in the standalone class because I can draw without care of the size because this environment resize the canvas acording to the drawing, that allows to import them to the main document using the graphics package within figure environment like is explained in the last part of this answer in Overlapping nodes in TikZ - Not enough space on paper – J Leon V. Jul 12 '18 at 04:25
  • 1
    @manooooh I don't follow, J Leon has reduced the space. With title height=1,bar height=1,bar top shift=.0, the bars and title fill the entire row height, and with y unit title=0.5cm,y unit chart=0.5cm the row heights are reduced to half. You could make y unit chart even smaller, to fit more rows in the same space. – Torbjørn T. Jul 12 '18 at 06:33
  • Yes @TorbjørnT. you are right. I didn't tested... thank you all! – manooooh Jul 14 '18 at 00:08