我正在制作一个双栏目录。它非常详细,包含小节、子小节,甚至命名段落。当然,这些栏会覆盖整个页面,并从下一页重新开始。
1) 我希望这些双列块不是从页面边界重新开始,而是从每个新部分重新开始。我接受这些块的高度会有所不同,而且会很不整齐。
2)不再依赖页面边缘提供的自然边界,而是希望两栏区块被 mdframed单独地,必要时跨越页面边界。
etoc.pdf 中提供了下面引用的框架。但它很复杂,而且离我想要的还差得很远,除非有人能帮忙,否则我觉得这会花上我好几个星期的时间。(也欢迎基于 tcolorbox 的解决方案。)
42.5. 命令 \etocframedstyle 、 \etocframed 和 \etoclocalframed
整个目录都带有框架。标题本身没有框架:如果想要框架,应在 \etocframedstyle 或 \etocframed 的 title 参数内设置。背景颜色和边框组件(顶部、左侧、右侧、底部)的颜色通过适当的 \renewcommand 指定(参见第 46.2 节)。由于使用了 minipage,因此生成的目录与分页符不兼容。若要允许分页符,建议在 \etocsettocstyle 的参数中使用 mdframed 39 或 tcolorbox 40 命令。
答案1
以下是使用 和 的尝试framed
。mdframed
我没有尝试tcolorbox
。
但我遇到了一个困难:可能是因为multicols
便于在它之前或之后分页,所以很难让这些框很好地分页:要么它们不分页,要么它们优先在章节标题之后分页。
所以最后,我注释掉了用法multicols
,并在这里发布了单列的示例。
一些评论:
因为在两种情况下标题都是以延迟方式打印的(由
framed
或),所以和必须以某种方式存储然后重新使用,mdframed
\etocname
\etocnumber
因为章节样式可能会关闭一个组,所以
\etocglobaldefs
在序言中发布一个问题,因为我们重新定义了章节样式,所以
etoc
会自动为其他级别(章节、子章节、子子章节)使用其自己的自定义线条样式。但是这种自定义样式会删除段落和子段落,并“水平”打印子子章节。因此,完整的示例需要重新设计所有级别。
带框
\documentclass[a4paper]{book}
\usepackage{etoc}
\usepackage{framed}
\usepackage{color}
\definecolor{TFTitleColor}{rgb}{0,0,1}
\definecolor{TFFrameColor}{gray}{0.75}
\usepackage{amssymb}% \blacktriangleright needed by framed.sty
\usepackage{hyperref}% testing compatibility
\usepackage{geometry}
\begin{document}
\etocglobaldefs % needed because our chapter style closes a group
\etocsetstyle{chapter}
{}
{\etocxiffirst{}%
{%\end{multicols}
\end{titled-frame}}%
% the above possibly closed a group, this is why we issued \etocglobaldefs
% seems we need to preserve meaning for later expansion
\global\let\savedchapterlinkednumber\etocthelinkednumber
\global\let\savedchapterlinkedname\etocthelinkedname
\begin{titled-frame}{\savedchapterlinkednumber. \savedchapterlinkedname}
%\begin{multicols}{2}
}
{}
{%\end{multicols}
\end{titled-frame}}
% \renewcommand{\etocaftertitlehook}{\columnsep1cm }% multicols
\tableofcontents
\part{ONE}
\chapter{Test chapter one}
\section{Section one one}
\subsection{Subsection one one one}
\subsection{Subsection one one two}
\section{Section one two}
\subsection{Subsection one two one}
\subsection{Subsection one two two}
\section{Section one three}
\subsection{Subsection one three one}
\subsection{Subsection one three two}
\section{Section one four}
\subsection{Subsection one four one}
\subsection{Subsection one four two}
\chapter{Test chapter two}
\section{Section two one}
\subsection{Subsection two one one}
\subsection{Subsection two one two}
\subsection{Subsection two one three}
\section{Section two two}
\subsection{Subsection two two one}
\subsection{Subsection two two two}
\subsection{Subsection two two three}
\section{Section two three}
\subsection{Subsection two three one}
\subsection{Subsection two three two}
\subsection{Subsection two three three}
\section{Section two four}
\subsection{Subsection two four one}
\subsection{Subsection two four two}
\subsection{Subsection two four three}
\section{Section two five}
\subsection{Subsection two five one}
\subsection{Subsection two five two}
\subsection{Subsection two five three}
\section{Section two six}
\subsection{Subsection two six one}
\subsection{Subsection two six two}
\subsection{Subsection two six three}
\subsection{Subsection two four three}
\section{Section two seven}
\subsection{Subsection two seven one}
\subsection{Subsection two seven two}
\subsection{Subsection two seven three}
\section{Section two eight}
\subsection{Subsection two eight one}
\subsection{Subsection two eight two}
\subsection{Subsection two eight three}
\chapter{Test chapter three}
\section{Section three one}
\subsection{Subsection three one one}
\subsection{Subsection three one two}
\section{Section three two}
\subsection{Subsection three two one}
\subsection{Subsection three two two}
\section{Section three three}
\subsection{Subsection three three one}
\subsection{Subsection three three two}
\section{Section three four}
\subsection{Subsection three four one}
\subsection{Subsection three four two}
\chapter{Test chapter four}
\section{Section four one}
\subsection{Subsection four one one}
\subsection{Subsection four one two}
\subsection{Subsection four one three}
\section{Section four two}
\subsection{Subsection four two one}
\subsection{Subsection four two two}
\subsection{Subsection four two three}
\end{document}
第一页:
第二页:
使用 mdframed
\documentclass{book}
\usepackage{etoc}
\usepackage{mdframed}
\begin{document}
\global\mdfdefinestyle{myexampledefault}{%
linecolor=red,linewidth=3pt,%
leftmargin=1cm,rightmargin=1cm,%
rightline=true,innerleftmargin=10,innerrightmargin=10,
frametitlerule=true,frametitlerulecolor=green,
frametitlebackgroundcolor=yellow,
frametitlerulewidth=2pt}
\etocglobaldefs % needed because our chapter style closes a group
\etocsetstyle{chapter}
{}
{\etocxiffirst{}%
{%\end{multicols}
\end{mdframed}}%
% the above possibly closed a group, this is why we issued \etocglobaldefs
% seems we need to preserve meaning for later expansion
\global\let\savedchapterlinkednumber\etocthelinkednumber
\global\let\savedchapterlinkedname\etocthelinkedname
\begin{mdframed}[style=myexampledefault,%
frametitle={\savedchapterlinkednumber. \savedchapterlinkedname}]%
%\begin{multicols}{2}
}
{}
{%\end{multicols}
\end{mdframed}}
% \renewcommand{\etocaftertitlehook}{\columnsep1cm }% multicols
\tableofcontents
\part{ONE}
\chapter{Test chapter one}
\section{Section one one}
\subsection{Subsection one one one}
\subsection{Subsection one one two}
\section{Section one two}
\subsection{Subsection one two one}
\subsection{Subsection one two two}
\section{Section one three}
\subsection{Subsection one three one}
\subsection{Subsection one three two}
\section{Section one four}
\subsection{Subsection one four one}
\subsection{Subsection one four two}
\chapter{Test chapter two}
\section{Section two one}
\subsection{Subsection two one one}
\subsection{Subsection two one two}
\subsection{Subsection two one three}
\section{Section two two}
\subsection{Subsection two two one}
\subsection{Subsection two two two}
\subsection{Subsection two two three}
\section{Section two three}
\subsection{Subsection two three one}
\subsection{Subsection two three two}
\subsection{Subsection two three three}
\section{Section two four}
\subsection{Subsection two four one}
\subsection{Subsection two four two}
\subsection{Subsection two four three}
\section{Section two five}
\subsection{Subsection two five one}
\subsection{Subsection two five two}
\subsection{Subsection two five three}
\section{Section two six}
\subsection{Subsection two six one}
\subsection{Subsection two six two}
\subsection{Subsection two six three}
\subsection{Subsection two four three}
\section{Section two seven}
\subsection{Subsection two seven one}
\subsection{Subsection two seven two}
\subsection{Subsection two seven three}
\section{Section two eight}
\subsection{Subsection two eight one}
\subsection{Subsection two eight two}
\subsection{Subsection two eight three}
\chapter{Test chapter three}
\section{Section three one}
\subsection{Subsection three one one}
\subsection{Subsection three one two}
\section{Section three two}
\subsection{Subsection three two one}
\subsection{Subsection three two two}
\section{Section three three}
\subsection{Subsection three three one}
\subsection{Subsection three three two}
\section{Section three four}
\subsection{Subsection three four one}
\subsection{Subsection three four two}
\chapter{Test chapter four}
\section{Section four one}
\subsection{Subsection four one one}
\subsection{Subsection four one two}
\subsection{Subsection four one three}
\section{Section four two}
\subsection{Subsection four two one}
\subsection{Subsection four two two}
\subsection{Subsection four two three}
\end{document}
第一页
第二页
正如我在 incipit 中解释的那样,它确实适用于multicols
可破坏框内的附加环境,只是破坏的位置选择得令人失望,而我对此没有解决方案。因此我没有发布图片。取消注释 MWE 中的相关行以进行测试。
当然,上面的内容需要重新设计以适应 OP 的限制,因为如前所述,使用了自己的 etoc 样式,并且只有章节以自定义方式定义。也许像这样的东西\etocsavedsectiontocline
可以有所帮助,因为它们允许重现类默认值。请参阅 etoc 文档。
我正在添加一个版本,该版本在框架章节样式中将章节和子章节设置为类默认值。MWE 已添加\part{TWO}
。左侧注释掉的尝试要么在多列中排版整个内容,要么在框架环境中使用多列,每个都有其问题(此处未说明)。
\documentclass[a4paper]{book}
\usepackage{etoc}
\usepackage{framed}
\usepackage{color}
\definecolor{TFTitleColor}{rgb}{0,0,1}
\definecolor{TFFrameColor}{gray}{0.75}
\usepackage{amssymb}% \blacktriangleright needed by framed.sty
\usepackage{hyperref}% testing compatibility
\usepackage{geometry}
\begin{document}
\etocglobaldefs % needed because our chapter style closes a group
\etocsetstyle{chapter}
{}
{\etocxiffirst{}%
{%\end{multicols}
\end{titled-frame}}%
% the above possibly closed a group, this is why we issued \etocglobaldefs
% seems we need to preserve meaning for later expansion
\global\let\savedchapterlinkednumber\etocthelinkednumber
\global\let\savedchapterlinkedname\etocthelinkedname
\begin{titled-frame}{\savedchapterlinkednumber. \savedchapterlinkedname}
%\begin{multicols}{2}
}
{}
{%\end{multicols}
\end{titled-frame}}
% \renewcommand{\etocaftertitlehook}{\begin{multicols}2\raggedcolumns}
% \renewcommand{\etocaftercontentshook}{\end{multicols}}
\etocsetstyle{section}
{}
{\etocsavedsectiontocline
{\etocifnumbered{\numberline{\etocnumber}}{}%
\etocname}
{\etocpage}%
}
{}
{}
\etocsetstyle{subsection}
{}
{\etocsavedsubsectiontocline
{\etocxifnumbered{\numberline{\etocnumber}}{}%
\etocname}
{\etocpage}%
}
{}
{}
\tableofcontents
\part{ONE}
\chapter{Test chapter one}
\section{Section one one}
\subsection{Subsection one one one}
\subsection{Subsection one one two}
\section{Section one two}
\subsection{Subsection one two one}
\subsection{Subsection one two two}
\section{Section one three}
\subsection{Subsection one three one}
\subsection{Subsection one three two}
\section{Section one four}
\subsection{Subsection one four one}
\subsection{Subsection one four two}
\chapter{Test chapter two}
\section{Section two one}
\subsection{Subsection two one one}
\subsection{Subsection two one two}
\subsection{Subsection two one three}
\section{Section two two}
\subsection{Subsection two two one}
\subsection{Subsection two two two}
\subsection{Subsection two two three}
\section{Section two three}
\subsection{Subsection two three one}
\subsection{Subsection two three two}
\subsection{Subsection two three three}
\section{Section two four}
\subsection{Subsection two four one}
\subsection{Subsection two four two}
\subsection{Subsection two four three}
\section{Section two five}
\subsection{Subsection two five one}
\subsection{Subsection two five two}
\subsection{Subsection two five three}
\section{Section two six}
\subsection{Subsection two six one}
\subsection{Subsection two six two}
\subsection{Subsection two six three}
\subsection{Subsection two four three}
\section{Section two seven}
\subsection{Subsection two seven one}
\subsection{Subsection two seven two}
\subsection{Subsection two seven three}
\section{Section two eight}
\subsection{Subsection two eight one}
\subsection{Subsection two eight two}
\subsection{Subsection two eight three}
\part{TWO}
\chapter{Test chapter three}
\section{Section three one}
\subsection{Subsection three one one}
\subsection{Subsection three one two}
\section{Section three two}
\subsection{Subsection three two one}
\subsection{Subsection three two two}
\section{Section three three}
\subsection{Subsection three three one}
\subsection{Subsection three three two}
\section{Section three four}
\subsection{Subsection three four one}
\subsection{Subsection three four two}
\chapter{Test chapter four}
\section{Section four one}
\subsection{Subsection four one one}
\subsection{Subsection four one two}
\subsection{Subsection four one three}
\section{Section four two}
\subsection{Subsection four two one}
\subsection{Subsection four two two}
\subsection{Subsection four two three}
\end{document}
最后,这里是 2 列显示,但使用的是书籍类\twocolumn
而不是multicols
环境。这似乎工作正常。
诀窍是用来\etocsettocstyle
做与目录通常完全相反的事情,即,如果处于单列模式,我们将暂时切换到双列模式。
\documentclass[a4paper]{book}
\usepackage{etoc}
\usepackage{framed}
\usepackage{color}
\definecolor{TFTitleColor}{rgb}{0,0,1}
\definecolor{TFFrameColor}{gray}{0.75}
\usepackage{amssymb}% \blacktriangleright needed by framed.sty
\usepackage{hyperref}% testing compatibility
\usepackage{geometry}
\begin{document}
\etocglobaldefs % needed because our chapter style closes a group
\etocsetstyle{chapter}
{}
{\etocxiffirst{}%
{%\end{multicols}
\end{titled-frame}}%
% the above possibly closed a group, this is why we issued \etocglobaldefs
% seems we need to preserve meaning for later expansion
\global\let\savedchapterlinkednumber\etocthelinkednumber
\global\let\savedchapterlinkedname\etocthelinkedname
\begin{titled-frame}{\savedchapterlinkednumber. \savedchapterlinkedname}
%\begin{multicols}{2}
}
{}
{%\end{multicols}
\end{titled-frame}}
% \renewcommand{\etocaftertitlehook}{\begin{multicols}2\raggedcolumns}
% \renewcommand{\etocaftercontentshook}{\end{multicols}}
\etocsetstyle{section}
{}
{\etocsavedsectiontocline
{\etocifnumbered{\numberline{\etocnumber}}{}%
\etocname}
{\etocpage}%
}
{}
{}
\etocsetstyle{subsection}
{}
{\etocsavedsubsectiontocline
{\etocxifnumbered{\numberline{\etocnumber}}{}%
\etocname}
{\etocpage}%
}
{}
{}
\makeatletter
\etocsettocstyle
{\if@twocolumn \@restonecolfalse
\else \setlength{\columnsep}{1cm} \@restonecoltrue \twocolumn
\fi
\chapter *{\contentsname
\@mkboth {\MakeUppercase \contentsname}
{\MakeUppercase \contentsname}%
}%
}
{\if@restonecol \onecolumn \fi}
\makeatother
\tableofcontents
\part{ONE}
\chapter{Test chapter one}
\section{Section one one}
\subsection{Subsection one one one}
\subsection{Subsection one one two}
\section{Section one two}
\subsection{Subsection one two one}
\subsection{Subsection one two two}
\section{Section one three}
\subsection{Subsection one three one}
\subsection{Subsection one three two}
\section{Section one four}
\subsection{Subsection one four one}
\subsection{Subsection one four two}
\chapter{Test chapter two}
\section{Section two one}
\subsection{Subsection two one one}
\subsection{Subsection two one two}
\subsection{Subsection two one three}
\section{Section two two}
\subsection{Subsection two two one}
\subsection{Subsection two two two}
\subsection{Subsection two two three}
\section{Section two three}
\subsection{Subsection two three one}
\subsection{Subsection two three two}
\subsection{Subsection two three three}
\section{Section two four}
\subsection{Subsection two four one}
\subsection{Subsection two four two}
\subsection{Subsection two four three}
\section{Section two five}
\subsection{Subsection two five one}
\subsection{Subsection two five two}
\subsection{Subsection two five three}
\section{Section two six}
\subsection{Subsection two six one}
\subsection{Subsection two six two}
\subsection{Subsection two six three}
\subsection{Subsection two four three}
\section{Section two seven}
\subsection{Subsection two seven one}
\subsection{Subsection two seven two}
\subsection{Subsection two seven three}
\section{Section two eight}
\subsection{Subsection two eight one}
\subsection{Subsection two eight two}
\subsection{Subsection two eight three}
\part{TWO}
\chapter{Test chapter three}
\section{Section three one}
\subsection{Subsection three one one}
\subsection{Subsection three one two}
\section{Section three two}
\subsection{Subsection three two one}
\subsection{Subsection three two two}
\section{Section three three}
\subsection{Subsection three three one}
\subsection{Subsection three three two}
\section{Section three four}
\subsection{Subsection three four one}
\subsection{Subsection three four two}
\chapter{Test chapter four}
\section{Section four one}
\subsection{Subsection four one one}
\subsection{Subsection four one two}
\subsection{Subsection four one three}
\section{Section four two}
\subsection{Subsection four two one}
\subsection{Subsection four two two}
\subsection{Subsection four two three}
\end{document}
生产
第一页:
第二页: