4

I've got a simple Tikz calendar.

I'd just like to start the weeks on Sundays, which seems more natural to me -- that is, I'd like Sundays to be at the left.

Below a MWE:

\documentclass{article}
\usepackage[margin = 2.5cm, a4paper]{geometry}
\pagestyle{empty}
\usepackage[brazil]{babel}
\usepackage{fontspec}
\setmainfont{Alegreya Sans}
\usepackage{tikz}
\usetikzlibrary{calendar,positioning}



\def\pgfcalendarmonthname#1{ \translate{\ifcase#1\or Janeiro\or Fevereiro\or Março\or Abril\or Maio\or Junho\or Julho\or Agosto\or Setembro\or Outubro\or Novembro\or Dezembro\fi} }

    \def\pgfcalendarmonthshortname#1{ \translate{\ifcase#1\or Jan\or Fev\or Mar\or Abr\or Mai\or Jun\or Jul\or Ago\or Set\or Out\or Nov\or Dez\fi} }


\def\pgfcalendarweekdayshortname#1{ \translate{\ifcase#1\or Seg\or Ter\or Qua\or Qui\or Sex\or Sab\or Dom\fi} }

\def\pgfcalendarweekdayname#1{ \translate{\ifcase#1\or Segunda\or Terça\or Quarta\or Quinta\or Sexta\or Sábado\or Domingo\fi} }

\newcommand{\calyear}{2017}
\newcommand{\mon}[1]{\calendar[dates = \calyear-#1-01
    to \calyear-#1-last] if (Sunday) [red];}



\begin{document}
    \begin{tikzpicture}[every calendar/.style = {
        month label above centered,
        month text = {\Large\textsc{\%mt}},
        week list,
    }]
    \matrix (Calendar) [column sep = 4em, row sep = 3em] {
        \mon{01} & \mon{02} & \mon{03} \\
        \mon{04} & \mon{05} & \mon{06} \\
        \mon{07} & \mon{08} & \mon{09} \\
        \mon{10} & \mon{11} & \mon{12} \\ };
    \node [above = 1cm of Calendar, font = \Huge]
    {\calyear};
    \end{tikzpicture}
\end{document}
2

To integrate macmadness86's answer into the code in the question:

\documentclass{article}
\usepackage[margin = 2.5cm, a4paper]{geometry}
\pagestyle{empty}
\usepackage[brazil]{babel}
\usepackage{fontspec}
\setmainfont{Alegreya Sans}
\usepackage{tikz}
\usetikzlibrary{calendar,positioning}
\makeatletter
\tikzstyle{week list sunday}=[
% Note that we cannot extend from week list,
% the execute before day scope is cumulative
execute before day scope={%
  \ifdate{day of month=1}{\ifdate{equals=\pgfcalendarbeginiso}{}{
      % On first of month, except when first date in calendar.
      \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@month@yshift}%
      \pgftransformyshift{-\pgf@y}
    }}{}%
},
execute at begin day scope={%
  % Because for TikZ Monday is 0 and Sunday is 6,
  % we can't directly use \pgfcalendercurrentweekday,
  % but instead we define \c@pgf@counta (basically) as:
  % (\pgfcalendercurrentweekday + 1) % 7
  \pgfmathsetlength\pgf@x{\tikz@lib@cal@xshift}%
  \ifnum\pgfcalendarcurrentweekday=6
  \c@pgf@counta=0
  \else
  \c@pgf@counta=\pgfcalendarcurrentweekday
  \advance\c@pgf@counta by 1
  \fi
  \pgf@x=\c@pgf@counta\pgf@x
  % Shift to the right position for the day.
  \pgftransformxshift{\pgf@x}
},
execute after day scope={
  % Week is done, shift to the next line.
  \ifdate{Saturday}{
    \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}%
    \pgftransformyshift{-\pgf@y}
  }{}%
},
% This should be defined, glancing from the source code.
tikz@lib@cal@width=7
]
\makeatother

\def\pgfcalendarmonthname#1{ \translate{\ifcase#1\or Janeiro\or Fevereiro\or Março\or Abril\or Maio\or Junho\or Julho\or Agosto\or Setembro\or Outubro\or Novembro\or Dezembro\fi} }

\def\pgfcalendarmonthshortname#1{ \translate{\ifcase#1\or Jan\or Fev\or Mar\or Abr\or Mai\or Jun\or Jul\or Ago\or Set\or Out\or Nov\or Dez\fi} }

\def\pgfcalendarweekdayshortname#1{ \translate{\ifcase#1\or Seg\or Ter\or Qua\or Qui\or Sex\or Sab\or Dom\fi} }

\def\pgfcalendarweekdayname#1{ \translate{\ifcase#1\or Segunda\or Terça\or Quarta\or Quinta\or Sexta\or Sábado\or Domingo\fi} }

\newcommand{\calyear}{2017}
\newcommand{\mon}[1]{\calendar[dates = \calyear-#1-01
  to \calyear-#1-last] if (Sunday) [red];}

\begin{document}
\begin{tikzpicture}[every calendar/.style = {
    month label above centered,
    month text = {\Large\textsc{\%mt}},
    week list sunday,
  }]
  \matrix (Calendar) [column sep = 4em, row sep = 3em] {
    \mon{01} & \mon{02} & \mon{03} \\
    \mon{04} & \mon{05} & \mon{06} \\
    \mon{07} & \mon{08} & \mon{09} \\
    \mon{10} & \mon{11} & \mon{12} \\ };
  \node [above = 1cm of Calendar, font = \Huge]
  {\calyear};
\end{tikzpicture}
\end{document}

calendar

2

Get started with this Source http://www.texample.net/tikz/examples/changing-the-default-calendar-layout/

Tikz Calendar Style

% Define our own style
    \tikzstyle{week list sunday}=[
        % Note that we cannot extend from week list,
        % the execute before day scope is cumulative
        execute before day scope={%
               \ifdate{day of month=1}{\ifdate{equals=\pgfcalendarbeginiso}{}{
               % On first of month, except when first date in calendar.
                   \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@month@yshift}%
                   \pgftransformyshift{-\pgf@y}
               }}{}%
        },
        execute at begin day scope={%
            % Because for TikZ Monday is 0 and Sunday is 6,
            % we can't directly use \pgfcalendercurrentweekday,
            % but instead we define \c@pgf@counta (basically) as:
            % (\pgfcalendercurrentweekday + 1) % 7
            \pgfmathsetlength\pgf@x{\tikz@lib@cal@xshift}%
            \ifnum\pgfcalendarcurrentweekday=6
                \c@pgf@counta=0
            \else
                \c@pgf@counta=\pgfcalendarcurrentweekday
                \advance\c@pgf@counta by 1
            \fi
            \pgf@x=\c@pgf@counta\pgf@x
            % Shift to the right position for the day.
            \pgftransformxshift{\pgf@x}
        },
        execute after day scope={
            % Week is done, shift to the next line.
            \ifdate{Saturday}{
                \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}%
                \pgftransformyshift{-\pgf@y}
            }{}%
        },
        % This should be defined, glancing from the source code.
        tikz@lib@cal@width=7
    ]

Replace your style week list with week list sunday.

  • I had seen this page -- I can't get it to work (just adding the code doesn't change anything). How should I adapt it? – Joseph Jan 13 '17 at 23:24
  • @Joseph Put it in your preamble, probably, likely between a \makeatletter and \makeatother. Note that \tikzstyle is deprecated. – cfr Jan 15 '17 at 0:44
  • @cfr, that's exactly what I did, using the same MWE. It didn't work. – Joseph Jan 15 '17 at 0:54
  • @Joseph Works for me. – cfr Jan 15 '17 at 2:14
  • @Joseph Note that didn't work tells people almost nothing and certainly nothing which might lead to a diagnosis and solution. It could mean almost anything, – cfr Jan 15 '17 at 2:20

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.