我有一份文档,其中段落应在奇数/偶数(左/右)页上对齐。我使用以下代码这答案(礼貌尼古拉·塔尔博特)
\documentclass[12pt]{scrbook}
\usepackage{flowfram}
\usepackage{lipsum}
\usepackage{etoolbox}
% set up frames
\newflowframe{\textwidth}{\textheight}{0pt}{0pt}[main]
\newdynamicframe[odd]{\textwidth}{\textheight}{0pt}{0pt}[details]
\newdynamicframe[even]{\textwidth}{\textheight}{0pt}{0pt}[annote]
% \checkisroom{idl}{text}
\makeatletter
\providecommand{\@gobblethree}[3]{}
\newsavebox\tmpsbox
\newif\ifenoughroom
\newcommand{\checkisroom}[2]{%
\bgroup
% get the frame's idn (stored in \ff@id)
\@dynamicframeid{#1}%
% temporarily suspend writing to external files
\let\protected@write\@gobblethree
% put the frame's contents and the pending text into
% the temporary sbox
\begin{lrbox}{\tmpsbox}%
\begin{minipage}{\textwidth}%
\csname @dynamicframe@\romannumeral\ff@id\endcsname
\par
#2%
\end{minipage}
\end{lrbox}%
% Does it fit the page?
\settoheight{\@ff@tmp@y}{\usebox\tmpsbox}%
\settodepth{\dimen@ii}{\usebox\tmpsbox}%
\addtolength{\@ff@tmp@y}{\dimen@ii}%
\ifdim\@ff@tmp@y>\textheight
\global\enoughroomfalse
\else
\global\enoughroomtrue
\fi
\egroup
}
% \getcontentsheight{length}{text}
\newcommand{\getcontentsheight}[2]{%
\bgroup
\let\protected@write\@gobblethree
\begin{lrbox}{\tmpsbox}%
\begin{minipage}{\textwidth}%
#2%
\end{minipage}%
\end{lrbox}%
\settoheight{\@ff@tmp@y}{\usebox\tmpsbox}%
\settodepth{\dimen@ii}{\usebox\tmpsbox}%
\addtolength{\@ff@tmp@y}{\dimen@ii}%
\global#1=\@ff@tmp@y\relax
\egroup
}
\newcounter{heading}
% \heading{label}{title}
\newcommand{\heading}[2]{%
\refstepcounter{heading}%
\label{#1}%
\markboth{#2}{#2}%
\annote
{%
\section*{\ref{#1}. #2}%
}%
{%
\section*{\ref{#1}. #2}%
\addcontentsline{toc}{section}{#2}%
\par\strut
}%
\afterheadingtrue
}
\newif\ifafterheading
\newlength\blockheight
\newcommand{\blocksep}{\par\vspace{2ex}}
% \annote{annotation}{text}
\newcommand{\annote}[2]{%
\getcontentsheight{\blockheight}{#1}%
\def\largerblock{#1}%
\getcontentsheight{\@ff@tmp@y}{#2}%
\ifdim\blockheight<\@ff@tmp@y
\blockheight=\@ff@tmp@y\relax
\def\largerblock{#2}%
\fi
\ifafterheading
\edef\startblock{%
\noexpand\blocksep
\noexpand\begin{minipage}[t][\the\blockheight]{\the\textwidth}%
\noexpand\setlength{\noexpand\parindent}{\the\parindent}%
\noexpand\par\noexpand\noindent
}%
\afterheadingfalse
\else
\edef\startblock{%
\noexpand\begin{minipage}[t][\the\blockheight]{\the\textwidth}%
\noexpand\setlength{\noexpand\parindent}{\the\parindent}%
\noexpand\par\noexpand\indent
}%
\fi
\checkisroom{details}{\largerblock}%
\ifenoughroom
\@dynamicframeid{annote}%
\expandafter\appenddynamiccontents\expandafter\ff@id
\expandafter{%
\expandafter\blocksep
\startblock
#1%
\end{minipage}}%
\@dynamicframeid{details}%
\expandafter\appenddynamiccontents\expandafter\ff@id
\expandafter{%
\expandafter\blocksep
\startblock
#2%
\end{minipage}}%
\else
% output 2 pages
\cleartoeven
\@dynamicframeid{annote}%
\expandafter\setdynamiccontents\expandafter\ff@id
\expandafter{\startblock#1\end{minipage}}%
\@dynamicframeid{details}%
\expandafter\setdynamiccontents\expandafter\ff@id
\expandafter{\startblock#2\end{minipage}}%
\fi
}
\makeatother
\newcommand{\cleartoeven}{%
\ifthispageodd % KOMA command
{\newpage}%
{\mbox{}\newpage\mbox{}\newpage}%
}
\appto\tableofcontents{\cleartoeven}
\AtEndDocument{\cleartoeven}
\title{Sample Document}
\author{A.N. Other}
\begin{document}
\maketitle
\tableofcontents
\heading{sample}{Sample Heading}
\annote
{Annotation on the left}
{A longer paragraph on the right matching the annotation on the
left.
\lipsum[1]
}
\heading{sample2}{Another Sample Heading}
\annote
{\lipsum[2]}
{\lipsum[3]}
\annote
{Another annotation.}
{\lipsum[4]}
\annote
{\lipsum[5-6]}
{\lipsum[7]}
\end{document}
我有两个未能解决的问题:
- 我喜欢在新页面开始每个标题。我尝试了
cleartoeven
很多不同的方法,但都失败了。在特定情况下和/或在文档的其他部分,我该如何实现这一点? - 是否可以将第一个/第二个参数作为
\heading{}{}
左/右页的页眉?目前,奇数/偶数页的页眉上均显示一个参数。
为了澄清:我使用此代码进行翻译工作,其中原文在左边,翻译版本在右边。
答案1
以下 MWE 使每个\heading{
标签}{
标题}
清除跨页,这解决了第一个问题。页眉的设置方法是使用\markboth{
标题}{
标题}
,我没有对原始 MWE 进行任何更改,但是现在它\heading
总是开始一个新页面,页眉不会因为\heading
在同一个双页跨页上有多个而混淆,所以希望这可以解决您的第二个问题。
\documentclass[12pt]{scrbook}
\usepackage{flowfram}
\usepackage{lipsum}
\usepackage{etoolbox}
% set up frames
\newflowframe{\textwidth}{\textheight}{0pt}{0pt}[main]
\newdynamicframe[odd]{\textwidth}{\textheight}{0pt}{0pt}[details]
\newdynamicframe[even]{\textwidth}{\textheight}{0pt}{0pt}[annote]
% \checkisroom{idl}{text}
\makeatletter
\providecommand{\@gobblethree}[3]{}
\newsavebox\tmpsbox
\newif\ifenoughroom
\newcommand{\checkisroom}[2]{%
\bgroup
% get the frame's idn (stored in \ff@id)
\@dynamicframeid{#1}%
% temporarily suspend writing to external files
\let\protected@write\@gobblethree
% put the frame's contents and the pending text into
% the temporary sbox
\begin{lrbox}{\tmpsbox}%
\begin{minipage}{\textwidth}%
\csname @dynamicframe@\romannumeral\ff@id\endcsname
\par
#2%
\end{minipage}
\end{lrbox}%
% Does it fit the page?
\settoheight{\@ff@tmp@y}{\usebox\tmpsbox}%
\settodepth{\dimen@ii}{\usebox\tmpsbox}%
\addtolength{\@ff@tmp@y}{\dimen@ii}%
\ifdim\@ff@tmp@y>\textheight
\global\enoughroomfalse
\else
\global\enoughroomtrue
\fi
\egroup
}
% \getcontentsheight{length}{text}
\newcommand{\getcontentsheight}[2]{%
\bgroup
\let\protected@write\@gobblethree
\begin{lrbox}{\tmpsbox}%
\begin{minipage}{\textwidth}%
#2%
\end{minipage}%
\end{lrbox}%
\settoheight{\@ff@tmp@y}{\usebox\tmpsbox}%
\settodepth{\dimen@ii}{\usebox\tmpsbox}%
\addtolength{\@ff@tmp@y}{\dimen@ii}%
\global#1=\@ff@tmp@y\relax
\egroup
}
\newcounter{heading}
% \heading{label}{title}
\newcommand{\heading}[2]{%
\cleartoeven
\setdynamiccontents*{annote}{}%
\setdynamiccontents*{details}{}%
\refstepcounter{heading}%
\label{#1}%
\markboth{#2}{#2}%
\annote
{%
\section*{\ref{#1}. #2}%
}%
{%
\section*{\ref{#1}. #2}%
\addcontentsline{toc}{section}{#2}%
\par\strut
}%
\afterheadingtrue
}
\newif\ifafterheading
\newlength\blockheight
\newcommand{\blocksep}{\par\vspace{2ex}}
% \annote{annotation}{text}
\newcommand{\annote}[2]{%
\getcontentsheight{\blockheight}{#1}%
\def\largerblock{#1}%
\getcontentsheight{\@ff@tmp@y}{#2}%
\ifdim\blockheight<\@ff@tmp@y
\blockheight=\@ff@tmp@y\relax
\def\largerblock{#2}%
\fi
\ifafterheading
\edef\startblock{%
\noexpand\blocksep
\noexpand\begin{minipage}[t][\the\blockheight]{\the\textwidth}%
\noexpand\setlength{\noexpand\parindent}{\the\parindent}%
\noexpand\par\noexpand\noindent
}%
\afterheadingfalse
\else
\edef\startblock{%
\noexpand\begin{minipage}[t][\the\blockheight]{\the\textwidth}%
\noexpand\setlength{\noexpand\parindent}{\the\parindent}%
\noexpand\par\noexpand\indent
}%
\fi
\checkisroom{details}{\largerblock}%
\ifenoughroom
\@dynamicframeid{annote}%
\expandafter\appenddynamiccontents\expandafter\ff@id
\expandafter{%
\expandafter\blocksep
\startblock
#1%
\end{minipage}}%
\@dynamicframeid{details}%
\expandafter\appenddynamiccontents\expandafter\ff@id
\expandafter{%
\expandafter\blocksep
\startblock
#2%
\end{minipage}}%
\else
% output 2 pages
\cleartoeven
\@dynamicframeid{annote}%
\expandafter\setdynamiccontents\expandafter\ff@id
\expandafter{\startblock#1\end{minipage}}%
\@dynamicframeid{details}%
\expandafter\setdynamiccontents\expandafter\ff@id
\expandafter{\startblock#2\end{minipage}}%
\fi
}
\makeatother
\newcommand{\cleartoeven}{%
\ifthispageodd % KOMA command
{\newpage}%
{\mbox{}\newpage\mbox{}\newpage}%
}
\AtEndDocument{\cleartoeven}
\title{Sample Document}
\author{A.N. Other}
\begin{document}
\maketitle
\tableofcontents
\heading{sample}{Sample Heading}
\annote
{Annotation on the left}
{A longer paragraph on the right matching the annotation on the
left.
\lipsum[1]
}
\heading{sample2}{Another Sample Heading}
\annote
{\lipsum[2]}
{\lipsum[3]}
\annote
{Another annotation.}
{\lipsum[4]}
\annote
{\lipsum[5-6]}
{\lipsum[7]}
\end{document}
第一个跨页(第 4 页和第 5 页):
第二个跨页(第 6 页和第 7 页):