4

I have modified code given by cfr in the answer to this question about current day nodes. I want different colored (green and red) lines at the bottom and left of each day. However, for the single digit dates, the bottom line does not completely fill the area I want underlined.

I think I should be able to use the = modifier on d to insert the missing space where the zero would go, but I can't make it work. Do I need to modify the definition of week list to accomplish this?

\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{calendar}
\begin{document}
\begin{tikzpicture}
  \calendar (cal)
  [%
    week list,
    dates=2016-08-01 to 2016-10-last,
    day xshift=1.5em,
    month xshift=1pt,
    month label above left,
  ]
  if (weekend) [text=black!25]
  [%
  execute at end day scope={%
      \draw[red] 
      (cal-\%y0-\%m0-\%d0.north east) -- 
      (cal-\%y0-\%m0-\%d0.south east);
  }][%
  execute at end day scope={%
      \draw[green] 
      (cal-\%y0-\%m0-\%d0.south east) -- 
      (cal-\%y0-\%m0-\%d0.south west);
  }];
\end{tikzpicture}
\end{document}

[Note: This is one of two questions about modifying the same code. The other is here.]

1 Answer 1

3

1. Approach

You can use an if statement to check if the day is less then 10 and then increase the length of the line.

Code-snippet (using tikzlibrary calc):

\ifnum \%d0<10
    \draw[yellow] 
    (cal-\%y0-\%m0-\%d0.south east) -- 
    ($(cal-\%y0-\%m0-\%d0.south west) + (-1.6mm,0)$);
\else
    \draw[green] 
    (cal-\%y0-\%m0-\%d0.south east) -- 
    (cal-\%y0-\%m0-\%d0.south west);
\fi

But in the result even the green original line is to long (look at 9):

enter image description here

2. Approach

So another approach would be to use a fix length for that line:

\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{calendar}

\begin{document}
\begin{tikzpicture}
    \calendar (cal)
    [%
        week list,
        dates=2016-08-01 to 2016-10-last,
        day xshift=1.5em,
        month xshift=1pt,
        month label above left,
    ]
    if (weekend) [text=black!25]
    [%
    execute at end day scope={%
        \draw[red] 
        (cal-\%y0-\%m0-\%d0.north east) -- 
        (cal-\%y0-\%m0-\%d0.south east);
    }][%
    execute at end day scope={%
        \draw[green] 
        (cal-\%y0-\%m0-\%d0.south east) --++ 
        (-5.2mm,0);
    }];
\end{tikzpicture}
\end{document}

Result:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .