Skip to content

Instantly share code, notes, and snippets.

@brabect1
Created January 28, 2024 20:06
Show Gist options
  • Save brabect1/cbbe24d720f3411906f4e5aebf1171eb to your computer and use it in GitHub Desktop.
Save brabect1/cbbe24d720f3411906f4e5aebf1171eb to your computer and use it in GitHub Desktop.
Custom cover page with LaTeX memoir class.

Custom Coverpage with LaTeX memoir

Example showing use of custom cover page with memoir class of article class option. There are some few "tricks" to yield the desired effect.

% Copyright 2024 Tomas Brabec
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%
\documentclass[10pt,a4paper,article,oneside]{memoir}
\usepackage{helvet}
\usepackage{amssymb,amsmath}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\usepackage{xcolor}
\usepackage{lastpage}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
pdftitle={csip\_65ldotp\_ctrl Documentation},
%% hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[margin=2cm]{geometry}
\usepackage{longtable,booktabs}
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\usepackage{graphicx}
\usepackage{mwe}
% custom style package
\usepackage{mypackage}
% ==========================================
% begin: Template setup
% ==========================================
% IP version to be displayed
\docversion{X.Y.Z}
%
% Datasheet title (normally the IP library name)
\title{My Title}
%
% Datasheet sub-title (normally the IP library descriptive name)
\subtitle{subtitle}
%
% Author name (not used)
\author{The Author}
%
% coverpage logo path
\logoimg{../../doc/img/other/onsemi_logo_final_v5_t_full_color.png}
%
% extra customization through following commands
% ----------------------------------------------
% %% % redefine default font style
% %% \renewcommand{\familydefault}{\sfdefault}
%
% %% % redefine revision prefix
% %% \renewcommand{\revprefix}{v}
%
% end: Template setup
% ==========================================
\begin{document}
% cover page/title
\frontmatter
% legal notice and TOC
\mainmatter
\chapter{First section}
\lipsum[1-10]
\chapter{Second section}
\lipsum[1-9]
\backmatter
\end{document}
% Copyright 2024 Tomas Brabec
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{mypackage}
[2024/01/28 v0.01 LaTeX package]
%\RequirePackage{whatever}
% load the font
\renewcommand{\familydefault}{\sfdefault}
% colors
\definecolor{grayM}{HTML}{B6B6B6}
\definecolor{whiteM}{HTML}{FFFFFF}
\definecolor{blackM}{HTML}{000000}
\newcommand{\mymonth}{%
\ifcase\month% 0
\or Jan% 1
\or Feb% 2
\or Mar% 3
\or Apr% 4
\or May% 5
\or Jun% 6
\or Jul% 7
\or Aug% 8
\or Sep% 9
\or Oct% 10
\or Nov% 11
\or Dec% 12
\fi}
\newcommand{\myyear}{\number\year}
\newcommand{\monthyeardate}{\mymonth-\myyear}
\DeclareRobustCommand\subtitle[1]{\gdef\@subtitle{#1}}
\DeclareRobustCommand\docversion[1]{\gdef\@docversion{#1}}
\DeclareRobustCommand\logoimg[1]{\gdef\@logoimg{#1}}
\newcommand{\revprefix}{rev.~}
%\IfClassLoadedTF{memoir}{%
\@ifclassloaded{memoir}{%
% memoir class: override front/main/back matters
\renewcommand{\frontmatter}{%
\thispagestyle{mytitlepage}%
\datasheettitle%
\clearpage%
}%
\renewcommand{\mainmatter}{%
\pagestyle{mytitlepage}%
% TOC/table of contents
\tableofcontents*%
\clearpage%
\pagestyle{mycustompage}%
}%
\renewcommand{\backmatter}{}%
%
% memoir class: page style for mainmatter pages
\makepagestyle{mycustompage}
%\makeatletter
% Make \leftmark display only the chapter name
% CC-BY-SA 3.0, https://tex.stackexchange.com/a/349398
% (for related topic see https://tex.stackexchange.com/a/127636)
\renewcommand\chaptermark[1]{\markboth{#1}{}}%
\makeheadfootruleprefix{mycustompage}{\color{grayM}}{\color{grayM}}
\makeheadrule {mycustompage}{\textwidth}{0.4pt}
\makefootrule {mycustompage}{\textwidth}{0.4pt}{\footruleskip}
\makeevenhead{mycustompage}{\textsf{\@title}}{}{\textsf{\leftmark}}
\makeoddhead{mycustompage}{\textsf{\@title}}{}{\textsf{\leftmark}}
\makeevenfoot{mycustompage}{\revprefix\@docversion}{\thepage}{}
\makeoddfoot{mycustompage}{}{Page \thepage\ of \pageref*{LastPage}}{\revprefix\@docversion}
%\makeatother
%
% memoir class: page style for frontmatter pages
\makepagestyle{mytitlepage}
\makeheadfootruleprefix{mytitlepage}{\color{grayM}}{\color{grayM}}
\makefootrule {mytitlepage}{\textwidth}{0.4pt}{\footruleskip}
\makeevenhead{mytitlepage}{}{}{}
\makeoddhead{mytitlepage}{}{}{}
\makeevenfoot{mytitlepage}{\oncopyright}{}{}
\makeoddfoot{mytitlepage}{\oncopyright}{}{}
%
% memoir class: override the `plain` style to enforce a mainmatter page style on TOC
\copypagestyle{plain}{mycustompage}
%
% memoir class: custom title to be used instead of \maketitle
%---->>>> CC-BY-SA 3.0, https://tex.stackexchange.com/a/122139
\newlength\drop
\makeatletter
\newcommand*\datasheettitle{\begingroup% Misericords, T&H p 153
\setlength\drop{0.08\textheight}
\centering
\hfill\textcolor{grayM}{\textbf{\revprefix\@docversion, \monthyeardate}}
\vspace*{\drop}
\vspace{0.75in}
\includegraphics[width=1.0\textwidth]{\@logoimg}\par\vspace{1cm}%
\vspace{0.5in}
{\Huge\textcolor{grayM}{\textbf{\@title}}}\\[\baselineskip]
{\huge\textcolor{grayM}{\@subtitle}}\\[\baselineskip]
\vfill
\vspace*{2\drop}
\endgroup}
\makeatother
%<<<<----
}{}%
\endinput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment