100 想要定制目录样式,请大佬帮帮忙,目录真的不擅长。

发布于 2022-12-13 13:15:31

4249E4DB-4A61-473C-BA59-6851F9780AD7.jpeg

要求如图,补充如下:
1.所有目录中的标题项需要支持多行文本,就是能自动断行且不会破坏排版
2.无编号的*标题不应出现在目录中
3.编号的地方应至少留够三位数的空间
4.最重要的是,每章后面有虚线间隔,类似上个问题,并且
中间间隔的竖线必须能随着右侧内容高度而自动改变适应
5.最右侧的XX是页码哈
6.比例的话,最好是按图中比例,但也可以适当改变
实在是不熟悉目录如何做,趁着这次学习一些,希望大家帮帮忙,感激不尽哈,这将完善我的模板中的遗留问题,千恩万谢了!!!

查看更多

关注者
0
被浏览
1.1k
雾月
雾月 2022-12-13
这家伙很懒,什么也没写!

外面的盒子自己改。用 tikztcolorbox 都可以。改颜色、字体、\parttocbox \chaptertocbox \chaptertocdashed即可,其它的基本不用改。

目前的效果是这样:
image.png

\documentclass{ctexbook}
%\usepackage{titlesec}
\usepackage{xcolor}
\usepackage{paracol}
\usepackage{etoc}
\usepackage{calc}
\usepackage{varwidth}
%\usepackage{hyperref}
\begin{document}

\makeatletter
\newlength{\parttocsep}
%%%---只需改这中间的即可,如果要改间距再改后面的
\newcommand{\toccolorlist}{black,red!70,green!30!black,cyan,black!70}
%% 颜色自己加,使用逗号分割即可,在目录中 \tocthecolor 保存了当前值
\setlength{\parttocsep}{12pt plus 4pt minus 4pt}
% #1=number, #2=name, #3=page
\newcommand{\parttocbox}[3]{\zihao{-3}\fbox{#3}\hfill
  \parbox[t]{.7\columnwidth}{#1\par \large #2}}
\newcommand{\chaptertocbox}[3]{%
  \fbox{\parbox{2em}{#1}%
    \begin{varwidth}{\linewidth-4em}#2\end{varwidth}}\hfill#3}
\newcommand{\chaptertocdashed}{\noindent\makebox[\columnwidth]{\dotfill}}
\newcommand{\tocinitials}{\columnratio{.33}
  \twosided[m]%
  \setlength{\columnseprule}{3pt}% 中间的线宽
  \setlength{\parindent}{0pt}}
\newcommand{\parttoccode}{{\parttocbox{Part \etocnumber}{\etocname}{\two@digits{\etocthepage}}\par}}
\newcommand{\chaptertoccode}{{\chaptertocbox{\etocnumber}{\etocname}{\etocpage}\par}}
\newcommand{\sectiontoccode}{\@dottedtocline{1}{3em}{3.7em}{\etocnumber\enskip\etocname}{\etocpage}}
\newcommand{\subsectiontoccode}{\@dottedtocline{2}{6.7em}{2.6em}{\etocnumber\etocname}{\etocpage}}
\newcommand{\subsubsectiontoccode}{\@dottedtocline{3}{6.7em}{2.6em}{\etocnumber\etocname}{\etocpage}}
%%%---
\ExplSyntaxOn
\tl_set:Nn \tocthecolor {black}
\cs_new_protected:Npn \toccolor #1
  {
    \tl_set:Nx \tocthecolor
      {
        \clist_item:Nn \toccolorlist
          { \int_mod:nn {#1} { \clist_count:N \toccolorlist } + 1 }
      }
    \normalcolor
  }
\ExplSyntaxOff
\newcommand{\tocnumberline}[1]{%
  \protect\numberline{\CTEXifname{\number\value{#1}}{0}}}
%% 必须留着
\ctexset{part/tocline=\tocnumberline{part}{#2},
  chapter/tocline=\tocnumberline{chapter}{#2},
  section/name={第,节},section/number=\arabic{section},
  subsection/number={\thesection.\arabic{subsection}},}
\renewcommand*{\thesection}{\arabic{chapter}.\arabic{section}}
\counterwithin{chapter}{part}

\begingroup
\etocsetstyle{part}
  {}
  {\@bsphack\tocinitials\@esphack
    \def\normalcolor{\color{\tocthecolor}}%
    \etociffirst{}{\addvspace{\parttocsep}}%
    \begin{paracol}{2}}
  {\switchcolumn[0]* \toccolor{\etocthenumber}\parttoccode}
  {}
\etocsetstyle{chapter}
  {\switchcolumn \nointerlineskip}
  {\etociffirst{}{\par\chaptertocdashed\par}}
  {\chaptertoccode\par \prevdepth-\@m\p@ \vspace{1ex+\lineskip}\par}
  {\end{paracol}}
\etocsetstyle{section}
  {\par}
  {}
  {\sectiontoccode}
  {\par\prevdepth-\@m\p@ \vspace{1ex+\lineskip}\par}
\etocsetstyle{subsection}
  {\par}
  {}
  {\subsectiontoccode}
  {\par}
\etocsetstyle{subsubsection}
  {\par}
  {}
  {\subsubsectiontoccode}
  {\par}
\tableofcontents
\endgroup
\makeatother

\part{一个部分}
\chapter{介绍}
\section{引言}
\chapter{简明教程}

\part{编译方式、编码与字库}
\chapter{常见的编译方式有哪些}
\chapter{不同的编码}
\chapter{字库}

\part{章节标题设置方式大全}
\chapter{章节标题样式设计大全(不使用宏包直接设置方法)}
\section{编号相关}
\section{格式相关}
\section{间距相关}
\section{目录、附录}
\subsection{小小节但是名字很长的节}
\subsection{小心地}
\section{很长很长很长很长很长的标题怎么设置}
\chapter{章节标题样式设计大全(宏包)}
\chapter{一分为二的标题}
\chapter{一些样式}

\part{长标题是怎样排版的?长标题是怎样换行的?}
\chapter{长标题要断行该使用什么样的命令或环境呢?}
\chapter{短标题}
\chapter{不得使用titlesec宏包}
\chapter{直接用ctex设置}
\chapter{1234567}

\end{document}
2 个回答
LaTeXStudio
LaTeXStudio 2022-12-13
这家伙很懒,什么也没写!

是不是更接近这个链接的样式:https://www.latexstudio.net/index/details/index/mid/387.html

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览