我正在尝试创建一个 3 列的书籍布局。到目前为止,我发现的唯一获得 3 列的方法是使用古老的multicol
,效果很好。使用这个问题的答案自动将 \begin{multicols}{N} 添加到章节我试图使用 在每次输入时etoolbox
自动插入;但是,当使用 设计章节样式时,这会中断。\begin
\end
multicols
\chapter
titlesec
\documentclass{book}
\usepackage{etoolbox}
\usepackage{multicol}
\usepackage{titlesec} % Customize chapters and sections
\usepackage{kantlipsum}
% Automatically wrap \chapter with \begin and \end multicols
\newif\iffirst
\makeatletter
\appto{\mainmatter}
{\firsttrue
\preto{\chapter}{\iffirst\firstfalse\else\end{multicols*}\fi}
\preto{\enddocument}{\end{multicols*}}
\apptocmd{\@makechapterhead}{\begin{multicols*}{3}}{}{}
\apptocmd{\@makeschapterhead}{\begin{multicols*}{3}}{}{}
}
\makeatother
% Format chapter heading
\titleformat
{\chapter} % command
[display] % shape
{\LARGE} % format
{} % label
{-1.75cm} % horizontal separation between label and title body
{Chapter \thechapter. \enspace \vspace{0cm}} % before-code
[] % after-code
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{A chapter}
\kant
\chapter{A chapter}
\kant
\chapter{A chapter}
\kant
\end{document}
Latex 抱怨! Argument of \begin has an extra }.
什么是使这个工作最好的方法?
答案1
我会采取不同的做法:
\documentclass{book}
\usepackage{etoolbox}
\usepackage{multicol}
\usepackage{titlesec} % Customize chapters and sections
\usepackage{xparse}
\usepackage{kantlipsum}
% Automatically wrap \chapter with \begin and \end multicols
\let\latexchapter\chapter
\newif\iffirst
\appto\mainmatter{\sloppy\global\firsttrue\let\chapter\zendelchapter}
\raggedbottom
\NewDocumentCommand{\zendelchapter}{sO{#3}m}{%
\iffirst\global\firstfalse\else\end{multicols*}\fi
\begin{multicols*}{3}[%
\IfBooleanTF{#1}{\latexchapter*{#3}}{\latexchapter[#2]{#3}}%
]
}
\AtEndDocument{\end{multicols*}}
% Format chapter heading
\titleformat
{\chapter} % command
[display] % shape
{\LARGE} % format
{} % label
{-1.75cm} % horizontal separation between label and title body
{Chapter \thechapter.\quad} % before-code
[] % after-code
\titlespacing{\chapter}{0pt}{50pt}{51.7pt}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{A chapter}
\kant
\chapter{A chapter}
\kant
\chapter{A chapter}
\kant
\end{document}
51.7pt
为了确保章节页面的行数为整数,我们通过反复试验计算出了奇数。
对于较旧的 TeX 发行版,会出现错误
! Illegal parameter number in definition of \zendelchapter
\zendelchapter
可以通过用以下公式替换给定的定义来解决
\NewDocumentCommand{\zendelchapter}{som}{%
\iffirst\global\firstfalse\else\end{multicols*}\fi
\begin{multicols*}{3}[%
\IfBooleanTF{#1}
{%
\latexchapter*{#3}%
}
{%
\IfNoValueTF{#2}
{%
\latexchapter{#3}%
}%
{%
\latexchapter[#2]{#3}%
}%
}%
]
}