MiniToc 节点内的对齐

MiniToc 节点内的对齐

我正在使用 tikz 在每个章节中定制我的 miniToc。但是我在节点内部的 TOC 对齐方面遇到了问题。

\begin{flushright}我在 minipage 里面用过,也在命令\contentsmargin{0cm}前用过\printcontents\noindent但是没有得到想要的结果。

这就是我所追求的:

在此处输入图片描述

在此处输入图片描述

这是我用于定制 minitoc 的代码:

\newcommand{\printmyminitoc}{%
    \begin{center}%
        \begin{tikzpicture}%
            \node[anchor=south,inner ysep=12.5pt,inner xsep=20pt,align=flush left] (s) at (current page.south) {
                \begin{minipage}[c][][t]{0.90\textwidth}
                    \begin{flushright}
                        \renewcommand{\baselinestretch}{1.2}\selectfont
                        \startcontents[chapters]
                        \printcontents[chapters]{}{1}{}
                     \end{flushright}
                \end{minipage}
             };
            \draw[bottom color = blue!80, top color= blue!10, draw=blue!90,fill opacity=0.1,decorate, decoration={random steps,segment length=3pt,amplitude=1pt},line width=1.25pt] (s.north west) rectangle (s.south east);
        \end{tikzpicture}%
    \end{center}%
    }

我能否获得有关如何定义正确对齐的任何指导?

以下是 MWE:

\documentclass[twoside,12pt,openright]{scrbook}
\usepackage[a4paper]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage[sfdefault]{universalis}
\usepackage{titletoc}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{decorations, decorations.pathmorphing, decorations.pathreplacing}
\usepackage[linkcolor=black,colorlinks=true]{hyperref}
%% command to print the actual minitoc ---------------------------------------------
\newcommand{\printmyminitoc}{%
    \begin{center}%
        \begin{tikzpicture}%
            \node[anchor=south,inner ysep=12.5pt,inner xsep=20pt,align=flush left] (s) at (current page.south) {
                \begin{minipage}[c][][t]{0.90\textwidth}
                    \begin{flushright}
                        \renewcommand{\baselinestretch}{1.2}\selectfont
                        \startcontents[chapters]
                        \printcontents[chapters]{}{1}{}
                     \end{flushright}
                \end{minipage}
             };
            \draw[bottom color = blue!80, top color= blue!10, draw=blue!90,fill opacity=0.1,decorate, decoration={random steps,segment length=3pt,amplitude=1pt},line width=1.25pt] (s.north west) rectangle (s.south east);
        \end{tikzpicture}%
    \end{center}%
    }
    
\begin{document}
    \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
    \frontmatter
    \pagenumbering{roman}
    \pagestyle{empty}   
    \setcounter{tocdepth}{2}
    \tableofcontents        
    \cleardoublepage
    \mainmatter
    \pagenumbering{arabic}
    \setcounter{page}{1}
    \pagestyle{headings}
    \chapter{Intro}
    \printmyminitoc
    \lipsum[1-3]
    \section{Intro 1 - Section 1}
    \lipsum[1-3]
    \section{Intro 1 - Section 2}
    \lipsum[1-3]
    \section{Intro 1 - Section 3}
    \lipsum[1-3]
    \section{Intro 1 - Section 4}
    \lipsum[1-3]
    \section{Intro 1  - Section 5}
    \lipsum[1-3]
    \chapter{Literature}
    \printmyminitoc
    \lipsum[1-3]
    \section{Literature - Section 1}
    \lipsum[1-3]
    \section{Literature - Section 2}
    \lipsum[1-3]
    \section{Literature - Section 3}
    \lipsum[1-3]
    \section{Literature - Section 4}
    \lipsum[1-3]
    \section{Literature - Section 5}
    \lipsum[1-3]
\end{document}

答案1

创建一个新的章节和小节格式(名为xsectionxsubsection),使用\titlecontentsfromtitletoc和 adjust left(左边距从左边距)

\titlecontents{⟨section⟩}[⟨left⟩]{⟨above-code⟩}{⟨numbered-entry-format⟩}{⟨numberless-entry-format⟩}
{⟨filler-page-format⟩}[⟨below-code⟩]

然后用来\printcontents[chapters]{x}{1}{}生成部分 ToC。

A

\documentclass[twoside,12pt,openright]{scrbook}
\usepackage[a4paper]{geometry}
\usepackage[dvipsnames]{xcolor}
\usepackage[sfdefault]{universalis}
\usepackage{titletoc}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{decorations, decorations.pathmorphing, decorations.pathreplacing}
\usepackage[linkcolor=black,colorlinks=true]{hyperref}
%% command to print the actual minitoc ---------------------------------------------
\newcommand{\printmyminitoc}{%
    \begin{center}%
        \begin{tikzpicture}%
            \node[anchor=south,inner ysep=12.5pt,inner xsep=20pt,align=flush left] (s) at (current page.south) {
                \begin{minipage}[c][][t]{0.90\textwidth}
                    \begin{flushright}
                        \renewcommand{\baselinestretch}{1.2}\selectfont
                        \startcontents[chapters]
                        \printcontents[chapters]{x}{1}{}% changed <<<<<<<<<<<<<<<<
                    \end{flushright}
                \end{minipage}
            };
            \draw[bottom color = blue!80, top color= blue!10, draw=blue!90,fill opacity=0.1,decorate, decoration={random steps,segment length=3pt,amplitude=1pt},line width=1.25pt] (s.north west) rectangle (s.south east);
        \end{tikzpicture}%
    \end{center}%
}

%****************************% added <<<<<<<<<<<< from https://tex.stackexchange.com/a/66346/161015
\titlecontents{xsection}[1em]{}{\contentslabel{2.3em}} {} {\titlerule*[1pc]{.}\contentspage}

\titlecontents{xsubsection}[4.2em]{}{\contentslabel{3.2em}} {} {\titlerule*[1pc]{.}\contentspage}
%**********************************

\begin{document}
    \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
    \frontmatter
    \pagenumbering{roman}
    \pagestyle{empty}   
    \setcounter{tocdepth}{2}
    \tableofcontents        
    \cleardoublepage
    \mainmatter
    \pagenumbering{arabic}
    \setcounter{page}{1}
    \pagestyle{headings}
    \chapter{Intro}
    \printmyminitoc
    \lipsum[1-3]
    \section{Intro 1 - Section 1}
    \lipsum[1-3]
    \subsection{Intro 1 -Sub Section 1}
    \lipsum[1-3]
    \section{Intro 1 - Section 3}
    \lipsum[1-3]
    \section{Intro 1 - Section 4}
    \lipsum[1-3]
    \section{Intro 1  - Section 5}
    \lipsum[1-3]
    \chapter{Literature}
    \printmyminitoc
    \lipsum[1-3]
    \section{Literature - Section 1}
    \lipsum[1-3]
    \section{Literature - Section 2}
    \lipsum[1-3]
    \section{Literature - Section 3}
    \lipsum[1-3]
    \section{Literature - Section 4}
    \lipsum[1-3]
    \section{Literature - Section 5}
    \lipsum[1-3]
\end{document}

删除部分目录中的章节缩进

相关内容