10

I'm trying to compose a TikZ calendar, but only want workdays printed. From the manual (I'm using v2.1):

57.1.2 Checking Dates

...

  • workday Passed by Mondays, Tuesdays, Wednesdays, Thursdays, and Fridays.
  • weekend Passed Saturdays and Sundays.

I know I can pass formatting options or node shapes on top of dates based on these checks... but how can I completely omit them from being printed?

Or is a date check not the way to go about this?

I'm using week list since it's so convenient for a calendar format layout by just using \calendar[dates=2012-01-01 to 2012-01-last] vs. what I think I might have to do to get what I want, which is pass each weekly range for every month. This quadruples my lines of code and really reduces the re-usability of my document.

Is there a better way? I didn't see any examples of this in the manual.


If reproducible code is required, I'm looking for this but with no weekends printed:

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calendar,shapes.geometric}

\begin{document}

\begin{tikzpicture}
   [every calendar/.style={
       month label above left,
       month text={\textit{\%mt}},
       week list}]

   \calendar[dates=2012-01-01 to 2012-01-last] ;

\end{tikzpicture}

\end{document}
0

1 Answer 1

9

You can use the if(weekend) [<do something with this weekend>] syntax. For example, you could set the weekend's color to red:

\calendar[dates=2012-01-01 to 2012-01-last] if(weekend) [red];

or, if you want it to disappear, to white. But this still prints out the actual node text. Or, even worse, you have white text on a colored background.

With the argument coordinate (short for shape=coordinate) you can transform the day node to a coordinate. A coordinate has no text.
Therefore there is not even a node text that is just hidden.

This will most likely be enough for most simple cases unless every node or every day (or another if later) will explicitly sets a shape. (If there's a label involved this will also still appear with a coordinate.)

The whole printing of the day node can be removed by setting day code to an empty value.

Of course, these can also be used via the if key which is appendable to an every calendar style.

Code

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calendar}
\tikzset{
  no day/.style={shape=coordinate},
  no day'/.style={day code=}}
\begin{document}
\tikz[
  every calendar/.style={
    month label above left,
    month text={\textit{\%mt}},
    week list}]
 \calendar[dates=2012-01-01 to 2012-01-last] if(weekend) [no day];

\tikz[
  every calendar/.style={
    month label above left,
    month text={\textit{\%mt}},
    week list}]
 \calendar[dates=2012-01-01 to 2012-01-last] if(weekend) [no day'];
\end{document}

Output

Note: The yellow boxes are a two-line selection that shows that there is no hidden text. Compare with the [white] version on the right.

Output produces by the posted codeenter image description here

4
  • 1
    That's a nice shortcut.
    – percusse
    Sep 11, 2012 at 0:15
  • Awesome! I had tried using if(weekend) and just passing no argument, hoping it would do nothing... but I think it defaults to doing "nothing" in the sense of "nothing other than what it was going to do anyway." I'll try this after lunch and accept if successful. Thanks a ton!
    – Hendy
    Sep 11, 2012 at 16:26
  • @Hendy I'm glad I could help. Yes, the [] argument just gets passed to the internally \node … {…} command as \node[] … {…}. It would just have no effect. Sep 11, 2012 at 16:39
  • Just tried this and worked wonderfully. I added it to every calendar/.style={..., if={(weekend) [shape=coordinate]}, ... } so that I didn't have to add it to every instance. Fantastic and clever solution!
    – Hendy
    Sep 12, 2012 at 17:28

You must log in to answer this question.

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