将迷你目录移至页面第 2 部分顶角

将迷你目录移至页面第 2 部分顶角

这个问题是建立提出的解决方案这里

我现在想让内容根据页码显示在相对的两侧,即奇数或偶数。我尝试使用命令\node[above right=\topmargin, anchor=north east,但没有得到想要的结果。您能帮助我让迷你目录根据章节开始的页码显示在交替的两侧吗?

以下是由克拉格费尔特

\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

万一您想自动放置 minitoc(而不是手动),因为eso-pic无论如何您都在加载,我无法抗拒。

\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}

相关内容