2

I would like to create a package (.sty) for a titlepage. I followed this guide https://en.wikibooks.org/wiki/LaTeX/Title_Creation from which I took the following two codes: the first code is the package called columbidaeTitle.sty, the second code is the document where the package, earlier created, is loaded.

columbidaeTitle.sty

% Copyright note: This package defines how titles should
% be typeset at the columbidae University
% Please check for updates
\ProvidesPackage{columbidaeTitle}[2015/08/10 v.01 an
example package^^J for wikibooks]
\RequirePackage{graphicx}
\newcommand*{\project}[1]{\gdef\@project{#1}%
}
\newcommand*{\@project}{Final Year Project}
\newcommand*{\supervisor}[1]{\gdef\@supervisor{#1}%
}
\newcommand*{\@supervisor}{\texttt{\string\supervisor} currently
not set. Please fix this.}
\renewcommand*{\maketitle}{%
\begin{titlepage}
{\raggedleft%
    \includegraphics[width=3cm]{example-image-16x9}\par
}\vspace{1cm}
    \centering
{\scshape\LARGE Columbidae University \par}
\vspace{1cm}
{\scshape\Large\@project\unskip\strut\par}
\vspace{1.5cm}
{\huge\bfseries\@title\unskip\strut\par}
\vspace{2cm}
{\Large\itshape\@author\unskip\strut\par}
\vfill
supervised by\par
\@supervisor\unskip\strut\par

\vfill

{\large \@date\par}
\end{titlepage}
}
\endinput

Document:

\documentclass{book}
\usepackage{columbidaeTitle}
\supervisor{Dr. James Miller}
\project{Bachelor Thesis}
\author{A LaTeX enthusiast}
\title{Why i want to be a duck}

\begin{document}
\maketitle
\tableofcontents
\chapter{Ducks are awesome}
\end{document}

I have an issue. I would like the whole document to have this margin:

\usepackage[bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm]{geometry}

except for the titlepage, for which I would like to have

\newgeometry{left=3cm,right=3cm,bottom=2cm,top=3cm}

I tried to insert \RequirePackage{geometry} in the columbidaeTitle.sty file and then

\newgeometry{left=3cm,right=3cm,bottom=2cm,top=3cm}
\begin{titlepage}
...
\end{titlepage}
\restoregeometry

but it didn't work. How can I make?

Marco
  • 1,373
  • try \begin{titlepage}\newgeometry{left=3cm,right=3cm,bottom=2cm,top=3cm} ... \restoregeometry \end{titlepage} – touhami Jan 11 '16 at 17:39
  • But since the titlepage is quite static, you can use an extra document and just include the pdf as stated in .... well, it was somewhere. Isn't that written on that wiki page? – Johannes_B Jan 11 '16 at 17:49
  • By the way, packing up a new package is only a good idea, if you have a standard page and you want to save your colleagues some time. Else, c.f. How to customize my titlepage? – Johannes_B Jan 11 '16 at 17:50
  • This is my first time trying to create (copy and paste it truthfully) a simple package. I would not like to create it inside the document but I wish to create this package. Anyway: I tried \RequirePackage{geometry}, then \begin{titlepage}\newgeometry{left=3cm,right=3cm,bottom=2cm,top=3cm} ... \restoregeometry \end{titlepage} and in document .tex I inserted \usepackage[bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm]{geometry} but I get an error: ! LaTeX Error: Option clash for package geometry. – Marco Jan 11 '16 at 18:04
  • 1
    Yes of course, you cannot load the document with different options. Use \geometry{bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm} – Johannes_B Jan 11 '16 at 18:07
  • I have to say that your bindingoffset is quite large, and that omitting it on the title seems to be more than strange to me. The title will be moved strange into the left margin. Do you want that? – Johannes_B Jan 11 '16 at 18:08
  • I inserted \usepackage[bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm]{geometry} in the .sty file and only \usepackage{geometry} in the .tex file. Now I do not get any error. Is it correct? I am going to think about what you said about the binding offset. – Marco Jan 11 '16 at 18:14
  • I did not read your comment well: are you saying to put in the .tex file \usepackage{geometry} \geometry{bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm} and in .sty file just \usepackage{geometry}? – Marco Jan 11 '16 at 18:21
  • Do \@ifpackageloaded{geometry}{}{\RequirePackage[pass]{geometry}}. If geometry has already been loaded, OK, otherwise, load it so it doesn't harm the page parameters, but you'll have \newgeometry available. – egreg Jan 11 '16 at 18:40
  • Putting that line into the package really only makes sense, if the package is used by more than one author. – Johannes_B Jan 11 '16 at 18:43
  • I got lost. Putting \RequirePackage{geometry}\geometry{bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm} in the .sty file and \usepackage{geometry} in the .tex file works. Putting \usepackage{geometry} in the .sty file and \usepackage{geometry} \geometry{bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm} in the .tex file also works. I did not understand how to make the egreg's solution works. – Marco Jan 11 '16 at 18:51
  • Marco, does your titlepage change every two days? If not, and this is just for you, set up a new document with your current preamble and save the title as one single pdf which you include in your document. – Johannes_B Jan 11 '16 at 19:07
  • By this point, even if I think I will include the titlepage as you suggested, I would like to understand how to solve it. Particularly, could you tell me: even if these two following solutions do not give me errors when compiling, are they both correct? \RequirePackage{geometry}\geometry{bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm} in the .sty file and \usepackage{geometry} in the .tex file works. \usepackage{geometry} in the .sty file and \usepackage{geometry} \geometry{bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm} in the .tex file works. – Marco Jan 11 '16 at 20:00
  • You can load the package just once with a specific option set. Having a package makes sense if used by many, as i said multiple times. That also means, the geometry for the titlepage is fixed by the author of the package (right now, that is you). You as the author wants to use apckage geometry to set the margins on the titlepage. Now egreg's line drops in: Test if the package is already loaded, if so, ddon't do anything. If not, load package geometry without changing the default margins (pass) because that would change the rest of the document. \newgeometry can be used savely. – Johannes_B Jan 11 '16 at 20:11
  • Now suppose, geometry wasn't already loaded at load time of the bird package ... It will be afterwards. If your normal preamble now tries to load geometry with a specific set of options, you will get the option clash you mentioned earlier. You now have to use \geometry{bottom=2cm}. – Johannes_B Jan 11 '16 at 20:11
  • Or in other words, as a package author you have to be aware of the crazy things the package user comes up with, trying to think a few steps ahead. Like chess. As a normal user, needing this just once, you should not bend your mind three steps ahead to understand a problem that shouldn't exist in the first place. – Johannes_B Jan 11 '16 at 20:11
  • I would like now to set the package as it was used by other users. I can't figure out how to make the egreg's solutions works. – Marco Jan 12 '16 at 09:40
  • Put that line into the package file before setting up the titlepage. – Johannes_B Jan 13 '16 at 18:00
  • The wikibook pages tates that providing a titlepage as a package is something for experienced users. Sorry, please don't get me wrong, but ... I don't think you have the needed experience yet to provide something other people rely on. – Johannes_B Jan 13 '16 at 18:01
  • Is there any news here? – Johannes_B Jan 16 '16 at 07:46
  • I would have liked to create this titlepage as if somebody, besides me, had to use it, but not for real. Just for fun, to learn something new. However, I have not tried to use that line. I think it will be tough (for me, as I do not have experience) to make it works. – Marco Jan 16 '16 at 11:18

1 Answers1

4

Just load geometry conditionally. Of course the documentation should make it clear that the package must be loaded after geometry, if this package is used. A test for this could be added.

columbidaeTitle.sty

% Copyright note: This package defines how titles should
% be typeset at the columbidae University
% Please check for updates

\ProvidesPackage{columbidaeTitle}[2015/08/10 v.01 an example package^^J for wikibooks]
\RequirePackage{graphicx}

\@ifpackageloaded{geometry}{}{\RequirePackage[pass]{geometry}}

\newcommand*{\project}[1]{\gdef\@project{#1}}
\newcommand*{\@project}{Final Year Project}
\newcommand*{\supervisor}[1]{\gdef\@supervisor{#1}}
\newcommand*{\@supervisor}{\texttt{\string\supervisor} currently not set. Please fix this.}
\renewcommand*{\maketitle}{%
  \begin{titlepage}
  \newgeometry{left=3cm,right=3cm,bottom=2cm,top=3cm}
  {\raggedleft\includegraphics[width=3cm]{example-image-16x9}\par}
  \vspace{1cm}
  \centering
  {\scshape\LARGE Columbidae University \par}
  \vspace{1cm}
  {\scshape\Large\@project\unskip\strut\par}
  \vspace{1.5cm}
  {\huge\bfseries\@title\unskip\strut\par}
  \vspace{2cm}
  {\Large\itshape\@author\unskip\strut\par}
  \vfill
  supervised by\par
  \@supervisor\unskip\strut\par
  \vfill
  {\large \@date\par}
  \end{titlepage}
}
\endinput

test.tex

\documentclass{book}

\usepackage[bindingoffset=1.5cm, left=3cm, right=3cm, top=3cm, bottom=3cm,showframe]{geometry}

\usepackage{columbidaeTitle}
\supervisor{Dr. James Miller}
\project{Bachelor Thesis}
\author{A LaTeX enthusiast}
\title{Why i want to be a duck}

\begin{document}
\maketitle
\tableofcontents
\chapter{Ducks are awesome}
\end{document}

Output

enter image description here

Output if the call of geometry in test.tex is removed

enter image description here

egreg
  • 1,121,712