0

i use overlead and now i want to highlight current date on month calendar. This guide: Calendar with TIKZ-PGF: How to highlight current date?. But in my calendar display wrong place (Please see image) Thanks enter image description here My code:

\documentclass[a4paper,10pt]{article}
\usepackage[a4paper,left=2cm,right=2cm,top=1cm,bottom=1cm]{geometry}
%pagesize,
\usepackage[T1]{fontenc}
\usepackage[justification=centering]{caption}   
\usepackage{graphicx}
\usepackage[romanian]{babel}
%\usepackage{libertine} % fonts not installed here
\usepackage{translator, tikz, array} % pgfcalendar loaded later with \usetikzlibrary{calendar}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
%\usepackage{xcolor} % loaded by tikz
\usepackage{tabu}
\usepackage{epstopdf}
%\usepackage{color} % unnecessary, because xcolor already loaded
%\usepackage{pgf} % loaded by tikz

%=========================================================
%== Page characteristics (Page Setup) ====================
% using geometry would be better


\usetikzlibrary{calendar,shapes.geometric}
\usetikzlibrary{calc}
%== Define colors =================================
\definecolor{rozmam}{RGB}{242,172,184}
\newcommand{\troz}{\textcolor{rozmam}}


\makeatletter%
% these days, \tikzset is used
\tikzset{%
    day headings/.style={day heading=#1}, % \tikzoption{day headings}{\tikzstyle{day heading}=[#1]}
    day heading/.style={}, % \tikzstyle{day heading}=[]
    day letter headings/.style={% \tikzstyle{day letter headings} ...
        execute before day scope={ \ifdate{day of month=1}{%
          \pgfmathsetlength{\pgf@ya}{\tikz@lib@cal@yshift}%
          \pgfmathsetlength\pgf@xa{\tikz@lib@cal@xshift}%
          \pgftransformyshift{-\pgf@ya}
          \foreach \d/\l in {0/M,1/T,2/W,3/T,4/F,5/S,6/S} {
            \pgf@xa=\d\pgf@xa%
            \pgftransformxshift{\pgf@xa}%
            \pgftransformyshift{\pgf@ya}%
            \node[every day,day heading]{\l};%
          }
        }{}%
      }
    }
}
\makeatother



\begin{document}


\foreach \n in {2,...,2}{

\pgfcalendar{cal}{2018-\n-01}{2018-\n-last}
{
% added to ensure every day starts on a new page
\newpage
\thispagestyle{empty}
% remember day and month

\begin{minipage}{3cm}
\captionsetup{skip=4pt, minmargin=0cm, maxmargin=0cm}
{
  \centering
\includegraphics[width=2cm]{Image/ABC.jpg}
 \captionof*{figure}{\textcolor{red}{ABC}}
}
\end{minipage}%
\hspace*{0.8cm} 
\begin{minipage}{7cm}
\centering
\Huge  \textcolor{blue}{Planner} \\

\edef\pagedayofmonth{\pgfcalendarcurrentday}%
\edef\pagemonth{\pgfcalendarcurrentmonth}%
\noindent
{
\Huge \pgfcalendarweekdayname{\pgfcalendarcurrentweekday}
\Huge \bfseries
\pgfcalendarcurrentday{}\\[20pt]

}
\end{minipage}
\begin{tikzpicture}[remember picture, overlay, transform shape]
  \node [anchor=north east, inner sep=8pt, xshift = -15pt]
    at (current page.north east)
    {
      \begin{tikzpicture}[every node/.append style = {anchor=center}]
        \calendar (mycal) [dates=2018-\n-01 to 2018-\n-last,
        week list,
        day text=\%d0,
        month label above centered,
        month text={\%mt} \%y-,
        day xshift = 0.8cm,
        day headings=gray,
        day letter headings
    ]
    if (Saturday) [rozmam]
    if (Sunday)   [rozmam]
    % just set another text color; nodes={draw} could be added, but the rectangle is too large
    if (day of month=\pagedayofmonth) [cyan]
    ;
    % draw a frame around the day
    \draw[green,thick,rounded corners]
        ($(mycal-2018-\pagemonth-\pagedayofmonth.south east) + (-1.5mm,1.5mm)$) rectangle 
        ($(mycal-2018-\pagemonth-\pagedayofmonth.north west) + (1.5mm,-1.5mm)$);


      \end{tikzpicture}
    };
\end{tikzpicture}

\\[30pt]
\pagebreak
%{}
 }
}
\end{document}
  • 2
    Your code produces multiple errors. – Skillmon Sep 24 '18 at 12:50
  • i complete in overleaf and it can ignore some errors – latexforti Sep 24 '18 at 13:08
  • 2
    Though overleaf can ignore errors (as well as any other TeX installation), it might be the source of the issues. It is never a good idea to let errors pile up. – Skillmon Sep 24 '18 at 13:32
  • Thanks Skillmon, but i can not fix these errors – latexforti Sep 26 '18 at 8:18
  • 1
    I just noticed that you did use <pre>...</pre> to mark the code in your question. That is the wrong way and leads to the wrong output, which I copied, inserting multiple syntax errors which weren't there in your code. To mark displayed code as such, either select it with your mouse and hit the {} button in the editor, or indent each line by four spaces (which is what the code button does). – Skillmon Sep 26 '18 at 8:22
2

The following code compiled thrice does produce correct output (I just removed a superfluous \\ and changed the \edef\pagedayofmonth and \edef\pagemonth to \xdef\pagedayofmonth and \xdef\pagemonth, and replaced your image with one generally available on TeX Live and MikTeX).

\documentclass[a4paper,10pt]{article}
\usepackage[a4paper,left=2cm,right=2cm,top=1cm,bottom=1cm]{geometry}
%pagesize,
\usepackage[T1]{fontenc}
\usepackage[justification=centering]{caption}   
\usepackage{graphicx}
\usepackage[romanian]{babel}
%\usepackage{libertine} % fonts not installed here
\usepackage{translator, tikz, array} % pgfcalendar loaded later with \usetikzlibrary{calendar}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
%\usepackage{xcolor} % loaded by tikz
\usepackage{tabu}
\usepackage{epstopdf}
%\usepackage{color} % unnecessary, because xcolor already loaded
%\usepackage{pgf} % loaded by tikz

%=========================================================
%== Page characteristics (Page Setup) ====================
% using geometry would be better


\usetikzlibrary{calendar,shapes.geometric}
\usetikzlibrary{calc}
%== Define colors =================================
\definecolor{rozmam}{RGB}{242,172,184}
\newcommand{\troz}{\textcolor{rozmam}}


\makeatletter%
% these days, \tikzset is used
\tikzset{%
    day headings/.style={day heading=#1}, % \tikzoption{day headings}{\tikzstyle{day heading}=[#1]}
    day heading/.style={}, % \tikzstyle{day heading}=[]
    day letter headings/.style={% \tikzstyle{day letter headings} ...
        execute before day scope={ \ifdate{day of month=1}{%
          \pgfmathsetlength{\pgf@ya}{\tikz@lib@cal@yshift}%
          \pgfmathsetlength\pgf@xa{\tikz@lib@cal@xshift}%
          \pgftransformyshift{-\pgf@ya}
          \foreach \d/\l in {0/M,1/T,2/W,3/T,4/F,5/S,6/S} {
            \pgf@xa=\d\pgf@xa%
            \pgftransformxshift{\pgf@xa}%
            \pgftransformyshift{\pgf@ya}%
            \node[every day,day heading]{\l};%
          }
        }{}%
      }
    }
}
\makeatother



\begin{document}


\foreach \n in {2,...,2}{

\pgfcalendar{cal}{2018-\n-01}{2018-\n-last}
{
% added to ensure every day starts on a new page
\newpage
\thispagestyle{empty}
% remember day and month

\begin{minipage}{3cm}
\captionsetup{skip=4pt, minmargin=0cm, maxmargin=0cm}
{
  \centering
\includegraphics[width=2cm]{example-image-duck}
 \captionof*{figure}{\textcolor{red}{ABC}}
}
\end{minipage}%
\hspace*{0.8cm} 
\begin{minipage}{7cm}
\centering
\Huge  \textcolor{blue}{Planner} \\

\xdef\pagedayofmonth{\pgfcalendarcurrentday}%
\xdef\pagemonth{\pgfcalendarcurrentmonth}%
\noindent
{
\Huge \pgfcalendarweekdayname{\pgfcalendarcurrentweekday}
\Huge \bfseries
\pgfcalendarcurrentday{}\\[20pt]

}
\end{minipage}
\begin{tikzpicture}[remember picture, overlay, transform shape]
  \node [anchor=north east, inner sep=8pt, xshift = -15pt]
    at (current page.north east)
    {
      \begin{tikzpicture}[every node/.append style = {anchor=center}]
        \calendar (mycal) [dates=2018-\n-01 to 2018-\n-last,
        week list,
        day text=\%d0,
        month label above centered,
        month text={\%mt} \%y-,
        day xshift = 0.8cm,
        day headings=gray,
        day letter headings
    ]
    if (Saturday) [rozmam]
    if (Sunday)   [rozmam]
    % just set another text color; nodes={draw} could be added, but the rectangle is too large
    if (day of month=\pagedayofmonth) [cyan]
    ;
    % draw a frame around the day
    \draw[green,thick,rounded corners]
        ($(mycal-2018-\pagemonth-\pagedayofmonth.south east) + (-1.5mm,1.5mm)$) rectangle 
        ($(mycal-2018-\pagemonth-\pagedayofmonth.north west) + (1.5mm,-1.5mm)$);


      \end{tikzpicture}
    };
\end{tikzpicture}

\pagebreak
%{}
 }
}
\end{document}
  • Thank Skillmon, your code is really better. – latexforti Sep 26 '18 at 14:16
  • @BVOT it isn't my code, I just changed three lines... – Skillmon Sep 26 '18 at 14:16
  • i change the number of year 2018 -> 2019 then this error again: highlight position not in current day. "\begin{tikzpicture}[every node/.append style = {anchor=center}] \calendar (mycal) [dates=2019-\n-01 to 2019-\n-last," can you fix it? Thanks – latexforti Sep 27 '18 at 23:37
  • @tisaigon if I change every occurrence of 2018 with 2019 I don't get any errors and it builds fine. – Skillmon Sep 28 '18 at 7:30
  • Thank skillmon, how can i move this calendar x to left postion (1cm) and y to below position (1cm) – latexforti Sep 28 '18 at 14:17

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.