如何在 TikZ 中的日历内放置箭头和虚线?

如何在 TikZ 中的日历内放置箭头和虚线?

我尝试在日历/时间表中将许多箭头连接和事件之间的虚线放入事件中,但我对“绘制”语句有问题:

这是我的实际日历的图片,我们看到了错误的箭头重叠线:

enter image description here

这就是我想要的:

enter image description here

这是我的脚本,我试图在节点 (a) 和 (b) 之间画线:

\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{tikz}
\usepackage{amssymb, amsmath}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}

\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}

\usetikzlibrary[positioning]
\usetikzlibrary{patterns}
\usepackage[french]{babel} % styles français

\title{A simple Timetable}
\author{Laurent Dutriaux}
\date{\today}
\newcommand{\daywidth}{2.2 cm}
\begin{document}
\maketitle

\begin{tikzpicture}[x=\daywidth, y=-1cm, node distance=0 cm,outer sep = 0pt]

% Style for Days
\tikzstyle{room}=[draw, rectangle,  minimum height=1cm, minimum width=\daywidth, fill=yellow!20,anchor=south west]

% Style for hours
\tikzstyle{timeslots}=[draw, rectangle, minimum height=1 cm, minimum width=1.5 cm, fill=yellow!30,anchor=north east]

% Styles for events
% Duration of sequences
\tikzstyle{events}=[rectangle,draw, minimum width=\daywidth, anchor=north west,text centered,text width=5 em]

\tikzstyle{1event}=[events,minimum height=1cm]
\tikzstyle{2events}=[events,minimum height=2cm]
\tikzstyle{3event2}=[events,minimum height=3cm]

%Style for type of sequence 
\tikzstyle{Ang2h}=[1event,fill=green!20]
\tikzstyle{Phys2h}=[1event,fill=red!20]
\tikzstyle{Math2h}=[1event,fill=blue!20]
\tikzstyle{TIPE2h}=[1event,fill=blue!10]
\tikzstyle{TP2h}=[2events, pattern=north east lines, pattern color=magenta]
\tikzstyle{G3h}=[3event2, pattern=north west lines, pattern color=magenta!60!white]
\tikzstyle{Planche}=[1event,fill=white]

% Positioning labels for days and hours
\node[room] (A) at (1,8) {$r_{1}$};
\node[room] (B) [right = of A] {$r_{2}$};
\node[room] (C) [right = of B] {$r_{3}$};
\node[room] (D) [right = of C] {$r_{4}$};

\node[timeslots] (AA) at (1,8) {$t_{1}$};
\node[timeslots] (BB) [below = of AA] {$t_{2}$};
\node[timeslots] (CC) [below= of BB] {$t_{3}$};
\node[timeslots] (DD) [below = of CC] {$t_{4}$};
\node[timeslots] (EE) [below  = of DD] {$t_{5}$};

%Position of sequences
\node[Phys2h] (a) at (1,8) {$e_{8}$};   %node a
\node[Phys2h] at (1,9) {};
\node[Phys2h] at (1,10) {};
\node[Phys2h] at (1,11) {$e_{16}$};
\node[Phys2h] at (1,12) {};

\node[Math2h] at (2,8) {};
\node[Math2h] (b) at (2,9) {$e_{7}$}; %node b
\node[Math2h] at (2,10) {};
\node[Math2h] at (2,11) {$e_{20}$};
\node[Math2h] at (2,12) {};


%Here my problem.......
\draw [-latex,thick] (a) --  node [anchor=135,outer sep=2pt] { } (b) ;

\node[TIPE2h] at (3,8) {};
\node[TIPE2h] at (3,9) {};
\node[TIPE2h] at (3,10) {$e_{11}$};
\node[TIPE2h] at (3,11) {};
\node[TIPE2h] at (3,12) {};

\node[TIPE2h] at (4,8) {};
\node[TIPE2h] at (4,9) {};
\node[TIPE2h] at (4,10) {};
\node[TIPE2h] at (4,11) {};
\node[TIPE2h] at (4,12) {};

\end{tikzpicture}
\end{document}

是否有一种有效的方法通过箭头或虚线连接事件?

问候,

答案1

节点是延伸的对象。你可以连接中心并稍微缩短箭头。

\documentclass[a4paper,11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{tikz}
\usepackage{amssymb, amsmath}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}

\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}

\usetikzlibrary[positioning]
\usetikzlibrary{patterns}
\usepackage[french]{babel} % styles français

\title{A simple Timetable}
\author{Laurent Dutriaux}
\date{\today}
\newcommand{\daywidth}{2.2 cm}
\begin{document}
\maketitle

\begin{tikzpicture}[x=\daywidth, y=-1cm, node distance=0 cm,outer sep = 0pt]

% Style for Days
\tikzstyle{room}=[draw, rectangle,  minimum height=1cm, minimum width=\daywidth, fill=yellow!20,anchor=south west]

% Style for hours
\tikzstyle{timeslots}=[draw, rectangle, minimum height=1 cm, minimum width=1.5 cm, fill=yellow!30,anchor=north east]

% Styles for events
% Duration of sequences
\tikzstyle{events}=[rectangle,draw, minimum width=\daywidth, anchor=north west,text centered,text width=5 em]

\tikzstyle{1event}=[events,minimum height=1cm]
\tikzstyle{2events}=[events,minimum height=2cm]
\tikzstyle{3event2}=[events,minimum height=3cm]

%Style for type of sequence 
\tikzstyle{Ang2h}=[1event,fill=green!20]
\tikzstyle{Phys2h}=[1event,fill=red!20]
\tikzstyle{Math2h}=[1event,fill=blue!20]
\tikzstyle{TIPE2h}=[1event,fill=blue!10]
\tikzstyle{TP2h}=[2events, pattern=north east lines, pattern color=magenta]
\tikzstyle{G3h}=[3event2, pattern=north west lines, pattern color=magenta!60!white]
\tikzstyle{Planche}=[1event,fill=white]

% Positioning labels for days and hours
\node[room] (A) at (1,8) {$r_{1}$};
\node[room] (B) [right = of A] {$r_{2}$};
\node[room] (C) [right = of B] {$r_{3}$};
\node[room] (D) [right = of C] {$r_{4}$};

\node[timeslots] (AA) at (1,8) {$t_{1}$};
\node[timeslots] (BB) [below = of AA] {$t_{2}$};
\node[timeslots] (CC) [below= of BB] {$t_{3}$};
\node[timeslots] (DD) [below = of CC] {$t_{4}$};
\node[timeslots] (EE) [below  = of DD] {$t_{5}$};

%Position of sequences
\node[Phys2h] (a) at (1,8) {$e_{8}$};   %node a
\node[Phys2h] at (1,9) {};
\node[Phys2h] at (1,10) {};
\node[Phys2h] (e) at (1,11) {$e_{16}$};
\node[Phys2h] at (1,12) {};

\node[Math2h] at (2,8) {};
\node[Math2h] (b) at (2,9) {$e_{7}$}; %node b
\node[Math2h] at (2,10) {};
\node[Math2h] (c) at (2,11) {$e_{20}$};
\node[Math2h] at (2,12) {};



\node[TIPE2h] at (3,8) {};
\node[TIPE2h] at (3,9) {};
\node[TIPE2h] (d) at (3,10) {$e_{11}$};
\node[TIPE2h] at (3,11) {};
\node[TIPE2h] at (3,12) {};

\node[TIPE2h] at (4,8) {};
\node[TIPE2h] at (4,9) {};
\node[TIPE2h] at (4,10) {};
\node[TIPE2h] at (4,11) {};
\node[TIPE2h] at (4,12) {};

%Arrows
\draw [-latex,thick,shorten >=5pt,shorten <=5pt] (a.center) --  node [anchor=135,outer sep=2pt] { }
(b.center) ;
\draw [-latex,thick,shorten >=5pt,shorten <=5pt] (b.center) --  node [anchor=135,outer sep=2pt] { }
(c.center) ;
\draw [-latex,thick,shorten >=7pt,shorten <=7pt] (c.center) --  node [anchor=135,outer sep=2pt] { }
(e.center) ;
\draw [-latex,thick,shorten >=5pt,shorten <=7pt] (e.center) to[bend right=40]  node [anchor=135,outer sep=2pt] { }
(d.center) ;
% dotted line
\draw[very thick,dotted,shorten >=6pt] (EE.center) -- ++(0,-1.5cm);

\end{tikzpicture}
\end{document}

enter image description here

相关内容