1

This question is building of the solution presented here.

I would now like the contents to appear on opposite sides based on the page number, i.e. odd or even. I tried using the commands \node[above right=\topmargin, anchor=north east, but I did not get the desired results. Can you assist me in getting the mini TOC to show up on alternate sides based on the page number that the chapter starts?

Here is the code developed by Cragfelt:

\documentclass{report}

\RequirePackage{polyglossia}
\RequirePackage{calc}
\RequirePackage[usenames,dvipsnames,svgnames,table]{xcolor}
\RequirePackage{amsmath, amsfonts, amssymb}
\RequirePackage{ragged2e}
\RequirePackage{eso-pic}
\RequirePackage{fancyhdr}
\RequirePackage{marginfix}
\RequirePackage{titletoc}
\RequirePackage{mdframed}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       Layout
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{changepage}

\patchcmd{\part}{\thispagestyle{plain}}{\thispagestyle{empty}}{}{\errmessage{Cannot patch \string\part}}

\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}
\setlength{\marginparpush}{1.5\baselineskip}

\RequirePackage[
    xetex,
    a4paper,
%   showframe,
    twoside,
    top=27mm,
    bottom=27mm,
    inner=20mm,
    outer=20mm,
    ignorehead,
    ignorefoot,
    includemp,
    marginparwidth=52mm,
    marginparsep=8mm,
    headsep=7mm,
    footskip=14mm,
    headheight=12.2pt,
]{geometry}

% Commands for changing the page layout mid-document
\newcommand{\symmetricalPage}{
    \fancyhfoffset[OR, EL]{0mm}
    \newgeometry{
        top=20mm,
        bottom=20mm,
        inner=20mm,
        outer=20mm,
        includehead,
        ignorefoot,
        nomarginpar,
        headsep=10mm,
        footskip=10mm,
    }
}
\newcommand{\asymmetricalPage}{
    \restoregeometry
    \fancyhfoffset[OR, EL]{\marginparsep + \marginparwidth}
}

\setlength{\columnsep}{\marginparsep}

% Saving some length as commands
\newlength{\wholeMargin}
\setlength{\wholeMargin}{\marginparwidth}
\addtolength{\wholeMargin}{\marginparsep}

\newlength{\wholeWidth}
\setlength{\wholeWidth}{\textwidth}
\addtolength{\wholeWidth}{\wholeMargin}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       Titling
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{etoc}
\RequirePackage{titlesec}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       Hyper-references
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{hyperref}
\hypersetup{
    pdftoolbar=false,
    pdfmenubar=true,
    pdffitwindow=false,
    pdfborder={0 0 0},
    pdfcreator=LaTeX,
    colorlinks=true,
    linkcolor=black,
    linktoc=all,
    urlcolor=blue,
    citecolor=blue,
    filecolor=blue,
    breaklinks
}

\usepackage{lipsum}

\usepackage{tikz}
\usetikzlibrary{shadows.blur}

\usepackage{titletoc}

\usepackage{calc}

\usepackage[]{titlesec}

\definecolor{lightGrey}{gray}{0.94}

\colorlet{chpnumbercolor}{blue}
\makeatletter
\let\oldl@chapter\l@chapter
\def\l@chapter#1#2{\oldl@chapter{#1}{\textcolor{black}{\textbf{#2}}}}

\let\old@dottedcontentsline\@dottedtocline
\def\@dottedtocline#1#2#3#4#5{%
\old@dottedcontentsline{#1}{#2}{#3}{#4}{{\textcolor{black}{#5}}}}
\makeatother

%command to print the acutal minitoc
\newcommand{\printmyminitoc}{%
    \noindent\hspace{-2cm}%
    \colorlet{chpnumbercolor}{white}%
    \begin{tikzpicture}[remember picture, overlay, transform shape]
    \node[above left=\topmargin, anchor=north west, rounded corners, align=left, fill=lightGrey, blur shadow={shadow blur steps=5}, inner sep=5mm] at (current page.north west)
    {%
        \color{black}%
        \begin{minipage}{8cm}%minipage trick
        \hfill\rule{\linewidth}{.5mm}
        \printcontents[chapters]{}{1}{}
        \hfill\rule{\linewidth}{.5mm}
        \end{minipage}
    };
    \end{tikzpicture}}


\begin{document}

    \chapter{Introduction}
\startcontents[chapters]
\printmyminitoc

    \section{Lorem Ipsum Dolor}
    \lipsum[2]
    \subsection{Test Subsection}
    \lipsum[1]

    \section{Nam dui ligula}

    \lipsum[3]

    \chapter{Content}
\startcontents[chapters]
\printmyminitoc

    \lipsum[2]
    \lipsum[3]

    \section{First Section}
    \subsection{Subsection}

    \lipsum[2]

    \lipsum[2]

    \lipsum[3]

\end{document}
  • 1
    If you get rid of above left=\topmargin, then the minitoc no longer gets swallowed. But I am wondering if you really want to add the minitoc by hand or am I missing something? (I am asking because you are loading eso-pic anyaway.) – marmot Aug 8 '18 at 1:46
2

Just in case you want to put the minitoc automatically (rather than by hand), since you are loading eso-pic anyway, I could not resist.

\documentclass{report}

\RequirePackage{polyglossia}
\RequirePackage{calc}
\RequirePackage[usenames,dvipsnames,svgnames,table]{xcolor}
\RequirePackage{amsmath, amsfonts, amssymb}
\RequirePackage{ragged2e}
\RequirePackage{eso-pic}
\RequirePackage{fancyhdr}
\RequirePackage{marginfix}
\RequirePackage{titletoc}
\RequirePackage{mdframed}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       Layout
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{changepage}

\patchcmd{\part}{\thispagestyle{plain}}{\thispagestyle{empty}}{}{\errmessage{Cannot patch \string\part}}

\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}
\setlength{\marginparpush}{1.5\baselineskip}

\RequirePackage[
    xetex,
    a4paper,
%   showframe,
    twoside,
    top=27mm,
    bottom=27mm,
    inner=20mm,
    outer=20mm,
    ignorehead,
    ignorefoot,
    includemp,
    marginparwidth=52mm,
    marginparsep=8mm,
    headsep=7mm,
    footskip=14mm,
    headheight=12.2pt,
]{geometry}

% Commands for changing the page layout mid-document
\newcommand{\symmetricalPage}{
    \fancyhfoffset[OR, EL]{0mm}
    \newgeometry{
        top=20mm,
        bottom=20mm,
        inner=20mm,
        outer=20mm,
        includehead,
        ignorefoot,
        nomarginpar,
        headsep=10mm,
        footskip=10mm,
    }
}
\newcommand{\asymmetricalPage}{
    \restoregeometry
    \fancyhfoffset[OR, EL]{\marginparsep + \marginparwidth}
}

\setlength{\columnsep}{\marginparsep}

% Saving some length as commands
\newlength{\wholeMargin}
\setlength{\wholeMargin}{\marginparwidth}
\addtolength{\wholeMargin}{\marginparsep}

\newlength{\wholeWidth}
\setlength{\wholeWidth}{\textwidth}
\addtolength{\wholeWidth}{\wholeMargin}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       Titling
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{etoc}
\RequirePackage{titlesec}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%       Hyper-references
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{hyperref}
\hypersetup{
    pdftoolbar=false,
    pdfmenubar=true,
    pdffitwindow=false,
    pdfborder={0 0 0},
    pdfcreator=LaTeX,
    colorlinks=true,
    linkcolor=black,
    linktoc=all,
    urlcolor=blue,
    citecolor=blue,
    filecolor=blue,
    breaklinks
}

\usepackage{lipsum}

\usepackage{tikz}
\usetikzlibrary{shadows.blur}

\usepackage{titletoc}

\usepackage{calc}

\usepackage[]{titlesec}

\definecolor{lightGrey}{gray}{0.94}

\colorlet{chpnumbercolor}{blue}
\makeatletter
\let\oldl@chapter\l@chapter
\def\l@chapter#1#2{\oldl@chapter{#1}{\textcolor{black}{\textbf{#2}}}}

\let\old@dottedcontentsline\@dottedtocline
\def\@dottedtocline#1#2#3#4#5{%
\old@dottedcontentsline{#1}{#2}{#3}{#4}{{\textcolor{black}{#5}}}}
\makeatother

%command to print the acutal minitoc
\newcommand{\printmyminitoc}{%
    \noindent\hspace{-2cm}%
    \colorlet{chpnumbercolor}{white}%
    \begin{tikzpicture}[remember picture, overlay, transform shape]
    \node[above left=\topmargin, anchor=north west, rounded corners, align=left, fill=lightGrey, blur shadow={shadow blur steps=5}, inner sep=5mm] at (current page.north west)
    {%
        \color{black}%
        \begin{minipage}{8cm}%minipage trick
        \hfill\rule{\linewidth}{.5mm}
        \printcontents[chapters]{}{1}{}
        \hfill\rule{\linewidth}{.5mm}
        \end{minipage}
    };
    \end{tikzpicture}}

\AddToShipoutPictureFG{%
    \ifodd\value{page}
    \printmyminitoc %<- move this below \else if you want the minitoc on even pages
    \else
    \fi
    }

\begin{document}

    \chapter{Introduction}
\startcontents[chapters]


    \section{Lorem Ipsum Dolor}
    \lipsum[2]
    \subsection{Test Subsection}
    \lipsum[1]

    \section{Nam dui ligula}

    \lipsum[3]

    \chapter{Content}
\startcontents[chapters]

    \lipsum[2]
    \lipsum[3]

    \section{First Section}
    \subsection{Subsection}

    \lipsum[2]

    \lipsum[2]

    \lipsum[3]

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.