LaTeX 中的日程安排

LaTeX 中的日程安排

我正在寻找一种在 LaTeX 中输入每周计划的方法。唯一的问题是条目可能会有重叠。

我在看“用于日程表和/或日历的 LaTeX 类或样式?”但这不是我想要的日程表/日历类型。

我也查看了这个schedule.sty包,但它没有提供处理重叠条目的方法。

本时间表中的条目示例如下:

Monday 8am to 12am: Virtual Reality,
Monday 8am to 10am: Real time networks,
Monday 1pm to 4pm : ESOA, ...

根据以上条目的输出示例

有谁有办法用 LaTeX 生成每周计划吗?

答案1

我忍不住想说:这是用 TikZ 绘制此图的一种方法。为了使它更好用,应该有一些额外的包装器,可以自动计算节点的水平位置。除此之外,代码非常简洁。

\documentclass{article}
\usepackage{tikz}

\begin{document}

% These set the width of a day and the height of an hour.
\newcommand*\daywidth{6cm}
\newcommand*\hourheight{1.2em}

% The entry style will have two options:
% * the first option sets how many hours the entry will be (i.e. its height);
% * the second option sets how many overlapping entries there are (thus
%   determining the width).
\tikzset{entry/.style 2 args={
    draw,
    rectangle,
    anchor=north west,
    line width=0.4pt,
    inner sep=0.3333em,
    text width={\daywidth/#2-0.6666em-0.4pt},
    minimum height=#1*\hourheight,
    align=center
}}

% Start the picture and set the x coordinate to correspond to days and the y
% coordinate to correspond to hours (y should point downwards).
\begin{tikzpicture}[y=-\hourheight,x=\daywidth]

    % First print a list of times.
    \foreach \time/\ustime in {8/8am,9/9am,10/10am,11/11am,12/12pm,13/1pm,14/2pm,15/3pm,16/4pm,17/5pm,18/6pm}
        \node[anchor=north east] at (1,\time) {\ustime};

    % Draw some day dividers.
    \draw (1,6.5) -- (1,19);
    \draw (2,6.5) -- (2,19);
    \draw (3,6.5) -- (3,19);

    % Start Monday.
    \node[anchor=north] at (1.5,6.5) {Monday};
    % Write the entries. Note that the x coordinate is 1 (for Monday) plus an
    % appropriate amount of shifting. The y coordinate is simply the starting
    % time.
    \node[entry={4}{2}] at (1,8) {Virtual Reality};
    \node[entry={3}{2}] at (1.5,8) {Realtime Network};
    \node[entry={3}{1}] at (1,13) {EOSA};

    % The same for Tuesday.
    \node[anchor=north] at (2.5,6.5) {Tuesday};
    \node[entry={3.5}{3}] at (2,9) {Class A};
    \node[entry={2.5}{3}] at (2.33333,9.5) {Class B};
    \node[entry={2.5}{3}] at (2.66667,10) {Class C};
\end{tikzpicture}
\end{document}

结果

当然,你可以运用 TikZ 的所有功能来让它看起来更好(或更糟......)。例如,只需\tikzset

\tikzset{entry/.style 2 args={
    xshift=(0.5334em+0.8pt)/2,
    draw,
    line width=0.8pt,
    font=\sffamily,
    rectangle,
    rounded corners,
    fill=blue!20,
    anchor=north west,
    inner sep=0.3333em,
    text width={\daywidth/#2-1.2em-1.6pt},
    minimum height=#1*\hourheight,
    align=center
}}

获得

示例 2

答案2

谢谢 Caramdir。这就是我的使用方法。我用相同的颜色给相同的课程上色。并将白色部分更改为相同课程但不同组。至于颜色,我从这个页面获得了灵感: https://99designs.com/blog/creative-inspiration/color-combinations/

\documentclass[12pt]{scrartcl}
\setparsizes{0em}{0.25\baselineskip plus .25\baselineskip}{1em plus 1fil}

\usepackage{geometry}
\geometry{
paper = a4paper,
textwidth = 250mm,
textheight = 160mm,
landscape
}

\usepackage[newcommands]{ragged2e}
%\setlength{\RaggedRightskip}{0pt plus 2cm}

\usepackage[libertinus]{fontsetup}


%\usepackage[ngerman]{babel}
%\selectlanguage{ngerman}
\usepackage{microtype}
%======
\usepackage{tikz}
\usetikzlibrary{math}
%======

\definecolor{co-olive}{HTML}{829079}
\definecolor{co-beige}{HTML}{ede6b9}
\definecolor{co-brown}{HTML}{b9925e}

\colorlet{co-cour}{co-olive!25!white}
\colorlet{co-labA}{co-beige!45!white}
\colorlet{co-labB}{co-beige!30!white}
\colorlet{co-mast}{orange!20!white}
\colorlet{co-lecA}{co-brown!35!white}
\colorlet{co-lecB}{co-brown!20!white}

\begin{document}
\enlargethispage{2cm}
\thispagestyle{empty}

% Start
% These set the width of a day and the height of an hour.
\newcommand*\daywidth{5cm}
\newcommand*\hourheight{1.2cm}

% The entry style will have two options:
% * the first option sets how many hours the entry will be (i.e. its height);
% * the second option sets how many overlapping entries there are (thus
%   determining the width).
\tikzset{entry/.style 2 args={
    draw,
    rectangle,
    rounded corners,
    anchor=north west,
    line width=0.4pt,
    inner xsep=0.3333em,
    inner ysep=0ex,
    text width={\daywidth/#2-0.6666em-0.4pt},
    text height=2.5ex,
    text depth=#1*\hourheight-2.5ex,
    align=left
}}
\vspace*{-2cm}
\begin{center}
    Schedule 2023
\end{center}


% Start the picture and set the x coordinate to correspond to days and the y
% coordinate to correspond to hours (y should point downwards).
\begin{tikzpicture}[y=-\hourheight,x=\daywidth]

    % First print a list of times 9 - 16 o'clock
    \foreach \time/\ustime in {9/9,10/10,11/11,12/12,13/13,14/14,15/15,16/16}{
        % Full hour, added :00
        % changed anchor to mid east
        \node[anchor=mid east] at (0.94,\time) {\ustime:00};
        \draw [thick] (1,\time) -- (6,\time);
        
        % Quarter
        \foreach \qtime/\qmin in {0.25/15,0.5/30,0.75/45}{
          \node[anchor=mid east] at (1,\time+\qtime) {\qmin};
          \draw [thin] (1,\time+\qtime) -- (6,\time+\qtime);
          }
        }
      
  % Adding the times: 17:00
  % And then 15,30
  \node[anchor=mid east] at (0.94,17) {17:00};
  \draw [thick] (1,17) -- (6,17);
     \foreach \qtime/\qmin in {0.25/15,0.5/30}{
         \node[anchor=mid east] at (1,17+\qtime) {\qmin};
          \draw [thin] (1,17+\qtime) -- (6,17+\qtime);
      }
        
\tikzmath{
   \startTime =  8.5; % Vertical line start
   \endTime   = 18;   % Vertical line end
%   
   \xday = 1.5; % x-position of name of days
   \yday = 8.5; % y-position (hour) of name of days
}

    % Draw some day dividers.
    \foreach \i in {1,...,6}
       \draw (\i,\startTime) -- (\i,\endTime);
    

    % Start Monday
    \node[anchor=north] at (\xday,\yday) {Monday};
    % Write the entries. Note that the x coordinate is 1 (for Monday) plus an
    % appropriate amount of shifting. The y coordinate is simply the starting
    % time.

    % Tuesday
    \node[anchor=north] at (\xday+1,\yday) {Tuesday};
    \node[entry={1.5}{1}, fill=co-cour] 
                  at (2,11.5) {Course 3 \\Room 1.23};
    \node[entry={1.5}{2}, fill=co-labA] 
                  at (2,14) {Lab RT 3A\\ S 05.305};
    \node[entry={1.5}{2}, fill=co-mast] 
                  at (2.5,14) {Master\\ Room 1.33};
    \node[entry={1.5}{2}, fill=co-labA] 
                  at (2,15.75) {Lab RT 3A\\ Room 2.34};
    \node[entry={1.5}{2}, fill=co-mast] 
                  at (2.5,15.75) {Master\\ Room 3.45};
                  
   % Wednesday
    \node[anchor=north] at (\xday+2,\yday) {Wednesday};
    \node[entry={1.5}{1}, fill=co-labB] 
                  at (3,14) {Lab RT 3B\\ Room 3.45};
    \node[entry={1.5}{1}, fill=co-labB] 
                  at (3,15.75) {Lab RT 3B\\ Room 3.45};

   % Thursday
    \node[anchor=north] at (\xday+3,\yday) {Thursday};
    \node[entry={1.5}{1}, fill=co-lecA] 
                  at (4,14) {Lecture A\\ Room 3.45};
    \node[entry={1.5}{1}, fill=co-lecB] 
                  at (4,15.75) {Lecture B\\ Room 3.45};
                  
   % Friday
    \node[anchor=north] at (\xday+4,\yday) {Friday};
    \node[entry={1.5}{1}, fill=co-lecB] 
                  at (5,9.75) {Lecture B\\ Room 3.45};
    \node[entry={1.5}{1}, fill=co-lecA] 
                  at (5,11.5) {Lecture A\\ Room 3.45};
    \node[entry={1.5}{1}, fill=co-cour] 
                  at (5,14) {Course 3\\ Room 3.45};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容