15

As I haven't got answers to my questions here:

How to draw vertical lines using pgfgantt package, I decided to implement my own command that I added to the pgfgantt.sty file (I have made a copy). I looked at pgfgantt.sty and I came up with this code that works with only one problem:

\newcommand\drawverticalline[1]{%
\begingroup%
\begin{pgfinterruptboundingbox}%
\begin{scope}
 \newif\ifgtt@includetitle
   \ganttset{%
      include title in canvas/.is if=gtt@includetitle,%
      include title in canvas
      }
   \gtt@tsstojulian{#1}{\gtt@today@slot}
   \gtt@juliantotimeslot{\gtt@today@slot}{\gtt@today@slot}%
   \ifgtt@includetitle%
    \def\y@upper{0}%
   \else%
     \pgfmathsetmacro\y@upper{%
      \gtt@lasttitleline * \ganttvalueof{y unit title}%
     }%
   \fi%
  \pgfmathsetmacro\y@lower{%
  \gtt@lasttitleline * \ganttvalueof{y unit title}%
  + (\gtt@currentline - \gtt@lasttitleline - 1)%
  * \ganttvalueof{y unit chart}%
  }%
  \pgfmathsetmacro\x@mid{%
     (\gtt@today@slot - 1 + \ganttvalueof{today offset})%
                    * \ganttvalueof{x unit}%
   }%
  \draw [/pgfgantt/today rule]
                (\x@mid pt, \y@upper pt) -- (\x@mid pt, \y@lower pt)
                node [/pgfgantt/today label node] {\ganttvalueof{today   label}};%
 \end{scope}
 \end{pgfinterruptboundingbox}%
  \endgroup%
}

This is just an example to show that it works. Here's what I get with this code :

\documentclass{article}
\usepackage[frenchb]{babel}  
\usepackage{pgfgantt}
\usetikzlibrary{shadows}

\begin{document}
\begin{tikzpicture} % optional
   \begin{ganttchart}[x unit=1.8mm, 
                  y unit chart=0.87cm, 
                  time slot format=isodate, 
                  vgrid=*{5}{dotted},
                 ]
                  {2014-04-14}{2014-07-11}
       \gantttitlecalendar{month=name} \\ 

       \ganttbar[progress=100]{title1}{2014-04-14}{2014-04-15} \\

       \ganttbar[progress=100]{title2}{2014-04-15}{2014-04-17} \\

       \drawverticalline{2014-05-07}
   \end{ganttchart}
\end{tikzpicture}
\end{document}

enter image description here

Normally the line should be draw below the title bar. It's this code that define where we start drawing :

\ifgtt@includetitle%
  \def\y@upper{0}%
\else%
  \pgfmathsetmacro\y@upper{%
    \gtt@lasttitleline * \ganttvalueof{y unit title}%
  }%
\fi%

How \ifgtt@includetitle works? It's defined like this :

\newif\ifgtt@includetitle
\ganttset{%
    include title in canvas/.is if=gtt@includetitle,%
    include title in canvas
    }
7
  • 1
    Usually define the \newif\ifgtt@includetitle outside your command definition of \drawverticalline. Then also, where do you set this conditional (true would be \gtt@includetitletrue and false would be \gtt@includetitlefalse)? It's default is false.
    – Werner
    May 7, 2014 at 20:46
  • 1
    \gantset{% ...} is not part of the \newif declaration: \newif\ifgtt@includetitle creates the conditional, then, as in your earlier snippet, you have \ifgtt@include ...<true> ... \else ...<false> ... \fi. You then can pick 'true' or 'false' with \gtt@includetitletrue or \gtt@includetitlefalse. Basically, it means: if \gtt@include = true, do <true>; otherwise do <false>. Note that the default is false.
    – jon
    May 7, 2014 at 20:47
  • 1
    why have you put the command into a file called pgfgantt.sty so making your document incompatible with every other latex installation, rather than put it in the document or a package of a different name? No one can run your MWE (unless they want to break their own installation) May 7, 2014 at 20:58
  • You can copy the file into the folder conatining your tex file. rename the package to mypgfgantt.sty and use usepackage{mypgfgantt}. This will not break your installation. And I just added a command I haven't modified any code of the original
    – Hunsu
    May 7, 2014 at 21:02
  • @user230137 yes well I could but it's wasteful to copy an entire package and a pain to maintain and update it when the original package updates and so you could have made it easier for anyone running the example, and for you, to have put the definition in the document, or in a package with just that definition and \RequirePackage{pgfgantt} May 7, 2014 at 21:06

1 Answer 1

30

\newif (in LaTeX) is defined by the following. (The original in plain has a slightly different definition).

\def\newif#1{%
  \count@\escapechar \escapechar\m@ne
    \let#1\iffalse
    \@if#1\iftrue
    \@if#1\iffalse
  \escapechar\count@}
\def\@if#1#2{%
  \expandafter\def\csname\expandafter\@gobbletwo\string#1%
                    \expandafter\@gobbletwo\string#2\endcsname
                       {\let#1#2}}

So \newif takes a command name (which by convention always starts with if) and defines three commands

\newif\iffoo defines

\iffoo to be \iffalse and defines

\footrue to be a command that defines \iffoo to be \iftrue and defines

\foofalse to be a command that defines \iffoo to be \iffalse.

\iftrue and \iffalse are primitives that act as true and false respectively.

So if you have

\iffoo

  some code here

\fi

the code will be executed or not depending whether earlier you have executed \footrue to change the meaning of \iffoo to \iftrue.

8
  • Thanks for that. In my case its value is contained in the include title in canvas parameter that we pass to the environment like this include title in canvas=true. How to execute the right command depending of the value of include title in canvas?
    – Hunsu
    May 7, 2014 at 20:59
  • @user230137 sorry I don't understand the comment, but it appears to be a question about pgf key setting (about which I know little) rather than about \newif May 7, 2014 at 21:03
  • Ok thanks. With your answer I could perhaps find the solution. If I can't I will just set it to true and do my thing.
    – Hunsu
    May 7, 2014 at 21:06
  • What does the header here, \count@\escapechar \escapechar\m@ne mean? By looking up the definitions I only find \count255\escapechar\escapechar\count22, which doesn't help me understand at all. May 1, 2018 at 9:49
  • 1
    @Atcold as I commented in the commen above, you should ask new questions, as new qustion posts not as comments on old answers. how can you say if it is tex or latex? as I comment in the answer that definition is the one in latex but plain tex has a simliar \newif defintion. the commands used in the defintion, \iftrue, \let, \iffalse are tex primitives. Mar 14 at 23:19

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.