0

I am working a new document class for my personal use. So I am writing a command to generate a title page. I have several issues (this code doesn't produce any errors) :

  • First issue : I want to delete the header Contents but I can't use :
\makeatletter
\@starttoc{toc}
\makeatother

Since the command is embedded in a \newcommand statement. It raises errors if I try to use it. I tried the different solutions I found here: How to hide the table of content's heading? and https://latex.org/forum/viewtopic.php?t=8151. None of them worked. EDIT: This issue is solved. I need to redefine \contentsname after \begin{document}.

  • Second issue : If I set a pagecolor when calling the function, the setting is not taken into account and the page remains white.

Here is the full code of the MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{lipsum}
% Packages used in this command :
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usepackage[object=vectorian]{pgfornament}
\usepackage{xcolor}
\usepackage{pagecolor}
\usepackage[paperheight=21cm,paperwidth=14.85cm,textheight=16cm,textwidth=13.85cm,inner=0.5cm,outer=0.5cm,top=2cm,twoside,showframe,verbose]{geometry}

\newcommand{\myTitlepage}[4]{ \pagenumbering{gobble} % No page number on this titlepage \thispagestyle{empty} \newpagecolor{#4} % Changing page color \newgeometry{paperheight=21cm,paperwidth=14.85cm,top=2cm,left=1cm,right=1cm,bottom=0.5cm} \begin{titlepage} \begin{center} \large #3 -- \today\[2cm] % Title {\begin{minipage}\linewidth \centering \vskip10pt \resizebox{\textwidth}{!}{#1}\[1cm] \pgfornament[width=0.5\textwidth]{68} \vskip6pt \end{minipage}} \vskip10pt \large #2\ \vspace{1cm} \begin{tcolorbox}[ breakable,enhanced,title={Table des matières}, colframe=black,colback=white,colbacktitle=white, fonttitle=\bfseries,coltitle=black,attach boxed title to top center= {yshift=-0.25mm-\tcboxedtitleheight/2,yshifttext=2mm-\tcboxedtitleheight/2}, boxed title style={boxrule=0.5mm, frame code={ \path[tcb fill frame] ([xshift=-4mm]frame.west) -- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east) -- (frame.south east) -- (frame.south west) -- cycle; }, interior code={ \path[tcb fill interior] ([xshift=-2mm]interior.west) -- (interior.north west) -- (interior.north east) -- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west) -- cycle;} }] % TOC display \tableofcontents \end{tcolorbox} \vfill \end{center} \restorepagecolor \end{titlepage} } \begin{document} \myTitlepage{A Title}{An Author (me)}{Header}{yellow!25!white} \section{A section} \lipsum[1] \end{document}

How can I solve those two issues please ?

Bernard
  • 271,350
Elyo
  • 386

1 Answers1

1

Just move the \restorepagecolor after \end{titlepage} (restore the color after the page was shipped out, not before!).

No need to change \contentsname, to use \@starttoc place \makeatletter and \makeatother around the entire definition of \myTitlepage. The category codes in TeX depend on the time when the input was first tokenized (so during the definition) and changing them later doesn't affect the definition of already tokenized things.

Also your code was missing a \restoregeometry after the title page. Inside \newgeometry you can't use paperheight and paperwidth. Using \pagenumbering{gobble} isn't necessary, just using \thispagestyle{empty} would suffice so that no page numbers will be shown, but (at least with article) this is unnecessary as the titlepage environment already does this for you. Also, inside another environment I'd use \centering instead of center (not an issue here, but often center adds unwanted vertical space if nested in the "wrong" environment, like e.g. floats).

Using \resizebox to typeset your title is a bad idea (what happens if your title gets too long?), instead I'd measure the size of your heading with \Huge and if it's too large for a single row I'd not scale, else we still can use \resizebox if you want.

Also, I've changed your numerous \vskip to \vspace and introduced a few \pars instead of \\ or other forms of linebreaking, removed the unnecessary nested minipage for your title, and I used \contentsname for your table of contents.

And additional to all those changes, I also reindented your code and changed the way you use the key=value interfaces (just to match my liking, but imho this makes the code easier to read and maintain).

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{lipsum}
% Packages used in this command :
\usepackage[most]{tcolorbox}
\usepackage[object=vectorian]{pgfornament}
\usepackage{xcolor}
\usepackage{pagecolor}
\usepackage
  [
     paperheight=21cm
    ,paperwidth=14.85cm
    ,textheight=16cm
    ,textwidth=13.85cm
    ,inner=0.5cm
    ,outer=0.5cm
    ,top=2cm
    ,twoside
    ,showframe
    ,verbose
  ]
  {geometry}

\makeatletter \newcommand{\myTitlepage}[4] {% \newpagecolor{#4}% Changing page color \newgeometry{top=2cm,left=1cm,right=1cm,bottom=0.5cm}% \begin{titlepage}% \centering \large #3 -- \today\par % Title \vspace{2cm}% \begingroup \Huge \sbox0{#1}% \ifdim\wd0>\linewidth \unhbox0 \else \resizebox{\linewidth}{!}{\usebox0}% \fi \par \endgroup \vspace{1cm}% \pgfornament[width=0.5\textwidth]{68}\par \vspace{16pt}% #2\par \vspace{1cm}% \begin{tcolorbox} [ breakable ,enhanced ,title=\contentsname ,colframe=black ,colback=white ,colbacktitle=white ,fonttitle=\bfseries ,coltitle=black ,attach boxed title to top center= {% yshift=-0.25mm-\tcboxedtitleheight/2 ,yshifttext=2mm-\tcboxedtitleheight/2 } ,boxed title style= {% boxrule=0.5mm ,frame code= {% \path[tcb fill frame] ([xshift=-4mm]frame.west) -- (frame.north west) -- (frame.north east) -- ([xshift=4mm]frame.east) -- (frame.south east) -- (frame.south west) -- cycle;% } ,interior code= {% \path[tcb fill interior] ([xshift=-2mm]interior.west) -- (interior.north west) -- (interior.north east) -- ([xshift=2mm]interior.east) -- (interior.south east) -- (interior.south west) -- cycle;% }% }% ]% % TOC display @starttoc{toc}% \end{tcolorbox}% \vfill \end{titlepage}% \restorepagecolor \restoregeometry } \makeatother

\usepackage{duckuments}% <- just for dummy contents

\begin{document} \myTitlepage{A really long Title that is too long to fit in a single line so creates issues}{An Author (me)}{Header}{yellow!25!white}

% dummy contents \duckument \duckument \end{document}

enter image description here

Skillmon
  • 60,462
  • Thank you for improving this solution. Removing the header by changing the associated command created an undesired space when I did it this way. – Elyo Dec 30 '21 at 13:31
  • @Elyo well, that would typeset an empty section heading, so naturally leads to a lot of extra space. – Skillmon Dec 30 '21 at 13:58