我已经将 LaTeX 文档设置为在左侧的每一页重复当前章节标题,并在右侧页面上留出空白以便对齐。为此,我使用了 EveryShipout。
我需要将文档中的某些部分放入框中,并在框的边缘添加虚线边框。有时这些框可能很长,跨越多页。当发生这种情况时,我的标题无法插入。我有一个名为的宏,\custompageheader
可以随时显示标题,我希望每次可拆分框拆分时都能调用此宏。此外,我需要将标题的定位与文档的其余部分保持一致,因此标题必须出现在框的外面。
有可能实现吗?我查看了 tcolorbox 文档并看到了几个可能有用的项目,但它们都没有完成工作。
/tcb/underlay
将在 tcolorbox 中呈现我的标题/tcb/overlay
有同样的问题我认为
/tcb/finish
有同样的问题/tcb/before
有同样的问题/tcb/extras
可能,但我看不到在额外的/tcb/frame code pre
看起来很有希望,但我无法让它发挥作用
我的代码如下:
% IMPORTANT: To build, run XeLaTeX twice!
\documentclass[twoside]{memoir}
\usepackage[papersize={8.5in,11in}, vmargin=0.5in, outer=1in, inner=0.5in, includehead, includefoot]{geometry}
\usepackage{color}
\usepackage{fontspec}
\usepackage{xifthen}
\usepackage{ifoddpage}
\usepackage{newunicodechar}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{everyshi}% http://ctan.org/pkg/everyshi
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage[none]{hyphenat}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{fp}
\usepackage{xparse}
\usepackage[skins,breakable]{tcolorbox}
\usepackage{tikz}
\graphicspath{ {images/} }
\tracingpatches
\setmainfont{OpenSans}
\newfontfamily{\fallbackfont}{Arial}
\DeclareTextFontCommand{\textfallback}{\fallbackfont}
\newunicodechar{█}{\textfallback{█}}
\makeatletter
\widowpenalty10000
\clubpenalty10000
\makechapterstyle{mychapterstyle}{
% Remove 'Chapter 1' from beginning of chapters
\renewcommand\@makechapterhead[1]{%
\chapterheadstart% \vspace*{50\p@}%
{%\parindent \z@ \raggedright \normalfont
%\parskip \z@
\parindent \z@ \memRTLraggedright \normalfont%
\printchaptertitle{##1}% \Huge \bfseries #1
\afterchaptertitle% \par\nobreak \vskip 40\p@
}
}
\setlength{\afterchapskip} {10pt}% Reduce spacing after headings
% Remove spacing before chapter titles
\renewcommand\chapterheadstart {}
%\setlength{\beforechapskip}{0pt} % Doesn't work
% Allow new chapter to start on right side page
\renewcommand\clearforchapter{
\clearpage
}
}
\NewEnviron{blockquote}{
\par
%\begin{tikzpicture}
%\node[rectangle,minimum width=0.9\textwidth] (m) {%
\centering{
\begin{tcolorbox}[blanker, breakable,
skin=freelance,
boxsep=5pt,
borderline={0mm}{0mm}{black!80!white,dashed},
width=0.9\textwidth,
every float={%
ggggggggggggggggggggggggggggggg\custompageheader%
}
]%
\BODY%
\end{tcolorbox}%
}
%};
%\draw[dashed] (m.south west) rectangle (m.north east);
%\end{tikzpicture}
}
% Repeating headings (based on http://tex.stackexchange.com/questions/47646/re-displaying-section-headings-after-page-breaks)
\let\@section@title@\relax% Section heading storage
\newcommand{\beginsection}[1]{%
\let\@section@title@\relax%
\normalfont\secheadstyle #1%
\normalfont\normalsize%
\par%
\vspace{0.5pt}% Required for vertical alignment, not quite sure why it's necessary
%
\gdef\@section@title@{#1}%
}
\newcommand{\begindocument}[1]{%
\let\@section@title@\relax%
\newpage%
\custompageheader%
\beginsection{#1}%
}
\makepagestyle{headings} {} % Disable default Memoir repeated headings, we'll make our own
\definecolor{grey}{gray}{0.8}
\definecolor{invis}{gray}{1}
\newcommand\custompageheader{
\begingroup\let\protect\@typeset@protect
\checkoddpage
\ifoddpage
{
\textcolor{grey}{\chaptitlefont\f@rhdr\ (cont'd.)}% Reprint chapter header
}
\else
{
\textcolor{invis}{\chaptitlefont\f@rhdr\ (cont'd.)}% Header not displayed but still present for spacing reasons
}
\fi
\afterchaptertitle
\@afterheading
\vspace{5pt} % Required for vertical alignment, not quite sure why it's necessary
\if\relax\@section@title@%
\relax
\else%
\@tempskipa \beforesecskip\relax%
\ifoddpage
{\textcolor{grey}{\normalfont\secheadstyle \@section@title@\ (cont'd.)}}% Reprint chapter header
\else
{\textcolor{invis}{\normalfont\secheadstyle \@section@title@\ (cont'd.)}}% Header not displayed but still present for spacing reasons
\fi
\fi%
\vspace{7pt}
\endgroup
}
\EveryShipout{%
\ifdim\pagetotal>\pagegoal% There is content overflow on this page
\custompageheader%
\fi%
}
\makeatother
%\raggedright
\setlength{\parindent}{0pt}%
\nonzeroparskip
\begin{document}
\chapterstyle{mychapterstyle}
\chapter{My Document}
\beginsection{Normal content}
\lipsum[10-29]
\beginsection{Transcript}
\begin{blockquote}
\lipsum[30-54]
\end{blockquote}
\end{document}
2017 年更新:
我在这个项目上休息了一段时间,但我真的很想完成它,而这个问题阻碍了我的工作。为了总结和详细说明我在评论中取得的进展,我现在使用和将标题放在memoir
标题系统中。这有所改进,我的标题现在显示在每一页上,但似乎回忆录要求标题具有恒定大小,而不能根据内容调整大小。当新的章节开始时,我希望我的标题消失并简单地使用块来呈现我的文本,而固定高度要求阻止了这一点。为了补偿,我现在渲染两次标题,一次在以可视方式显示标题,第二次在但不可见的中,我只是用它来留出间距。我当前的代码在这里:\makeoddhead
\makeevenhead
\chapter{My heading}
memoir
EveryShi
% IMPORTANT: To build, run XeLaTeX twice!
\documentclass[twoside]{memoir}
\usepackage[papersize={8.5in,11in}, vmargin=0.5in, outer=1in, inner=0.5in, head=0in, includehead, includefoot]{geometry}
\usepackage{color}
\usepackage{fontspec}
\usepackage{xifthen}
\usepackage{ifoddpage}
\usepackage{newunicodechar}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{everyshi}% http://ctan.org/pkg/everyshi
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage[none]{hyphenat}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{fp}
\usepackage{xparse}
\usepackage[skins,breakable]{tcolorbox}
\usepackage{tikz}
\usepackage{pgf}
\graphicspath{ {images/} }
\tracingpatches
\setmainfont{OpenSans}
\newfontfamily{\fallbackfont}{Arial}
\DeclareTextFontCommand{\textfallback}{\fallbackfont}
\newunicodechar{█}{\textfallback{█}}
\makeatletter
\widowpenalty10000
\clubpenalty10000
\makechapterstyle{mychapterstyle}{
% Remove 'Chapter 1' from beginning of chapters
\renewcommand\@makechapterhead[1]{%
\chapterheadstart% \vspace*{50\p@}%
{%\parindent \z@ \raggedright \normalfont
%\parskip \z@
\parindent \z@ \memRTLraggedright \normalfont%
\printchaptertitle{##1}% \Huge \bfseries #1
\afterchaptertitle% \par\nobreak \vskip 40\p@
}
}
\setlength{\afterchapskip} {10pt}% Reduce spacing after headings
% Remove spacing before chapter titles
\renewcommand\chapterheadstart {}
%\setlength{\beforechapskip}{0pt} % Doesn't work
% Allow new chapter to start on right side page
\renewcommand\clearforchapter{
\clearpage
}
}
\NewEnviron{blockquote}{
\par
%\begin{tikzpicture}
%\node[rectangle,minimum width=0.9\textwidth] (m) {%
\centering{
\begin{tcolorbox}[blanker, breakable,
skin=freelance,
boxsep=5pt,
borderline={0mm}{0mm}{black!80!white,dashed},
width=0.9\textwidth,
extras middle and last={before skip=45pt}
]%
\BODY%
\end{tcolorbox}%
}
%};
%\draw[dashed] (m.south west) rectangle (m.north east);
%\end{tikzpicture}
}
% Repeating headings (based on http://tex.stackexchange.com/questions/47646/re-displaying-section-headings-after-page-breaks)
\let\@section@title@\relax% Section heading storage
\newcommand{\beginsection}[1]{%
\let\@section@title@\relax%
\normalfont\secheadstyle #1%
\normalfont\normalsize%
\par%
\vspace{0.5pt}% Required for vertical alignment, not quite sure why it's necessary
%
\gdef\@section@title@{#1}%
}
\newcommand{\begindocument}[1]{%
\let\@section@title@\relax%
\newpage%
\custompageheader%
\beginsection{#1}%
}
\makepagestyle{headings} {} % Disable default Memoir repeated headings, we'll make our own
\definecolor{grey}{gray}{0.8}
\definecolor{invis}{gray}{1}
\newcommand\myheader[1]{%
\begingroup\let\protect\@typeset@protect%
\pgfsetfillopacity{#1}%
\textcolor{gray}{\chaptitlefont\f@rhdr\ (cont'd.)}% Reprint chapter header
\pgfsetfillopacity{0}%
\afterchaptertitle
\@afterheading
\vspace{5pt} % Required for vertical alignment, not quite sure why it's necessary
\if\relax\@section@title@%
\relax
\else%
\@tempskipa \beforesecskip\relax%
\pgfsetfillopacity{#1}%
\textcolor{gray}{\normalfont\secheadstyle \@section@title@\ (cont'd.)}% Reprint chapter header
\pgfsetfillopacity{1}%
\fi%
\vspace{7pt}
\endgroup
}
\newcommand\headervspace{%
\par%
\vspace{5pt}%
}
\EveryShipout{%
\ifdim\pagetotal>\pagegoal% There is content overflow on this page
\myheader{0}%
\fi%
}
%\makepagestyle{scpbookpage}
\makeoddhead{headings}{\headervspace\myheader{1}}{}{}
\makeevenhead{headings}{\headervspace\myheader{0}}{}{}
\makeatother
%\raggedright
\setlength{\parindent}{0pt}%
\nonzeroparskip
\begin{document}
\chapterstyle{mychapterstyle}
\chapter{My Document}
\beginsection{Normal content}
\lipsum[10-29]
\beginsection{Transcript}
\begin{blockquote}
\lipsum[30-54]
\end{blockquote}
\end{document}
问题在于 EveryShipout 仍然无法在 tcolorbox 中间运行,因此在后续页面上我的标题会在 tcolorbox 后面呈现:
这里的好处是,我知道在从 tcolorbox 中途开始的页面上,标题将始终具有相同的大小。所以我需要做的就是让后续页面上的 tcolorbox 开始得稍微低一些。我尝试使用 Ulrike Fischer 在评论中的建议,topsep at break=3cm
但效果不太好:
无论如何,我非常感激大家能给予的任何帮助。谢谢!
答案1
我原本想把这个问题提交上来获取赏金,但后来我想到了一个解决方案。虽然不太好懂,但确实管用。
我不会重新解释我针对我的问题的评论所做的更改,因此如果您遇到类似的问题并试图解决,请阅读我的问题的“2017 更新”部分,以了解我已经做出的更改。
从那时起,我所做的更改基本上就是在每页的顶部添加了 65pt 的固定边距。然后,在我用于间距的 EveryShipout 代码中,我应用负 vspace 来否定此边距。这允许我根据页面是否是新章节的开始来自定义标题大小,但它也利用了这样一个事实:如果页面以 tcolorbox 的延续开始,那么它保证具有最大尺寸的标题。
更新的代码:
% IMPORTANT: To build, run XeLaTeX twice!
\documentclass[twoside]{memoir}
\usepackage[papersize={8.5in,11in}, vmargin=0.5in, outer=1in, inner=0.5in, head=65pt, includehead, includefoot]{geometry}
\usepackage{color}
\usepackage{fontspec}
\usepackage{xifthen}
\usepackage{ifoddpage}
\usepackage{newunicodechar}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{everyshi}% http://ctan.org/pkg/everyshi
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage[none]{hyphenat}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{fp}
\usepackage{xparse}
\usepackage[skins,breakable]{tcolorbox}
\usepackage{tikz}
\usepackage{pgf}
\graphicspath{ {images/} }
\tracingpatches
\setmainfont{OpenSans}
\newfontfamily{\fallbackfont}{Arial}
\DeclareTextFontCommand{\textfallback}{\fallbackfont}
\newunicodechar{█}{\textfallback{█}}
\makeatletter
\widowpenalty10000
\clubpenalty10000
\makechapterstyle{mychapterstyle}{
% Remove 'Chapter 1' from beginning of chapters
\renewcommand\@makechapterhead[1]{%
\vspace*{-91pt}
\chapterheadstart% \vspace*{50\p@}%
{%\parindent \z@ \raggedright \normalfont
%\parskip \z@
\parindent \z@ \memRTLraggedright \normalfont%
\printchaptertitle{##1}% \Huge \bfseries #1
\afterchaptertitle% \par\nobreak \vskip 40\p@
}
}
\setlength{\afterchapskip} {10pt}% Reduce spacing after headings
% Remove spacing before chapter titles
\renewcommand\chapterheadstart {}
%\setlength{\beforechapskip}{0pt} % Doesn't work
% Allow new chapter to start on right side page
\renewcommand\clearforchapter{
\clearpage
}
}
\NewEnviron{blockquote}{
\par%
%\begin{tikzpicture}
%\node[rectangle,minimum width=0.9\textwidth] (m) {%
\centering{
\begin{tcolorbox}[blanker, breakable,
skin=freelance,
boxsep=5pt,
borderline={0mm}{0mm}{black!80!white,dashed},
width=0.9\textwidth,
extras middle and last={before skip=45pt}
]%
\BODY%
\end{tcolorbox}%
}
%};
%\draw[dashed] (m.south west) rectangle (m.north east);
%\end{tikzpicture}
}
% Repeating headings (based on http://tex.stackexchange.com/questions/47646/re-displaying-section-headings-after-page-breaks)
\let\@section@title@\relax% Section heading storage
\newcommand{\beginsection}[1]{%
\let\@section@title@\relax%
\normalfont\secheadstyle #1%
\normalfont\normalsize%
\par%
\vspace{8.5pt}% Required for vertical alignment, not quite sure why it's necessary
%
\gdef\@section@title@{#1}%
}
\newcommand{\begindocument}[1]{%
\let\@section@title@\relax%
\newpage%
\custompageheader%
\beginsection{#1}%
}
\makepagestyle{headings} {} % Disable default Memoir repeated headings, we'll make our own
\definecolor{grey}{gray}{0.8}
\definecolor{invis}{gray}{1}
\newcommand\myheader[1]{%
\begingroup\let\protect\@typeset@protect%
\pgfsetfillopacity{#1}%
\textcolor{gray}{\chaptitlefont\f@rhdr\ (cont'd.)}% Reprint chapter header
\pgfsetfillopacity{0}%
\afterchaptertitle
\@afterheading
\vspace{5pt} % Required for vertical alignment, not quite sure why it's necessary
\if\relax\@section@title@%
\relax
\else%
\@tempskipa \beforesecskip\relax%
\pgfsetfillopacity{#1}%
\textcolor{gray}{\normalfont\secheadstyle \@section@title@\ (cont'd.)}% Reprint chapter header
\pgfsetfillopacity{1}%
\fi%
\vspace{15pt}%
\endgroup%
}
\newcommand\headervspace{%
\par%
\vspace{5pt}%
}
\EveryShipout{%
\ifdim\pagetotal>\pagegoal% There is content overflow on this page
\begingroup\let\protect\@typeset@protect%
\vspace*{-75pt}%
\endgroup%
\myheader{0}%
\fi%
}
%\makepagestyle{scpbookpage}
\makeoddhead{headings}{\headervspace\myheader{1}}{}{}
\makeevenhead{headings}{\headervspace\myheader{0}}{}{}
\makeatother
%\raggedright
\setlength{\parindent}{0pt}%
\nonzeroparskip
\begin{document}
\chapterstyle{mychapterstyle}
\chapter{My Document}
\beginsection{Normal content}
\lipsum[10-29]
\beginsection{Transcript}
\begin{blockquote}
\lipsum[30-54]
\end{blockquote}
\end{document}