0

So, I'm trying to recreate the following style of TOC.

enter image description here

I used the following:

{\tikz[remember picture,overlay] 
\draw [fill,red!20] (current page.north west) rectangle
 +(0.33\paperwidth,-\paperheight);
\tableofcontents}

which I found in this answer. It works OK, but I get only the one page of the TOC filled with color. The second and final page of the TOC is left intact. So, how can I succeed in getting the rectangle produced by tikz to match the two pages of my toc?

Here, is an MWE

\documentclass[12pt, a4paper, twoside, openany]{memoir}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{polyglossia}
\usepackage{xltxtra}
\usepackage{fontspec}
\setmainfont{GFS Didot}
\setdefaultlanguage{greek}
\usepackage{tikz}

\begin{document}
    
    {\tikz[remember picture,overlay] 
        \draw [fill,red!20] (current page.north west) rectangle
        +(0.20\paperwidth,-\paperheight);
        \tableofcontents}
    
    \chapter*{Πρόλογος}
    \addcontentsline{toc}{chapter}{Αντί Προλόγου}
    
    \chapter*{Οδηγός Μελέτης}
    \addcontentsline{toc}{chapter}{Οδηγός Μελέτης}
    
    \part{ΑΛΓΕΒΡΑ}
    
    \chapter{Αλγεβρικές Παραστάσεις}
    
    \section{Πραγματικοί αριθμοί και πράξεις}
    
    \section{Δυνάμεις πραγματικών αριθμών}
    
    \section{Τετραγωνική ρίζα πραγματικού αριθμού}
    
    \section{Μονώνυμα $\bullet$ Πολυώνυμα}
    
    \chapter{Ταυτότητες $-$ Παραγοντοποίηση}
    
    \section{Αξιοσημείωτες ταυτότητες}
    
    \section{Παραγοντοποίηση}
    
    \section{Ε.Κ.Π $\bullet$ Μ.Κ.Δ αλγεβρικών παραστάσεων}
    
    \section{Ρητές αλγεβρικές παραστάσεις}
    
    \section{Πρόσθεση $\bullet$ Αφαίρεση ρητών παραστάσεων}
    
    \chapter{Εξισώσεις - Ανισώσεις}
    
    \section{Η εξίσωση $\alpha x + \beta = 0 $}
    
    \section{Εξίσωση δευτέρου βαθμού}
    
    \section{Επίλυση εξίσωσης δεύτερου βαθμού με τύπο}
    
    \section{Κλασματικές εξισώσεις}
    
    \section{Διάταξη}
    
    \chapter{Συστήματα γραμμικών εξισώσεων}
    
    \section{Η έννοια της γραμμικής εξίσωσης}
    
    \section{Γραμμικό σύστημα}
    
    \part{ΓΕΩΜΕΤΡΙΑ $-$ ΤΡΙΓΩΝΟΜΕΤΡΙΑ}
    
    \chapter{Γεωμετρία}
    
    \section{Πρωτεύοντα - Δευτερεύοντα στοιχεία τριγώνου}
    
    \section{Ίσα τρίγωνα}
    
    
    
\end{document}
5
  • If you want people to help you need to provide a full but minimal example others can copy and test as is.
    – daleif
    Commented May 25, 2023 at 14:41
  • Sure, hold on!!
    – Tolaso
    Commented May 25, 2023 at 14:52
  • @daleif I think the MWE added demonstrates the problem.
    – Tolaso
    Commented May 25, 2023 at 15:00
  • Unrelated: what is up with ΓΕΩΜΕΤΡΙΑ $-$ ΤΡΙΓΩΝΟΜΕΤΡΙΑ? the $-$ part? Doesn't get have access to --?
    – daleif
    Commented May 25, 2023 at 15:17
  • I just ported it from an older .tex file I had ages ago.
    – Tolaso
    Commented May 25, 2023 at 17:41

1 Answer 1

1

Probably not the most effecient method, but it does work with my TeXLive 2023 and the hook mechanisms

\documentclass[12pt, a4paper, twoside, openany]{memoir}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{polyglossia}
\usepackage{xltxtra}
\usepackage{fontspec}
\setmainfont{GFS Didot}
\setdefaultlanguage{greek}
\usepackage{tikz}

\cftinsertcode{pre-toc}{
  \AddToHook{shipout/background}[toc-bg]{%
    \tikz[remember picture,overlay] 
    \draw [fill,red!20] (current page.north west) rectangle
    +(0.20\paperwidth,-\paperheight);
  }
}

\cftinsertcode{post-toc}{
  \AddToHookNext{shipout/background}{
    \RemoveFromHook{shipout/background}[toc-bg]
  }
}

% add a hookline into the toc file it self
\AddToHook{begindocument}{
  \cftinserthook{toc}{pre-toc}
}
% add one at the very end as well, we cannot use \cftinserthook there
% as it needs to be immediate
\makeatletter
\AddToHook{enddocument/afterlastpage}{
  \immediate@protected@write\@auxout{}{\string\@writefile{toc}{\string\cftinsert\string{post-toc\string}}}
}
\makeatother


\begin{document}


\tableofcontents

... % the rest of the OPs example
3
  • I run TeXlive 2017 and unfortunately hooks do not work for me!
    – Tolaso
    Commented May 25, 2023 at 17:43
  • Any workaround?
    – Tolaso
    Commented May 26, 2023 at 5:41
  • @Tolaso sorry but I see no reason to support such an old LaTeX, upgrade your LaTeX or switch to using overleaf.com
    – daleif
    Commented May 26, 2023 at 7:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .