我目前正在用 LaTeX 和 LyX 开发一个图书项目,发现了一个奇怪的错误,它似乎崩溃 LaTeX。我不知道如何解决该崩溃问题,所以我想在这里寻求帮助。
简而言之:我使用KOMA 脚本类scrbook
创建一个 A4 大小的文档,并希望设置边注与正文一起。我阅读了大量有关不同程序的资料,并决定尝试该scrlayer-notecolumn
软件包以避免其他方法的缺点。
为了更清楚起见,我希望能够缩进所有常规段落,但章节和节标题不缩进。我已经设法设置了这一点(但如果需要以不同的方式完成,我愿意听取建议)。以下是类文件的 MWE:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{MyBook}[2016/10/01 My Book Class]
% General setup
\RequirePackage{blindtext}
\RequirePackage{leading}
\RequirePackage{calc}
\RequirePackage{color}
\definecolor{orange}{rgb}{1.0, 0.5, 0.0}
\newcommand\pagedividers{14}
% Page Layout
\LoadClass[
a4paper,
twoside,
titlepage,
fontsize = 9pt,
parskip = full,
headings = small,
index = totoc,
listof = totoc,
bibliography = totoc,
numbers = noenddot,
appendixprefix = true,
captions = nooneline
]{scrbook}
\RequirePackage{geometry}
\geometry{
reversemarginpar,
inner = 21cm / \pagedividers,
outer = 21cm / \pagedividers * 2,
top = 29.7cm / \pagedividers,
bottom = 29.7cm / \pagedividers,
heightrounded
}
% Use scrlayer-scrpage, so that package notecolumn works
\RequirePackage[
plainheadsepline,
plainfootsepline,
]{scrlayer-scrpage}
% Set up the note column
\RequirePackage{scrlayer-notecolumn}
\RequirePackage{scrextend}
\newlength{\completemargin}
\setlength{\completemargin}{4.125cm}
\newlength{\notescolwidth}
\setlength{\notescolwidth}{\completemargin - \marginparsep}
\DeclareNewNoteColumn[
marginpar,
position = \ifthispageodd{\oddsidemargin + 1in}{\evensidemargin + 1in},
width = \notescolwidth,
font = \raggedright\footnotesize\color{orange}
]{notes}
% Indent the paragraphs, lists, equations and subsections
\RequirePackage{enumitem}
\setlength{\leftskip}{\completemargin}
\setlist[itemize]{leftmargin = \completemargin}
\setlist[enumerate]{leftmargin = \completemargin}
\setlist[description]{leftmargin = \completemargin + 1cm, labelindent = \completemargin}
\addtokomafont{subsubsection}{\setlength{\leftskip}{\completemargin}}
\addtokomafont{paragraph}{\setlength{\leftskip}{\completemargin}}
\addtokomafont{subparagraph}{\setlength{\leftskip}{\completemargin}}
\RequirePackage[fleqn]{amsmath}
\setlength{\mathindent}{\completemargin + 1cm}
下面是用于测试布局的示例文件:
\documentclass[english]{MyBook}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{babel}
\begin{document}
\chapter{Chapter Heading}
\Blindtext[2]
\section{Section Heading}
\makenote[notes]{Here's a note for the new note column. Just for testing purposes.}\Blindtext[4]
\subsection{Sub Section Heading}
\makenote[notes]{Here's a note for the new note column. Just for testing purposes.}\Blindtext[3]
\end{document}
当然,这会导致布局不对称。这就是我的问题所在:
注释列(notes
在上面的例子中)需要位于正文的左侧,无论是奇数页还是偶数页。由于外边距和内边距不同,我需要一种方法来检查我在奇数页还是偶数页上设置注释列的位置。我按照建议使用\ifthispageodd
from package来做到这一点scrextend
。
然而,导致 LaTeX 崩溃(或者 pdflatex,从 LyX 调用时)。
我真的不知道该如何解决这个问题。如果我删除\ifthispageodd
并使用,例如,\oddsidemargin
页面看起来会像这样:
那么,还有其他方法可以检查奇数页或偶数页吗?或者是否有命令可用于读出当前页面的实际左边距(而不是\oddsidemargin
上面的 MWE)。或者我应该使用不同的程序来设置注释列?任何帮助都将不胜感激。
哦,顺便说一句:如果有人知道如何对齐注释栏中注释的基线与正文一致,我也会很高兴。
答案1
\Ifthispageodd
¹ 使用与设置和引用标签非常相似的机制。这可能是它崩溃的原因。但是当初始化图层页面样式(用于注释列)时,正确的页码是已知的。因此您可以使用
position = \ifodd\value{page}
\dimexpr 1in+\oddsidemargin \relax
\else
\dimexpr 1in+\evensidemargin \relax
\fi
请注意,加载包时不需要\dimexpr
和。\relax
calc
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{MyBook}[2016/10/01 My Book Class]
% General setup
\RequirePackage{blindtext}% only for dummy text
\RequirePackage{leading}
\RequirePackage{calc}
\RequirePackage{color}
\definecolor{orange}{rgb}{1.0, 0.5, 0.0}
\newcommand\pagedividers{14}
% Page Layout
\LoadClass[
a4paper,
twoside,
titlepage,
fontsize = 9pt,
parskip = full,
headings = small,
index = totoc,
listof = totoc,
bibliography = totoc,
numbers = noenddot,
appendixprefix = true,
captions = nooneline
]{scrbook}
\RequirePackage{geometry}
\geometry{
reversemarginpar,
inner = \paperwidth / \pagedividers,
outer = \paperwidth / \pagedividers * 2,
top = \paperheight / \pagedividers,
bottom = \paperheight / \pagedividers,
heightrounded
}
% Use scrlayer-scrpage, so that package notecolumn works
\RequirePackage[
plainheadsepline,
plainfootsepline,
]{scrlayer-scrpage}
% Set up the note column
\RequirePackage{scrlayer-notecolumn}
\newlength{\completemargin}
\setlength{\completemargin}{4.125cm}
\newlength{\notescolwidth}
\setlength{\notescolwidth}{\completemargin - \marginparsep}
\DeclareNewNoteColumn[
marginpar,
position = \ifodd \value{page} 1in+\oddsidemargin \else 1in+\evensidemargin \fi,
width = \notescolwidth,
font = \raggedright\footnotesize\color{orange}
]{notes}
% Indent the paragraphs, lists, equations and subsections
\RequirePackage{enumitem}
\setlength{\leftskip}{\completemargin}
\setlist[itemize]{leftmargin = \completemargin}
\setlist[enumerate]{leftmargin = \completemargin}
\setlist[description]{leftmargin = \completemargin + 1cm, labelindent = \completemargin}
\RedeclareSectionCommands[
indent=\completemargin
]{subsubsection,paragraph,subparagraph}
\RequirePackage[fleqn]{amsmath}
\setlength{\mathindent}{\completemargin + 1cm}
请注意我已经习惯改变等的\RedeclareSectionCommands
缩进。subsubsection
\documentclass[english]{MyBook}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{babel}
\begin{document}
\chapter{Chapter Heading}
\Blindtext[2]
\section{Section Heading}
\leavevmode\makenote[notes]{Here's a note for the new note column. Just for testing purposes.}
\Blindtext[4]
\subsection{Sub Section Heading}
\leavevmode\makenote[notes]{Here's a note for the new note column. Just for testing purposes.}
\Blindtext[3]
\end{document}
¹ 从 KOMA-Script 3.28 版开始\ifthispageodd
被 取代\Ifthispageodd
。