我从以下代码中借用了这里并根据我的要求进行了更改。我想在边框的每个角落显示年份,想知道如何将年份更改为自定义年份。任何帮助都将不胜感激。谢谢
输出
平均能量损失
\documentclass[border=4.9mm, multi={tikzpicture}]{standalone}
%\usepackage[hmargin=2cm,bmargin=3cm,tmargin=4.5cm,centering,a4paper]{geometry}
\usepackage[utf8]{inputenc}
%%in preamble:
%
\usepackage{tikz}
\usetikzlibrary{positioning,calendar}
\usetikzlibrary{decorations.markings}
\newcommand{\calrow}[1]{\node[anchor=base east](Mon){M};
\node[base right=of Mon](Tue){T}; \node[base right=of Tue](Wed){W};
\node[base right=of Wed](Thu){T}; \node[base right=of Thu](Fri){F};
\node[base right=of Fri](Sat){S}; \node[base right=of Sat](Sun){S};
\node[darkgreen,above=of Thu]{\textbf{#1}};}
\newcommand{\calperiod}[1]{\calendar[dates=\the\year-#1-01 to \the\year-#1-last]
if(Sunday) [black!50] \holidays;}
\newcommand{\holidays}{% holidays in Italy
if (equals=01-01) [black!50]%
if (equals=01-06) [black!50]%
if (equals=04-04) [black!50]%
if (equals=04-05) [black!50]%
if (equals=04-25) [black!50]%
if (equals=05-01) [black!50]%
if (equals=05-01) [black!50]%
if (equals=06-02) [black!50]%
if (equals=08-15) [black!50]%
if (equals=11-01) [black!50]%
if (equals=12-08) [black!50]%
if (equals=12-25) [black!50]%
if (equals=12-26) [black!50]%
}
\colorlet{darkgreen}{green!50!black}
\begin{document}
%%in document:
%
\begin{tikzpicture}[every calendar/.style={week list}]
\sffamily
\matrix[%
row 1/.style={darkgreen,node distance=.3ex},%
row 3/.style={darkgreen,node distance=.3ex},
row 5/.style={darkgreen,node distance=.3ex},
row 7/.style={darkgreen,node distance=.3ex},
column sep=1ex,%
draw=darkgreen,thick,rounded corners=5pt,%
postaction={decorate,decoration={markings,mark=at position 0.51 with
{\node[fill=white,text=darkgreen,font={\bfseries\Large}] (year) {\the\year};}}}
% year on frame: decorations.markings library
]{%
% first row: week day and month
\calrow{January} & \calrow{February} & \calrow{March} \\
\calperiod{01} & \calperiod{02} & \calperiod{03} \\[1ex]
% second row: calendar
\calrow{April} & \calrow{May} & \calrow{June} \\
\calperiod{04} & \calperiod{05} & \calperiod{06} \\[1ex]
% third row: week day and month
\calrow{July} & \calrow{August} & \calrow{September} \\
\calperiod{07} & \calperiod{08} & \calperiod{09} \\[1ex]
% forth row: calendar
\calrow{October} & \calrow{November} & \calrow{December} \\
\calperiod{10} & \calperiod{11} & \calperiod{12} \\
};
\end{tikzpicture}
\end{document}
答案1
要获取不同的年份,只需使用 即可\year=2017
。但如果这不可行,则\currentyear
可以使用宏(可选地作为宏的默认参数\calperiod
)。
为了将年份排版在矩阵的角落,我使用了append after command
。这要求将\currentyear
设置在矩阵范围之外。此外,矩阵底部还需要一些额外的空间,以避免与年份标签重叠。
\documentclass[tikz,border=5]{standalone}
\renewcommand\familydefault\sfdefault
\usetikzlibrary{positioning,calendar}
\colorlet{darkgreen}{green!50!black}
\colorlet{holiday}{black!50}
\newcommand{\calrow}[1]{\node[anchor=base east](Mon){M};
\node[base right=of Mon](Tue){T}; \node[base right=of Tue](Wed){W};
\node[base right=of Wed](Thu){T}; \node[base right=of Thu](Fri){F};
\node[base right=of Fri](Sat){S}; \node[base right=of Sat](Sun){S};
\node[darkgreen, above=of Thu]{\textbf{#1}};}
\newcommand{\calperiod}[2][\currentyear]{%
\calendar[dates=\currentyear-#2-01 to \currentyear-#2-last]
if (Sunday) [holiday] \holidays;}
\edef\currentyear{\the\year}
\newcommand{\holidays}{% holidays in Italy
if (equals=01-01) [holiday]%
if (equals=01-06) [holiday]%
if (equals=04-04) [holiday]%
if (equals=04-05) [holiday]%
if (equals=04-25) [holiday]%
if (equals=05-01) [holiday]%
if (equals=05-01) [holiday]%
if (equals=06-02) [holiday]%
if (equals=08-15) [holiday]%
if (equals=11-01) [holiday]%
if (equals=12-08) [holiday]%
if (equals=12-25) [holiday]%
if (equals=12-26) [holiday]%
}
\begin{document}
\begin{tikzpicture}[every calendar/.style={week list},
year label/.style={
fill=white,text=darkgreen,font=\bfseries\Large
}, current year/.store in=\currentyear,
current year=2017]
\matrix[%
row 1/.style={darkgreen,node distance=.3ex},%
row 3/.style={darkgreen,node distance=.3ex},
row 5/.style={darkgreen,node distance=.3ex},
row 7/.style={darkgreen,node distance=.3ex},
column sep=1ex,%
draw=darkgreen,thick,rounded corners=5pt,%
append after command={
\pgfextra{\edef\matrixname{\tikzlastnode}}
node [year label/.try, right=1ex of \matrixname.south west] {\currentyear}
node [year label/.try, right=1ex of \matrixname.north west] {\currentyear}
node [year label/.try, left=1ex of \matrixname.south east] {\currentyear}
node [year label/.try, left=1ex of \matrixname.north east] {\currentyear}
}
]{%
% first row: week day and month
\calrow{January} & \calrow{February} & \calrow{March} \\
\calperiod{01} & \calperiod{02} & \calperiod{03} \\[1ex]
% second row: calendar
\calrow{April} & \calrow{May} & \calrow{June} \\
\calperiod{04} & \calperiod{05} & \calperiod{06} \\[1ex]
% third row: week day and month
\calrow{July} & \calrow{August} & \calrow{September} \\
\calperiod{07} & \calperiod{08} & \calperiod{09} \\[1ex]
% forth row: calendar
\calrow{October} & \calrow{November} & \calrow{December} \\
\calperiod{10} & \calperiod{11} & \calperiod{12} \\[1ex]\\
};
\end{tikzpicture}
\end{document}
答案2
边框从东北角开始,逆时针方向。水平距离为 2 份,垂直距离为 3 份。因此,2 位于西北,5 位于西南,7 位于东南。现在您可以在每个角落添加更多装饰。
\documentclass[border=4.9mm, multi={tikzpicture}]{standalone}
%\usepackage[hmargin=2cm,bmargin=3cm,tmargin=4.5cm,centering,a4paper]{geometry}
\usepackage[utf8]{inputenc}
%%in preamble:
%
\usepackage{tikz}
\usetikzlibrary{positioning,calendar}
\usetikzlibrary{decorations.markings}
\newcommand{\calrow}[1]{\node[anchor=base east](Mon){M};
\node[base right=of Mon](Tue){T}; \node[base right=of Tue](Wed){W};
\node[base right=of Wed](Thu){T}; \node[base right=of Thu](Fri){F};
\node[base right=of Fri](Sat){S}; \node[base right=of Sat](Sun){S};
\node[darkgreen,above=of Thu]{\textbf{#1}};}
\newcommand{\calperiod}[1]{\calendar[dates=\the\year-#1-01 to \the\year-#1-last]
if(Sunday) [black!50] \holidays;}
\newcommand{\holidays}{% holidays in Italy
if (equals=01-01) [black!50]%
if (equals=01-06) [black!50]%
if (equals=04-04) [black!50]%
if (equals=04-05) [black!50]%
if (equals=04-25) [black!50]%
if (equals=05-01) [black!50]%
if (equals=05-01) [black!50]%
if (equals=06-02) [black!50]%
if (equals=08-15) [black!50]%
if (equals=11-01) [black!50]%
if (equals=12-08) [black!50]%
if (equals=12-25) [black!50]%
if (equals=12-26) [black!50]%
}
\colorlet{darkgreen}{green!50!black}
\begin{document}
%%in document:
%
\begin{tikzpicture}[every calendar/.style={week list}]
\sffamily
\matrix[%
row 1/.style={darkgreen,node distance=.3ex},%
row 3/.style={darkgreen,node distance=.3ex},
row 5/.style={darkgreen,node distance=.3ex},
row 7/.style={darkgreen,node distance=.3ex},
column sep=1ex,%
draw=darkgreen,thick,rounded corners=5pt,%
postaction={decorate,decoration={markings,mark=at position 0.2 with
{\node[fill=white,text=darkgreen,font={\bfseries\Large}] (year) {\the\year};}
}},
postaction={decorate,decoration={markings,mark=at position 0.51 with
{\node[fill=white,text=darkgreen,font={\bfseries\Large}] (year) {\the\year};}
}},
postaction={decorate,decoration={markings,mark=at position 0.7 with
{\node[fill=white,text=darkgreen,font={\bfseries\Large}] (year) {\the\year};}
}},
postaction={decorate,decoration={markings,mark=at position 0.01 with
{\node[fill=white,text=darkgreen,font={\bfseries\Large}] (year) {\the\year};}
}},
% year on frame: decorations.markings library
]{%
% first row: week day and month
\calrow{January} & \calrow{February} & \calrow{March} \\
\calperiod{01} & \calperiod{02} & \calperiod{03} \\[1ex]
% second row: calendar
\calrow{April} & \calrow{May} & \calrow{June} \\
\calperiod{04} & \calperiod{05} & \calperiod{06} \\[1ex]
% third row: week day and month
\calrow{July} & \calrow{August} & \calrow{September} \\
\calperiod{07} & \calperiod{08} & \calperiod{09} \\[1ex]
% forth row: calendar
\calrow{October} & \calrow{November} & \calrow{December} \\
\calperiod{10} & \calperiod{11} & \calperiod{12} \\
};
\end{tikzpicture}
\end{document}