4

I'm working to create an environment where I can take notes in LaTeX so it looks like notebook paper and handwriting. My code so far is as follows (I included graphics, tables, text, and headings, because I wanted to see how they looked):

\documentclass[letterpaper, 10pt]{article}
\usepackage{tikz, background, titling, setspace,titlesec,booktabs,float}
\usepackage[left=1.5in,right=.25in,top=1.125in,bottom=.125in]{geometry}
\usetikzlibrary{calc}

\backgroundsetup{%
 position=current page.center,
 angle=0,
 scale=1,
 contents={%
  \begin{tikzpicture}%
    [
      normal lines/.style={gray, very thin},
      every node/.append style={black, align=center, opacity=1}
    ]
    \foreach \y in {0.71,1.41,...,25.56}
      \draw[normal lines] (0,\y) -- (8.5in,\y);
    \draw[normal lines] (1.25in,0) -- (1.25in,11in);
    \node (t) [font=\LARGE, anchor=south] at ($(0,25.56)!1/2!(8.5in,25.56)$) {\thetitle};
    \node (d) [font=\large, anchor=south west, xshift=1.5em] at (0,25.6) {\today};
    \node (p) [font=\large, anchor=south east, xshift=-1.5em] at (8.5in,25.56) {p.~\thepage};
  \end{tikzpicture}%
}}

\titleformat{\section}[display]{\normalfont\large\bfseries}{}{0em}{}

\renewcommand{\rmdefault}{augie}

\title{Notes}
\author{Heather Young}

\begin{document}
\pagestyle{empty}
\doublespacing

\section{Math}
$x = \frac {-b \pm \sqrt{b^2 - 4ac}}{2a}$ the quadratic formula
$0 = ax^2 + bx + c$ mathematics is awesome

\section{Physics}
$\gamma \to e^+ + e^-$

\section{Coding}
Ever heard of LaTeX? No? Well, it's awesome, and it's what this document is written in.

\section{Diagrams + Doodling}

\begin{tikzpicture}
    \draw (0,0) rectangle (4,4);
    \draw (0,0) -- (4,4);
\end{tikzpicture}

\begin{table}[H]
    \begin{tabular}{|l|l|}
        \toprule
        X & Y \\
        \midrule
        0 & 1 \\
        \hline
        3 & 5 \\
        \hline
        4 & 7 \\
        \bottomrule
    \end{tabular}
    \label{tab:my_label}
\end{table}

\end{document}

Which gives the result

enter image description here

There are two main problems with this:

  1. Not all of the text is on a line, and I'm not sure why. I tried to adjust the title format of the section such that it wouldn't throw anything off, but I don't think that helped at all.
  2. Instead of "4" at the top of the page, it should say "Notes" but it doesn't, and again, I'm not sure why.

Any help would be appreciated. Thanks!

Credit for the notebook code goes to cfr in the answer to this question. I am using sharelatex.com.

Edit: I tried removing the graphic and table to see if either of those was the problem, but some of the text was still not on a line.

auden
  • 1,458

1 Answers1

2

this gets a bit closer, keeping tighter control over the various elements to keep to baseline spacing.

enter image description here

\documentclass[letterpaper, 10pt]{article}
\usepackage{tikz, background, titling, setspace,titlesec,booktabs,float}
\usepackage[left=1.5in,right=.25in,top=1.125in,bottom=.125in]{geometry}
\usetikzlibrary{calc}
\makeatletter
\backgroundsetup{%
 position=current page.center,
 angle=0,
 scale=1,
 contents={%
  \begin{tikzpicture}%
    [
      normal lines/.style={gray, very thin},
      every node/.append style={black, align=center, opacity=1}
    ]
    \foreach \y in {0.71,1.41,...,25.56}
      \draw[normal lines] (0,\y) -- (8.5in,\y);
    \draw[normal lines] (1.25in,0) -- (1.25in,11in);
    \node (t) [font=\LARGE, anchor=south] at ($(0,25.56)!1/2!(8.5in,25.56)$) {\@title};
    \node (d) [font=\large, anchor=south west, xshift=1.5em] at (0,25.6) {\today};
    \node (p) [font=\large, anchor=south east, xshift=-1.5em] at (8.5in,25.56) {p.~\thepage};
  \end{tikzpicture}%
}}

\titleformat{\section}[display]{\normalfont\bfseries}{}{0em}{}
\titlespacing{\section}{0pt}{\baselineskip}{\baselineskip}
\setlength\lineskip{0pt}

\renewcommand{\rmdefault}{augie}

\title{Notes}
\author{Heather Young}

\begin{document}
\pagestyle{empty}
\doublespacing

\section{Math}

$\smash{x = \frac {-b \pm \sqrt{b^2 - 4ac}}{2a}}$ the quadratic formula
$0 = ax^2 + bx + c$ mathematics is awesome

\section{Physics}
$\gamma \to e^+ + e^-$

\section{Coding}
Ever heard of LaTeX? No? Well, it's awesome, and it's what this document is written in.

\section{Diagrams + Doodling}

\begin{tikzpicture}
    \draw (0,0) rectangle (4,4);
    \draw (0,0) -- (4,4);
\end{tikzpicture}


    \begin{tabular}[t]{|l|l|}
        \toprule
        X & Y \\
        \midrule
        0 & 1 \\
        \hline
        3 & 5 \\
        \hline
        4 & 7 \\
        \bottomrule
    \end{tabular}


\end{document}
David Carlisle
  • 757,742
  • Thank you, this is perfect! Would you mind explaining what exactly you did? (Sorry, I'm a bit of a newbie with LaTeX.) – auden Aug 15 '16 at 20:14
  • @heather just diff against your original:-) I removed the \large from the section heading so it doesn't force extra space, I used the titlespacing command do force the space before and after to be \baselineskip then I used \smash around the quadratic formula which hides its size (it would over-print text if too big) so it doesn't disturb the space – David Carlisle Aug 15 '16 at 20:15
  • @heather by hand, if adding something big like a tikzpicture or graphic, you can use \vspace{5\baselineskip}\smash{\includegraphics{...} replacing 5 by whatever, that hides the size of what you are adding and forces an exact number of baselines... – David Carlisle Aug 15 '16 at 20:18
  • Oh, okay. Then the main thing is controlling each of the elements such that they use an exact number of lines, using commands such as \smash. That makes a lot of sense. I just thought it had to do with straight-up size, but that doesn't really matter, as long as the element doesn't take up a fractional line. Thanks! – auden Aug 15 '16 at 20:21
  • @heather if what you are adding is less than a baselineskip tex adds space to force baseline spacing, but if you add an over-sized item it doesn't have a built in way to add space to make it a multiple of baselineskip. You can automate it more than I suggest here but the macros get (a lot) more complicated and if you are not automatically trypesetting thousands of documents probably not worth it – David Carlisle Aug 15 '16 at 20:24
  • Nope, not typesetting thousands of documents (or even hundreds). =) Thanks again for all your help! You've explained it very clearly. – auden Aug 15 '16 at 20:25