개인 명령을 사용하여 일부 요일 이름을 달력에 전달하고 싶습니다. 그러면 사용자가 요일을 쉽게 변경하고 개인 달력을 만들 수 있습니다.
\mydays
list 에 전달되는 하나의 인수로 명령을 정의했습니다 \mydayslist
.
달력 내에서 이 목록을 어떻게 사용합니까?
MWE
\documentclass{report}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar}
\newcommand*{\mydays}[1]{%
\def\mydayslist{#1}%
}
\mydays{Monday,Friday}
\begin{document}
I want to pass the days \mydayslist\ to the calendar.
\noindent\centering
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick}]
\calendar (cal) [dates=2014-02-01 to 2014-07-last, month list, month label left,%
month text=\textcolor{black}{\%mt}, month yshift=1.7em, black!20]
%
if (Tuesday) [black]
% if (\mydayslist) [black] %% <-- insert \mydayslist
;
\end{tikzpicture}
\end{document}
답변1
키를 사용하여 if
테스트할 스타일을 정의 할 수 있습니다.하나일 ( myif
내 예에서는). 그런 다음 .expand once
핸들러(또는 .expanded
핸들러)를 사용하여 매크로를 확장하고 .list
핸들러를 사용하여 목록을 적용할 수 있습니다.
\documentclass{report}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar}
\newcommand*{\mydays}[1]{%
\def\mydayslist{#1}%
}
\mydays{Monday,Friday}
\begin{document}
I want to pass the days \mydayslist\ to the calendar.
\noindent\centering
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick}]
\calendar (cal) [dates=2014-02-01 to 2014-07-last,month list,month label left,
month text=\textcolor{black}{\%mt},month yshift=1.7em, black!20,
myif/.style={if=(#1)[black]},
myif/.list/.expand once={\mydayslist},
];
\end{tikzpicture}
\end{document}
첫 번째 편집
and
조건이 포함된 예TikZ 달력 및 조건부 테스트.
\documentclass{report}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar}
% code from https://tex.stackexchange.com/a/141027/14500
\makeatletter
\def\pgfcalendar@matchesfalse{\global\let\ifpgfcalendar@matches\iffalse}
\def\pgfcalendar@matchestrue{\global\let\ifpgfcalendar@matches\iftrue}
\pgfcalendar@matchesfalse
\pgfqkeys{/pgf/calendar}{and/.code 2 args={%
\begingroup
\ifdate{#1}{\ifdate{#2}{\pgfcalendar@matchestrue}{}}{}%
\endgroup
\ifpgfcalendar@matches\pgfcalendarmatchestrue\pgfcalendar@matchesfalse\fi}}
\makeatother
%------
\newcommand*{\mydays}[1]{%
\def\mydayslist{#1}%
}
\mydays{Monday,Friday}
\begin{document}
I want to pass the days \mydayslist\ to the calendar.
\noindent\centering
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick}]
\calendar (cal) [
dates=2014-02-01 to 2014-07-last,
month list,month label left,
month text=\textcolor{black}{\%mt},
month yshift=1.7em, black!20,
myif2/.style={if={(and={between=2014-04-01 and 2014-05-32}{#1})[red]}},
myif2/.list/.expanded={\mydayslist},
];
\end{tikzpicture}
\end{document}
두 번째 편집
여기에 용액 혼합이 있습니다.구호의 대답그리고 이전 솔루션. day
날짜 목록을 테스트하기 위해 새 키를 정의했습니다 .
\pgfkeys{
/pgf/calendar/@day/.style={#1},
/pgf/calendar/day/.style={@day/.list/.expanded=#1},
}
이러한 키를 사용하면 항상 사양 구문(pgfmanual의 524페이지)을 사용할 수 있습니다.
and
조건이 있는 예TikZ 달력 및 조건부 테스트.
\documentclass{report}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar}
% code from https://tex.stackexchange.com/a/141027/14500
\makeatletter
\def\pgfcalendar@matchesfalse{\global\let\ifpgfcalendar@matches\iffalse}
\def\pgfcalendar@matchestrue{\global\let\ifpgfcalendar@matches\iftrue}
\pgfcalendar@matchesfalse
\pgfqkeys{/pgf/calendar}{and/.code 2 args={%
\begingroup
\ifdate{#1}{\ifdate{#2}{\pgfcalendar@matchestrue}{}}{}%
\endgroup
\ifpgfcalendar@matches\pgfcalendarmatchestrue\pgfcalendar@matchesfalse\fi}}
\makeatother
%------
\pgfkeys{
/pgf/calendar/@day/.style={#1},
/pgf/calendar/day/.style={@day/.list/.expanded=#1},
}
\newcommand*{\mydays}[1]{%
\def\mydayslist{#1}%
}
\mydays{Monday,Friday}
\begin{document}
I want to pass the days \mydayslist\ to the calendar.
\noindent\centering
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick}]
\calendar (cal) [
dates=2014-02-01 to 2014-07-last,
month list,month label left,
month text=\textcolor{black}{\%mt},
month yshift=1.7em, black!20,
]
if (day=Sunday) [black,font=\itshape]
if (day=\mydayslist) [green]
if (and={between=2014-04-01 and 2014-05-32}{day=\mydayslist}) [red]
;
\end{tikzpicture}
\end{document}
세 번째 편집
세 번째 솔루션은 매크로를 정의합니다 ( 또는 접두사를 사용하여 \calkeys
키-값 쌍을 관리하기 위해 ). 이 매크로를 사용하면 모든 달력 선택기를 명명된 스타일로 정의할 수 있습니다.\pgfkeys
\tikzset
/pgf/calendar/
\def\calkeys#1{\pgfkeys{/pgf/calendar/.cd,#1}}
\calkeys{
my day list/.style={Friday,Saturday},
april/.style={between=2014-04-01 and 2014-04-30},
my day list in april/.style={and={april}{my day list}},
}
예:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calendar}
% code from https://tex.stackexchange.com/a/141027/14500
\makeatletter
\def\pgfcalendar@matchesfalse{\global\let\ifpgfcalendar@matches\iffalse}
\def\pgfcalendar@matchestrue{\global\let\ifpgfcalendar@matches\iftrue}
\pgfcalendar@matchesfalse
\pgfqkeys{/pgf/calendar}{and/.code 2 args={%
\begingroup
\ifdate{#1}{\ifdate{#2}{\pgfcalendar@matchestrue}{}}{}%
\endgroup
\ifpgfcalendar@matches\pgfcalendarmatchestrue\pgfcalendar@matchesfalse\fi}}
\makeatother
% -----
\def\calkeys#1{\pgfkeys{/pgf/calendar/.cd,#1}}
\calkeys{
my day list/.style={Friday,Saturday},
april 2014/.style={between=2014-04-01 and 2014-04-30},
my day list in april 2014/.style={and={april 2014}{my day list}},
}
\begin{document}
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick}]
\calendar (cal) [dates=2014-02-01 to 2014-07-last,month list,month label left,
month text=\textcolor{black}{\%mt},month yshift=1.7em, black!20]
if (my day list) [red]
if (my day list in april 2014) [green]
;
\end{tikzpicture}
\end{document}
답변2
tikz
다음은 인수(여기)를 사전 확장하는 코드 에 대한 래퍼 명령이 있는 버전입니다. \mydayslist
키 값 인터페이스의 일반적인 문제는 키 값의 확장이 누락된다는 것입니다.
\documentclass{report}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar}
\def\mydayslist{}
\newcommand*{\mydays}[1]{%
\def\mydayslist{#1}%
}
\mydays{Monday,Tuesday,Friday}
\newcommand{\sigurslittlehelper}[1]{%
if (#1) [black]
;
}
\newcommand{\tikzdo}[1]{% Expand the list first, then use the tikz code
\expandafter\sigurslittlehelper\expandafter{#1}%
}
\begin{document}
I want to pass the days \mydayslist\ to the calendar.
\noindent\centering
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick}]
\calendar (cal) [dates=2014-02-01 to 2014-07-last, month list, month label left,%
month text=\textcolor{black}{\%mt}, month yshift=1.7em, black!20]
\tikzdo{\mydayslist}
\end{tikzpicture}
\end{document}
답변3
이것은 작동하는 것 같습니다. 내부로 전달하기 전에 제어 시퀀스를 확장하는 키를 정의합니다 \ifdate
. 로부터 나오다이 답변.
\documentclass{report}
\usepackage[margin=1cm,landscape]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar}
\newcommand*{\mydays}[1]{%
\def\mydayslist{#1}%
}
\mydays{Monday,Friday}
\pgfqkeys{/pgf/calendar}{fromcs/.code={\expandafter\ifdate\expandafter{#1}{}{}}}%<=====added
\begin{document}
I want to pass the days \mydayslist\ to the calendar.
\noindent\centering
\begin{tikzpicture}
[every day/.style={anchor=mid},every node/.style={inner sep=2pt,rectangle,thick}]
\calendar (cal) [dates=2014-02-01 to 2014-07-last, month list, month label left,%
month text=\textcolor{black}{\%mt}, month yshift=1.7em, black!20]
%
if (Tuesday) [black]
if (fromcs={\mydayslist}) [black] %% <-- insert \mydayslist
;
\end{tikzpicture}
\end{document}