11

I just came across something I missed a few years ago: I still use notebooks that do not have the correct margins for writing, i.e., the outer and bottom margins are the end of the page and the inner and top ones have been set by default.

Assuming I'm using an A4 paper, I would like to get a template of a sheet that I can tell LaTeX to replicate 'n' times and make myself a beautiful "LaTeX Notebook", which includes the proper margins (perhaps only showing the inner and a light-shaded outer one), lines and page numbers.

I've manage to get the margins going on according to Tschichold's rules (see here) using the geometry package:

\usepackage[textwidth=0.666667\paperwidth,inner=0.111111\paperwidth,textheight=0.666667\paperheight,headheight=15pt,bottom=0.222222\paperheight]{geometry}

Now, how can I set the lines and margins? Again, I'm not trying to get a box as in the showframe option of geometry, but just the inner margin along with a gray one on the outside. What should be the line sizes?

  • Just use picture and commands like \put, \makebox, \line and so on. – Eddy_Em Sep 27 '13 at 19:06
  • I don't have time right this moment to write up a solution here. I've done something similar myself. I use TikZ with absolute positions. The results can be vary nice. If no one has answered this before I get to this later, I'll post example of what I've done myself. – A.Ellett Sep 27 '13 at 19:41
  • perhaps the tikzpagenodes package might be helpful, detailed in, for example, page number in a diamond box – cmhughes Sep 27 '13 at 20:33
9

Now that I've put this together I'm wondering whether it's really what you want.
Nevertheless, here it goes. I've followed @cmhughes 's suggestion to use the tikzpagenodes and plagiarized the header diamond format from page number in a diamond box

\documentclass{book}
\usepackage[%%
  textwidth=\dimexpr2\paperwidth/3\relax,
  inner=\dimexpr\paperwidth/9\relax,
  textheight=\dimexpr2\paperheight/3\relax,
  headheight=15pt,
  bottom=\dimexpr2\paperheight/9\relax,
  a4paper,
  ]{geometry}

\usepackage{tikzpagenodes}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{calc}
\tikzset{light gray lines/.style={line width=0.5pt,gray!20},
         medium gray lines/.style={line width=0.5pt,gray!80},
         dark gray lines/.style={line width=0.5pt,gray},
         header diamond format/.style={diamond,draw,font=\small\itshape,inner sep=0pt,minimum size=1cm},
         heder tail format/.style={double=white}
          } 
\def\aePageDia#1#2#3{%%
  \begin{tikzpicture}[remember picture,
                      overlay,
                      ]
    \node[header diamond format] (dia)  at (current page header area.#1 #2) {\makebox[0pt]{\thepage}};
    \coordinate                  (tail) at (current page header area.#1 #3) ;
    %%
    \draw[dark gray lines]   (dia.south)  -- (current page text area.south #2);
    \draw[light gray lines]  (tail.south) -- (current page text area.south #3);
    \draw[heder tail format] (dia.#3)     -- (tail);
    %%
    \foreach \x in {0,1,...,37} {%%
      \draw[medium gray lines] ($(current page text area.south #3)+(0,\x*0.5cm)$)
                               --
                               ($(current page text area.south #2)+(0,\x*0.5cm)$);
      }

  \end{tikzpicture}%%
}

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand\headrulewidth{0pt}
\fancyhead[OC]{\aePageDia{south}{east}{west}}
\fancyhead[EC]{\aePageDia{south}{west}{east}}
\fancyhead[OR]{\small\nouppercase\leftmark}
\fancyhead[EL]{\small\nouppercase\rightmark}

\usepackage{lipsum}
\begin{document}

\foreach \y in {1,2,...,20} { \makebox{}\clearpage}

\end{document}

enter image description here

This compiles rather slowly, but that's mostly because of all the rules. I'm thinking that a lot of this could be saved in a box and the box reproduced on each page. I'll think about this a bit more.

For the diamond, I set the minimum size=1cm. But that doesn't prevent the node from growing. So, to get around this I put the page number inside a box set to zero width.

Maybe this is what you want. Maybe it's not. Either way, I hope it at least gives you some ideas about how to achieve the effect you desire.

UPDATE

Here is a modified version of the above. It uses lrboxes to save the ruled page. This greatly increases the speed for compiling. Even a 2000 page document doesn't take too long. (Well, for 2000 pages you do have to wait, but 100 or 200 pages are fairly quick.)

I've created a boolean to help control the appearance of the diamond and the positioning of the page numbers. Caveat: this boolean needs to be set before the lrboxes are defined and before the formatting for the header and footers are set.

I've also annoted the example with comments to help you better understand what I'm doing and why. That should help if you want to modify the code to get a different effect.

\documentclass{book}
\usepackage[%%
  textwidth=\dimexpr2\paperwidth/3\relax,
  inner=\dimexpr\paperwidth/9\relax,
  textheight=\dimexpr2\paperheight/3\relax,
  headheight=15pt,
  bottom=\dimexpr2\paperheight/9\relax,
  a4paper
  ]{geometry}

% I've create a boolean to control the presence of the diamond (and subsequently     
% where the page numbers are placed.  If "true", the diamond will be rendered and    
% the page numbers will appear in the diamond.  If "false", the diamond will not     
% be rendered and the page numbers will appear on the bottom of the page.  See       
% the code where I call the booleans to modify this behavior.  Overall, I've tried   
% to divorce the formatting for rules and diamonds from the placement of the diamond.
\newif\ifusediamond
\usediamondfalse
\usediamondtrue

%% load the packages and libraries for creating the notebook pages                   
\usepackage{tikzpagenodes}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{calc}

%% create the styles for the nodes                                                   
\tikzset{my page number format/.style={font=\small\itshape},
         light gray lines/.style={line width=0.5pt,gray!20},
         medium gray lines/.style={line width=0.5pt,gray!80},
         dark gray lines/.style={line width=0.5pt,gray},
         header using a diamond format/.style={diamond,draw,my page number format,inner sep=0pt,minimum size=1cm},
         header without diamond format/.style={inner sep=0pt},
         header tail format/.style={double=white}
          } 

%% set up lengths to set up the environment.  Need these lengths because             
%% everything has to be set up prior to the first page being shipped out.            
%% That is, the ruled page is created before TikZ has any page nodes/coordinates     
%% to work with.                                                                     
\newlength{\myruledpagewidth}
\newlength{\myruledpageheight}
\setlength{\myruledpagewidth}{\textwidth}
\setlength{\myruledpageheight}{\textheight}

%% Here's the primary macro which generates the actual ruled paper.                  
%% It takes two argument which are directions: {east}{west} or {west}{east}          
\def\aeRuledPage#1#2{%%
  \begin{tikzpicture}
    \coordinate                  (my top west)     at (0,0);
    \coordinate                  (my top east)    at (\textwidth,0);
    \coordinate                  (my bottom west)  at (0,-\myruledpageheight);
    \coordinate                  (my bottom east) at (\textwidth,-\myruledpageheight);

    %% by setting the bounding box, it'll be easier to place the ruled page
    %% later and not worry about things (like possibly the diamond) which  
    %% would change the dimensions of the bounding box.                    
    \path[use as bounding box] (my top west) rectangle (my bottom east);

    %% The following two lines control how the "dia" node is rendered.     
    \ifusediamond
      \node[header using a diamond format] (dia)  at (my top #1) {};
    \else
      \node[header without diamond format] (dia)  at (my top #1) {};
    \fi
    \coordinate                  (tail) at (my top #2);

    %% The following lines will respect your decision about how the
    %% diamond is rendered (if at all)                             
    \draw[dark gray lines]    (dia.south)  -- (my bottom #1);
    \draw[light gray lines]   (tail.south) -- (my bottom #2);
    \draw[header tail format] (dia.#2)     -- (tail);

    \foreach \x in {0,1,...,36} {%%
      \draw[medium gray lines] ($(my bottom east)+(0,\x*0.5cm)$)
                               --
                               ($(my bottom west)+(0,\x*0.5cm)$);
    }
  \end{tikzpicture}%%
}

%% Here I set up the boxes that will greatly increase the speed for                  
%% compiling this document.                                                          
\makeatletter
\def\ae@ruled@page#1#2{\aeRuledPage{#1}{#2}}

\newsavebox{\ruledpage@south@east}
\begin{lrbox}{\ruledpage@south@east}
  \ae@ruled@page{west}{east}%%
\end{lrbox}

\newsavebox{\ruledpage@south@west}
\begin{lrbox}{\ruledpage@south@west}
  \ae@ruled@page{east}{west}%%
\end{lrbox}

%% I've created separate macro for the ruled page and the page numbering             
%% to make it a bit easier to change either without effecting the other.             
\def\aePlaceRuledPage#1#2{%
  \begin{tikzpicture}[remember picture,overlay]
    \node[anchor=north #2,inner sep=0pt] at (current page header area.#1 #2) { \usebox{\csname ruledpage@#1@#2\endcsname}};
  \end{tikzpicture}}

\def\aePlacePageNumber#1{%%
  \begin{tikzpicture}[remember picture,overlay]
    \ifusediamond
      \node[my page number format] at (current page header area.#1) {\thepage};
    \else
      \node[my page number format] at (current page text area.#1) {\thepage};
    \fi
  \end{tikzpicture}}

\makeatother

%% Setting up the header and footers                                                 
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand\headrulewidth{0pt}
\fancyhead[OC]{\aePlaceRuledPage{south}{west}}
\fancyhead[EC]{\aePlaceRuledPage{south}{east}}

%% These next three lines control the position of the page number        
\ifusediamond
  %% page number on either the left or right hand side of the top        
  \fancyhead[OL]{\aePlacePageNumber{south east}}
  \fancyhead[ER]{\aePlacePageNumber{south west}}
\else
  %% page number in the bottom, centered                                 
  \fancyfoot[C]{\aePlacePageNumber{south}}
\fi

\usepackage{lipsum}
\begin{document}

  \foreach \y in {1,2,...,100} { \makebox{}\clearpage}

\end{document}
  • This looks great! What about speeding the compilation? Is there any way to improve it? What change do I need if I wanted, lets say, the page number at the bottom center instead of the diamond? – Mario S. E. Sep 28 '13 at 10:49
  • @MarioS.E. I've updated the answer to something that is much quicker. I've also shown how you can make some changes for the placement of the page numbers. – A.Ellett Sep 28 '13 at 16:23
  • @A.Ellett Very nice answer and example. Unfortunately isn't clear (at least for me) how to deactivate the diamond with the number. In the other hand, how do you define the number of lines in the pages, how you could create an squared notebook? – Aradnix Dec 16 '15 at 0:41
2

Here is simple example: I use this to make a GOST-style frames around text. You can modify it like you want.

\textwidth=175mm
\textheight=260mm
\oddsidemargin=-.4mm
\headsep=5mm

\topmargin=-1in
\unitlength=1mm

\def\VL{\line(0,1){15}}
\def\HL{\line(1,0){185}}
\def\Box#1#2{\makebox(#1,5){#2}}
\def\simpleGrad{\sl\small\noindent\hbox to 0pt{%
\vbox to 0pt{%
\noindent\begin{picture}(185,287)(5,0)
\linethickness{0.3mm}
\put(0,0){\framebox(185,287){}}
\put(0,0){\Box{7}{Лит.}}
\put(0, 15)\HL
\multiput(0, 5)(0, 5){2}{\line(1,0){65}}
\put(7, 0){\VL\Box{10}{Изм.}}
\put(17, 0){\VL\Box{23}{\No~докум.}}
\put(40, 0){\VL\Box{15}{Подп.}}
\put(55, 0){\VL\Box{10}{Дата}}
\put(65, 0){\VL\makebox(110,15){\large\sc\rightmark}}
\put(175, 0){\VL\makebox(10,10){\normalsize\thepage}}
\put(175,10){\line(1,0){10}}
\end{picture}
}}}

\makeatletter
\def\@oddhead{\simpleGrad}
\def\@oddfoot{}
\makeatother

Frame is in header of document.

  • Could you please post a figure of the outcome for everybody to see? – Mario S. E. Sep 28 '13 at 10:40
  • look – Eddy_Em Sep 28 '13 at 20:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.