这是我根据 TikZ 手册改编的代码。我想做一个农业日历,但我对节点的位置感到困惑。非常感谢您的帮助。谢谢。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calendar,shadings}
\usetikzlibrary{calc}
\def\termin#1#2{
\node [text width= 3.4cm] at
($(cal-#1)+(0em, 0em)$) {\textcolor{red}\tiny{#2}};
}
\begin{document}
\sffamily
% A counter, since TikZ is not clever enough (yet) to handle
% arbitrary angle systems.
\newcount\mycount
\begin{tikzpicture}
[transform shape,
every day/.style={anchor=mid,font=\fontsize{6}{6}\selectfont}]
%\node{\normalsize 2012};
\foreach \month in
{1,2,...,12}
{
% Compute angle:
\mycount=\month
\advance\mycount by -1
\multiply\mycount by 30
\advance\mycount by -90
% The actual calendar
\calendar at (\the\mycount:6cm)
[
dates=2012-\month-01 to 2012-\month-last, name=cal,
]
if (day of month=1) {\tikzmonthcode}
if (equals = 2012-11-20) [red]
if (equals = 2012-03-10) [red]
if (all)
{
% Again, compute angle
\mycount=1
\advance\mycount by -\pgfcalendarcurrentday
\multiply\mycount by 11
\advance\mycount by 90
\pgftransformshift{\pgfpointpolar{\mycount}{1.4cm}}
};
}
\termin{2012-11-20}{\color{red}Soybean planting}
\termin{2012-03-10}{\color{red}Soybean harvesting}
\end{tikzpicture}
\end{document}
答案1
您可以向 中添加一个参数来termin
指定定位选项。下面我将left=2.5ex
定位应用于“大豆种植”,并将 定位right=1.5ex
应用于“大豆收获”。
代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calendar,shadings}
\usetikzlibrary{calc}
\newcommand{\termin}[3][]{%
\node [#1] at
($(cal-#2)+(0em, 0em)$) {\textcolor{red}{#3}};
}
\begin{document}
\sffamily
% A counter, since TikZ is not clever enough (yet) to handle
% arbitrary angle systems.
\newcount\mycount
\noindent
\begin{tikzpicture}
[transform shape, scale=0.85,
every day/.style={anchor=mid,font=\fontsize{6}{6}\selectfont}]
%\node{\normalsize 2012};
\foreach \month in
{1,2,...,12}
{
% Compute angle:
\mycount=\month
\advance\mycount by -1
\multiply\mycount by 30
\advance\mycount by -90
% The actual calendar
\calendar at (\the\mycount:6cm)
[
dates=2012-\month-01 to 2012-\month-last, name=cal,
]
if (day of month=1) {\tikzmonthcode}
if (equals = 2012-11-20) [red]
if (equals = 2012-03-10) [red]
if (all)
{
% Again, compute angle
\mycount=1
\advance\mycount by -\pgfcalendarcurrentday
\multiply\mycount by 11
\advance\mycount by 90
\pgftransformshift{\pgfpointpolar{\mycount}{1.4cm}}
};
}
\termin[left=2.5ex]{2012-11-20}{\color{red}Soybean planting}
\termin[right=1.5ex]{2012-03-10}{\color{red}Soybean harvesting}
\end{tikzpicture}
\end{document}
答案2
这是一个答案。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calendar,shadings,positioning}
\usetikzlibrary{calc}
\def\termin#1#2#3#4{%
\node [align=left,text=red,font=\tiny, #2 =0ex of cal-#1,anchor=#3] {#4};
}%
\begin{document}
\sffamily
% A counter, since TikZ is not clever enough (yet) to handle
% arbitrary angle systems.
\newcount\mycount
\begin{tikzpicture}
[transform shape,
every day/.style={anchor=mid,font=\fontsize{6}{6}\selectfont}]
%\node{\normalsize 2012};
\foreach \month in
{1,2,...,12}
{
% Compute angle:
\mycount=\month
\advance\mycount by -1
\multiply\mycount by 30
\advance\mycount by -90
% The actual calendar
\calendar at (\the\mycount:6cm)
[
dates=2012-\month-01 to 2012-\month-last, name=cal,
]
if (day of month=1) {\tikzmonthcode}
if (equals = 2012-11-20) [red]
if (equals = 2012-03-10) [red]
if (all)
{
% Again, compute angle
\mycount=1
\advance\mycount by -\pgfcalendarcurrentday
\multiply\mycount by 11
\advance\mycount by 90
\pgftransformshift{\pgfpointpolar{\mycount}{1.4cm}}
};
}
\termin{2012-11-20}{left}{east}{Soybean planting}
\termin{2012-03-10}{right}{west}{Soybean harvesting}
\end{tikzpicture}
\end{document}