我在 tikz 图片中有一个矩阵(由 组成calendar
)。我用 3 个矩形块将矩阵中的某些天数分开,但边缘重叠。如何防止边缘重叠?谢谢。
布卡普兹
\documentclass[10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calendar,backgrounds}
\begin{document}
\begin{tikzpicture}
\matrix{
\calendar (sep18) [dates=2018-09-01 to 2018-09-last,week list,month label above centered]; \\
};
\begin{scope}[on background layer]
\draw[draw=none,fill=orange,opacity=0.3] (sep18-2018-09-17.north west) -- (sep18-2018-09-23.north east)
-- (sep18-2018-09-30.south east) -- (sep18-2018-09-24.south west) -- cycle;
\draw[draw=black] (sep18-2018-09-17.north west) rectangle (sep18-2018-09-21.south east);
\draw[draw=black] (sep18-2018-09-24.north west) rectangle (sep18-2018-09-24.south east);
\draw[draw=black] (sep18-2018-09-25.north west) rectangle (sep18-2018-09-27.south east);
\end{scope}
\end{tikzpicture}
\end{document}
答案1
第一个选项,反复尝试day xshift
直到day yshift
找到正确的值以避免重叠:
\documentclass[10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calendar,backgrounds, calc}
\begin{document}
\begin{tikzpicture}
\matrix{
\calendar (sep18) [dates=2018-09-01 to 2018-09-last,week list,month label above centered, day xshift=4ex, day yshift=3.15ex]; \\
};
\begin{scope}[on background layer]
\fill[orange,opacity=0.3] (sep18-2018-09-17.north west) rectangle (sep18-2018-09-30.south east);
\draw[draw=black] (sep18-2018-09-17.north west) rectangle (sep18-2018-09-21.south east);
\draw[draw=black] (sep18-2018-09-24.north west) rectangle (sep18-2018-09-24.south east);
\draw[draw=black] (sep18-2018-09-25.north west) rectangle (sep18-2018-09-27.south east);
\end{scope}
\end{tikzpicture}
\end{document}
第二种选择:根据日期之间的中间坐标绘制矩形,而不是重叠的锚点。
\documentclass[10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calendar,backgrounds, calc}
\begin{document}
\begin{tikzpicture}
\matrix{
\calendar (sep18) [dates=2018-09-01 to 2018-09-last,week list,month label above centered]; \\
};
\begin{scope}[on background layer]
\fill[orange,opacity=0.3] (sep18-2018-09-17.north west) rectangle (sep18-2018-09-30.south east);
\coordinate (aux1) at ($(sep18-2018-09-21.south east)!.5!(sep18-2018-09-28.north east)$);
\coordinate (aux2) at ($(sep18-2018-09-21.south east)!.5!(sep18-2018-09-29.north west)$);
\draw[draw=black] (sep18-2018-09-17.north west) rectangle (aux1|-aux2);
\draw[draw=black] ($(sep18-2018-09-17.south west)!.5!(sep18-2018-09-24.north west)$) rectangle ($(sep18-2018-09-24.south east)!.5!(sep18-2018-09-25.south west)$) coordinate (aux3);
\draw[draw=black] (aux3) rectangle (aux1|-aux2);
\end{scope}
\end{tikzpicture}
\end{document}