调整 minitoc 标题和内容之间的垂直间距

调整 minitoc 标题和内容之间的垂直间距

我正在使用minitoc并且想要调整标题和内容之间的垂直空间,如下图所示:

minitoc 标题和内容之间的间距

这是我的 MWE:

\documentclass{book}    
\usepackage{minitoc}    
\nomtcrule
\begin{document}    
  \dominitoc
  \faketableofcontents    
  \chapter{Minimum}
    \minitoc
    \section{Working}
    \section{Example}    
\end{document}

答案1

使用\mtcsetfeature{minitoc}{open}{\vspace{1cm}}

\documentclass{book}   
\usepackage{minitoc}    

\mtcsetfeature{minitoc}{open}{\vspace{1cm}}
\nomtcrule
\begin{document}    
  \dominitoc
  \faketableofcontents    
  \chapter{Minimum}
    \minitoc
    \section{Working}
    \section{Example}    
\end{document}

答案2

嗯,\minitoc这是一个奇怪的命令;-)

我希望提供一种更清洁的方法,但xpatch在这里不起作用(或者我到目前为止还没有找到它),所以它归结为redefining \minitoc@,基本命令\minitoc

标题本身是在表格环境中设置的 - 如果没有mtc@rule,则使用条件的上部,几乎没有空间 - 我添加了新的长度并替换\\\\[\mymtcaftertitleskip]

        \ifx\mtc@rule\relax
         \begin{tabular}{@{}p{\columnwidth}@{}}
           \reset@font\mtifont\do@mtitc{\mtc@v\mtctitle}\\[\mymtcaftertitleskip]%
         \end{tabular}%
        \else
         \begin{tabular}{@{}p{\columnwidth}@{}}
           \reset@font\mtifont\do@mtitc{\mtc@v\mtctitle}\\\hline
         \end{tabular}%
        \fi

不要害怕长话短说\def\minitoc@——来自minitoc.sty

\documentclass[]{book}    
\usepackage{minitoc}    


\newlength{\mymtcaftertitleskip}
\setlength{\mymtcaftertitleskip}{2ex} % For example

\makeatletter

\def\minitoc@[#1]{%
\global\@minitoc@used@true
\if@mtc@longext@
   \def\@tocfile{mtc\The@mtc}%
\else
   \def\@tocfile{M\The@mtc}%
 \fi
        \mtc@CkFile{\jobname.\@tocfile}
        \if@mtc@FE
        \mtcPackageInfo[I0006]{minitoc}%
           {\jobname.\@tocfile\space is empty}
        \@mtc@empty@minitoc@true
        \else
        \thispageminitocstyle
%%        \mtc@markboth{\MakeUppercase{\mtctitle}}{\MakeUppercase{\mtctitle}}%
        \beforeminitoc
        \relax\begin{samepage}%
        \if #1e\let\do@mtitc\e@mti
         \else\if #1n\let\do@mtitc\n@mti
         \else\if #1c\let\do@mtitc\c@mti
         \else\if #1l\let\do@mtitc\l@mti
         \else\if #1r\let\do@mtitc\r@mti
         \else\if #1d\let\do@mtitc\df@mtitc
        \fi\fi\fi\fi\fi\fi
        \mtc@CkStr{\mtctitle}\if@mtc@FE \let\do@mtitc\e@mti\relax\fi
        \raggedright
        \parskip=\z@%
        \reset@font\mtcfont%
        \parindent=\z@%
        \nopagebreak[4]%
        \kern-0.8\baselineskip\nopagebreak[4]%
        \par\noindent %%
        \ifx\mtc@rule\relax
         \begin{tabular}{@{}p{\columnwidth}@{}}
           \reset@font\mtifont\do@mtitc{\mtc@v\mtctitle}\\[\mymtcaftertitleskip]%
         \end{tabular}%
        \else
         \begin{tabular}{@{}p{\columnwidth}@{}}
           \reset@font\mtifont\do@mtitc{\mtc@v\mtctitle}\\\hline
         \end{tabular}%
        \fi
        \nopagebreak[4]\null\leavevmode\mtc@zrule\\\mtc@BBR
        \leftmargin\mtcindent \rightmargin\mtcindent
        \itemindent=\z@\labelwidth=\z@%
        \labelsep=\z@\listparindent=\z@%
        \begin{mtc@verse}{\mtcoffset}%
        \c@tocdepth=\c@minitocdepth
        \leavevmode\\\mtc@BBR\vskip -.5\baselineskip
\begingroup
  \makeatletter
  \@ifundefined{mtc@pgno}%
  {\let\@dottedtocline\@undottedtocline}{}
  \@fileswfalse\mtc@hook@beforeinputfile
  \mtc@setform%
  \openminitoc \global\inminitoctrue
  \@input{\jobname.\@tocfile}%
  \global\inminitocfalse\closeminitoc
  \vspace{-1ex} \vspace{-\baselineskip}
  \leavevmode\mtc@strut
  \global\@nobreakfalse\endgroup
        \end{mtc@verse}%
        \kernafterminitoc
        \nopagebreak[4]\mtc@bottom@rule\null\leavevmode\\%
        \vskip-1.0\baselineskip\mtc@zrule\end{samepage}%
        \par\pagebreak[1]\vspace*{-1ex}\afterminitoc\fi}

\makeatother





\nomtcrule
\begin{document}    
  \dominitoc
  \faketableofcontents    
  \chapter{Minimum}
    \minitoc
    \section{Working}
    \section{Example}    
\end{document}

在此处输入图片描述

编辑现在,在 egreg 和 Heiko Oberdiek 的帮助下,我们得到了更简短的解决方案:

\minitoc内部使用\minitoc@,实际上稍后会\sv@minitoc@通过\let语句将其复制到。因此需要修补\sv@minitoc@

\documentclass[]{book}    
\usepackage{minitoc}    


\usepackage{xpatch}
\newlength{\mymtcaftertitleskip}
\setlength{\mymtcaftertitleskip}{2ex} % For example

\makeatletter
\xpatchcmd{\sv@minitoc@}{%
  \begin{tabular}{@{}p{\columnwidth}@{}}
    \reset@font\mtifont\do@mtitc{\mtc@v\mtctitle}\\
  \end{tabular}%
}{%
  \begin{tabular}{@{}p{\columnwidth}@{}}
    \reset@font\mtifont\do@mtitc{\mtc@v\mtctitle}\\[\mymtcaftertitleskip]%
  \end{tabular}%
}{\typeout{Patch success}}{\typeout{Patch failed}}  

\makeatother

\nomtcrule
\begin{document}    
  \dominitoc
  \faketableofcontents    
  \chapter{Minimum}
    \minitoc
    \section{Working}
    \section{Example}    
\end{document}

相关内容