[Tex/LaTex] How to create a decoration that runs down one side of each page

ebookmarginsmemoir

Hi I'm writing an ebook in org-mode that includes a separate .tex file for styles. What I'd like to do is create a box that contains the current chapter and section name on a background image that runs down the left hand side of each page. This side bar should be on each page except the title page, table of contents pages and the first page of a new chapter.

At the moment I'm using memoir and I'm guessing that this might have something to do with makechapterstyle. However last week was the first time I ever looked at LaTeX so I'm a bit lost! I'd really appreciate some insight into how one would think about solving this with LaTeX, rather than a canned solution – although, obviously I'd appreciate that too 🙂

On side note – searching for "latex wallpaper" gets some interesting, but not particularly relevant images!

Edit based on Christian's comments

I'm writing a pdf ebook and I'm using the oneside option to memoir. What I want is a thin (1cm or so) image running down the left hand side of every non title page with the name of the section rotated 90Ëš overlaid. The title pages will have a slightly wider image and a little bit of blurb. Here's a screenshot of my inspiration:

Side Projects book

Best Answer

Here is a start (some work still left to do):

This uses the background package (which internally usues tikz) to draw the required frame:

enter image description here

A few variables can be tweaked as desired (all distances are in cm):

  • \FrameXStart is horizontal distance from edge of page to outer edge of frame
  • \FrameXEnd is horizontal distance from edge of page to inner edge of frame
  • \FrameYClip is vertical distance from edge of page to top/bottom of the frame
  • \FrameTextShift is vertical distance of the text from the top edge of page
  • \PageNumberLocation is vertical distance from bottom of page to page number

Notes:

  • Two compile runs are required, the first to obtain the coordinates, the second to do the actual drawing.

References:

Further Enhancements:

  • This will appear on every page so need checks for detect:
    1. title page,
    2. table of contents pages, and
    3. the first page of a new chapter.

Code

\documentclass[12pt]{memoir}
\usepackage[all]{background}

\usepackage{lipsum}
\usepackage{showframe}
\usepackage{tikz}
\usetikzlibrary{calc}

%% Customization:
\newcommand*{\FrameXStart}{0.0}% in cm
\newcommand*{\FrameXEnd}{2.0}% in cm
\newcommand*{\FrameYClip}{0.0}% shift in cm of the frame, both from top and bottom
\newcommand*{\FrameTextShift}{-1.5}% shift in cm from the top
\newcommand*{\PageNumberLocation}{4.5}% in cm, from bottom


%-------------
% Need to store the name of the chapter and section. This might be able   
% to be simplified but the simplification might be class dependent.

\newcommand*{\ChapterName}{}%
\newcommand*{\OldChapter}{}%
\let\OldChapter\chapter
\def\chapter#1{\def\ChapterName{#1}\OldChapter{#1}}%

\newcommand*{\SectionName}{}%
\newcommand*{\OldSection}{}%
\let\OldSection\section
\def\section#1{\def\SectionName{#1}\OldSection{#1}}%

\newcommand*{\FrameTitle}{\ChapterName: \SectionName}%


% Style for frame
\tikzset{Frame Style/.style={fill=blue, draw=none, fill opacity=0.5, shade, top color=blue, bottom color=green}}
\tikzset{Title Style/.style={scale=2.75, text=white, rotate=-90, anchor=west}}
\tikzset{Title Top Shift/.style={xshift=\Midpoint cm, yshift=\FrameTextShift cm}}
\tikzset{Title Bottom Shift/.style={xshift=-\Midpoint cm, yshift=\FrameTextShift cm}}

% Style for page numbers in frame
\tikzset{Page Number Style/.style={scale=2.0, text=white, draw=none}}
\tikzset{Page Number Odd Shift/.style={ xshift= \Midpoint cm, yshift=\PageNumberLocation cm}}
\tikzset{Page Number Even Shift/.style={xshift=-\Midpoint cm, yshift=\PageNumberLocation cm}}

\pgfmathsetmacro{\Midpoint}{0.5*(\FrameXStart+\FrameXEnd)}
\newcommand{\MyGraphicLogo}{% For imported graphic logo
\begin{tikzpicture}[remember picture,overlay]
\checkoddpage
\ifoddpage
    \draw [Frame Style] 
            ($(current page.north west)+(\FrameXStart cm,-\FrameYClip cm)$) rectangle
            ($(current page.south west)+(\FrameXEnd   cm, \FrameYClip cm)$);
    \node [Title Top Shift, Title Style] at (current page.north west) {\FrameTitle};
    \node [Page Number Odd Shift, Page Number Style] at (current page.south west) {\thepage};
\else
    \draw [Frame Style] 
        ($(current page.north east)+(-\FrameXStart cm,-\FrameYClip cm)$) rectangle
        ($(current page.south east)+(-\FrameXEnd   cm, \FrameYClip cm)$);
    \node [Title Bottom Shift, Title Style] at (current page.north east) {\FrameTitle};
    \node [Page Number Even Shift, Page Number Style] at (current page.south east) {\thepage};
\fi 
\end{tikzpicture}
}

\SetBgContents{\MyGraphicLogo}% Select frame to be drawn

%\SetBgPosition{current page.north west}% Select location
\SetBgOpacity{1.0}% Select opacity
\SetBgAngle{0.0}% Select roation of logo
\SetBgScale{1.0}% Select scale factor of logo

\begin{document}
\chapter{Chapter Title}
\section{Section Title 1}
\lipsum[1-6]
\section{Section Title 2}
\lipsum[2-9]
\end{document}
Related Question