0

I would like to keep a sort of diary in LaTeX, and in this context I have the need for a command like:

\entry{date}{title}

such that the following is satisfied:

  • each 'diary entry' corresponds to a chapter of the dairy (assuming that the diary uses the documentclass book) and starts on a new page;
  • the date is listed on the left margin just next to the title as a marginnote;
  • the title starts exactly on the left margin (so it is aligned with the text below).

In this way I could list eventually all the diary entries in a table of contents. Less important but useful to me would be to control the spacing between the entry title and the first sentence of the entry (let's say this vertical distance equals \parskip).

All ideas, questions and suggestions are welcome.

1 Answer 1

2

Here is an option that uses the article class and setting the title manually. ToC-entries are inserted as \sections, which you can format using tocloft, if needed:

enter image description here

\documentclass{article}

\usepackage[paper=a5paper]{geometry}% Document layout
\usepackage{graphicx}
\usepackage{lipsum}

\makeatletter
\newcommand{\entry}[2]{% \entry{<date>}{<title>}
  \clearpage
  \noindent\leavevmode
  \addcontentsline{toc}{section}{#2}% Add to ToC
  \makebox[0pt][r]{\smash{\rotatebox[origin=r]{90}{\@datefont\strut #1\hspace*{-.5\baselineskip}}}\hspace{\datedist}}%
  {\@titlefont #2\par}%
  \vspace{\titleskip}
  \leavevmode\noindent
}
\newlength{\datedist}
\newcommand{\setdatedist}{\setlength{\datedist}}
\newcommand{\datefont}[1]{\gdef\@datefont{#1}}
\newcommand{\titlefont}[1]{\gdef\@titlefont{#1}}
\newlength{\titleskip}
\newcommand{\settitleskip}{\setlength{\titleskip}}
\makeatother

% Defaults
\datefont{\scshape}
\titlefont{\large\bfseries\sffamily}
\setdatedist{1em}
\settitleskip{\parskip}

% If you want to format the ToC entries...
\usepackage{tocloft}
\renewcommand{\cftsecfont}{\normalfont}

\begin{document}

\tableofcontents

\entry{\today}{Today}
\lipsum[1]

\entry{2017-06-01}{Tomorrow}
\lipsum[1-2]

\entry{July 1st, 2016}{Yesterday}
\lipsum[1-3]

\end{document}

Customization has been added to change

  • the distance the date is offset into the margin (via \setdatedist{<len>});

  • the date font (via \datefont{<font>});

  • the title font (via \titlefont{<font>}); and

  • the vertical skip below the title entry (via \settitleskip{<len>}).

3
  • Is there a way to add the date also in the toc (say also in the left margin)?
    – AYK
    Jul 1, 2016 at 1:36
  • @AYK: As a start, use \addcontentsline{toc}{section}{#1: #2} within the \entry command. There doesn't seem like there is enough room to place the date in the margin.
    – Werner
    Jul 1, 2016 at 2:49
  • Actually for my personal use I have a margin length of 5 cm (I have other commands making use of the margin), this is also why I have omitted the rotatebox command.
    – AYK
    Jul 1, 2016 at 11:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .