
Поскольку у меня нет ответов на мои вопросы здесь:
Как рисовать вертикальные линии с помощью пакета pgfgantt, я решил реализовать свою собственную команду, которую я добавил в pgfgantt.sty
файл (я сделал копию). Я посмотрел pgfgantt.sty
и придумал этот код, который работает, но с одной проблемой:
\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%
}
Это просто пример, чтобы показать, что это работает. Вот что я получаю с этим кодом:
\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}
Обычно линия должна быть нарисована под заголовком. Именно этот код определяет, где мы начинаем рисовать:
\ifgtt@includetitle%
\def\y@upper{0}%
\else%
\pgfmathsetmacro\y@upper{%
\gtt@lasttitleline * \ganttvalueof{y unit title}%
}%
\fi%
Как \ifgtt@includetitle
работает? Это определяется так:
\newif\ifgtt@includetitle
\ganttset{%
include title in canvas/.is if=gtt@includetitle,%
include title in canvas
}
решение1
\newif
(в LaTeX) определяется следующим образом. (Оригинал в простом виде имеет немного другое определение).
\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}}
Итак, \newif
берем имя команды (которое по соглашению всегда начинается с if
) и определяем три команды
\newif\iffoo
определяет
\iffoo
быть \iffalse
и определяет
\footrue
быть команда, которая определяет \iffoo
быть \iftrue
и определяет
\foofalse
быть — команда, определяющая \iffoo
быть \iffalse
.
\iftrue
и \iffalse
являются примитивами, которые действуют как истина и ложь соответственно.
Так что если у вас есть
\iffoo
some code here
\fi
код будет выполнен или нет в зависимости от того, выполнили ли вы ранее команду , \footrue
чтобы изменить значение \iffoo
на \iftrue
.