I've set up my LaTeX document to repeat the current chapter heading on every left hand page, and place whitespace on the right hand page for alignment reasons. To do this I have used EveryShipout.
I have sections of my document that I need to put in boxes, with a dashed border around the edge. Sometimes these boxes can be very long, spanning multiple pages. When this happens, my headings don't get inserted. I have a macro called \custompageheader
that I can use to display my header at any time, and I'd like for a way to call this macro every time my breakable box breaks. Additionally, I need the positioning of the header to be consistent with the rest of my document, so the header must appear outside of the box.
Is it possible to achieve this? I've looked through the tcolorbox documentation and seen several potentially helpful items, but none of them have quite done the job.
/tcb/underlay
would render my title within the tcolorbox/tcb/overlay
has the same issueI think
/tcb/finish
have the same issue/tcb/before
has the same issue/tcb/extras
possibly, but I can't see to output text from within an extra/tcb/frame code pre
seems promising, but I can't get it to work
My code is below:
% 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 UPDATE:
I took a bit of a break from this project, but I'd really like to finish it and this issue is standing in my way. Just to summarise and elaborate on the progress I've made in the comments, I've now put my headings inside the memoir
header system using \makeoddhead
and \makeevenhead
. This has the improvement that my headings now show up on every page, but it seems that Memoir requires headings to be a constant size and can't size them based on the contents. When a new chapter starts, I want my header to disappear and simply to use the \chapter{My heading}
block to render my text, and the fixed height requirement prevents this. In order to compensate, I now render my headers twice, once in memoir
which visually displays the header, and a second time in EveryShi
, but invisible, which I just use for spacing. My current code is here:
% 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}
The issue with this is that EveryShipout still doesn't run in the middle of a tcolorbox, so on subsequent pages my heading renders behind the tcolorbox:
The nice thing here is that I know that on a page that starts partway through a tcolorbox, the header will always have the same size. So all I need to do is make the tcolorbox on subsequent pages start a bit lower down. I tried a suggestion from Ulrike Fischer in the comments to use topsep at break=3cm
but that didn't quite have the right effect:
Anyway, I'd really appreciate any help people can give. Thanks!
memoir
andtcolorbox
shows me that broken tcolorboxes respectnormal
headers and footers. So, I imagine that the problem appears because you don't use them and forces/breaks page geometry withEveryShipout
.topsep at break=3cm
, and you could adapt the skins of the middle and last parts to get the correct frames and use overlay to insert your chapter heading (it hasn't problem to draw something outside a frame, but you are inside anyway). But imho it would be much more saner and easier to do as Ignasi suggested and to enlarge the headers if you want this whitespace everywhere anyway.memoir
documentation explains how to define your own headers and footers, and also how to define page geometry with ownmemoir
commands, and ...topsep at break=3cm
you suggested to work though. It lowers the text content of the frame by 3cm, but the border and background still start at the same position. Is there a way I can add vertical spacing before the frame? i.imgur.com/maw0tyr.png