0

So I am editing a historical manuscript, and I want the original page numbers of the handwritten manuscript to appear in the running head, both on the left and the right pages. As well, they also need to appear in the text, at the start of each original page (which can be anywhere on the printed page).

I implemented this using a command called \origpage which prints the original page number and executes a \markboth command to change the header.

So far so good. Except that sometimes the original page number appears within a table (rendered with \longtable) or at the beginning of a box (rendered with \tcolorbox). In these cases, the \markboth command somehow doesn’t manage to “reach” the running head, apparently because it’s encased in the \tcolorbox or \longtable environment. The \markboth command works when encased in a blank environment, though, so it’s not the environment per se that blocks its effect.

The MWE here shows only the \tcolorbox case. If you compile the code, you will see that first ten original pages create the running head correctly, but then the eleventh and twelfth original pages fail, but the thirteenth and fourteenth work again.

Why is this failing?

Can anybody help me figure out a way to get the original page numbers up in the running head even from within a \tcolorbox or \longtable? Would using \fancyhdr help?

% !TEX TS-program = lualatex
% !TEX encoding = UTF-8 Unicode
% !TEX spellcheck = en_EN

\documentclass[letterpaper,12pt]{book}
\usepackage[english]{babel}
\usepackage{fontspec}

\usepackage{lipsum}

\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\newcommand{\origpage}[1]{%
   {\textsf{\large{[#1.]}}}%
   \markboth{\hfill #1 \hfill}{\hfill #1 \hfill}
}

% +++++++++++++++++++++++++++++++++++++++++++

\begin{document}

\pagenumbering{gobble}

\origpage{1} \lipsum \lipsum \origpage{2} \lipsum \lipsum \origpage{3} \lipsum \lipsum \origpage{4} \lipsum \lipsum \origpage{5} \lipsum \lipsum \origpage{6} \lipsum \lipsum \origpage{7} \lipsum \lipsum \origpage{8} \lipsum \lipsum \origpage{9} \lipsum \lipsum \origpage{10} \lipsum \lipsum 

\begin{tcolorbox}[width=\linewidth,valign=center,breakable]
\origpage{11} \lipsum \lipsum \origpage{12} \lipsum \lipsum
\end{tcolorbox}

\origpage{13} \lipsum \lipsum \origpage{14} \lipsum \lipsum

\end{document}
5
  • 1
    marks have to be at the top level to be seen by the page breaker. even a simple \mbox is enough to stop that working. however longtable should work as long as you do it in a c l or r column, a p column can not work as it generates a \parbox Nov 22, 2021 at 15:17
  • Indeed the custom page numbers I had put inside longtable are in p columns. I'll have to try the c-l-r approach.
    – 35royan2
    Nov 22, 2021 at 15:41
  • 1
    tcolorbox could probably restore marks similar to multicol, but that something the package will have to do. Nov 22, 2021 at 16:14
  • For longtable, the c-l-r approach indeed fixes the \markboth problem. But I need to set the column widths in the table and using p columns is the only way to do that, isn't it?
    – 35royan2
    Nov 22, 2021 at 19:54
  • See also tex.stackexchange.com/questions/516938/… Nov 22, 2021 at 23:27

1 Answer 1

0

I ultimately solved the problem, and got the output I wanted, with two nasty workarounds. But they will not work for all cases.

With the \longtable environment: I just ended the longtable, typeset the original page number (so that the resulting \markboth is at the top level), and restarted the table. This was not what I wanted as a document designer, but it is not a disaster either.

With the \tcolorbox: in my actual code, the \tcolorbox is called by an environment (call it \mybox). At first I tried to have the \origpage command, within the \tcolorbox, set a flag that would be preserved and analyzed by the closing braces of the \mybox environment. However, the value of this flag was not preserved after the end of \tcolorbox. So this approach did not work. (Perhaps there could be a solution with \gdef?)

I found another approach that did work. That was to change the original page number to an optional argument of the \mybox environment. That allowed the \mybox environment to use if statements to issue the \markboth command at top level, and also to issue the \origpage command displaying the original page number within the tcolorbox. This only worked in my case because the \tcolorboxes are short and never span a page break, and because the original page number always appears at the beginning of the box. Using xparse environment definitions is necessary because the argument has to be used in the closing braces of the environment statement. This is not how I wanted to set up the file and I didn't find it very elegant, but it did get the job done.

Essentially it's like this:

\NewDocumentEnvironment{mybox}{o}
 {
  \begin{tcolorbox}
  \IfValueT{#1}{{\large{[#1.]}}}
 }
 {
  \end{tcolorbox}%
  \IfValueT{#1}{\markboth{\hfill #1 \hfill}{\hfill #1 \hfill}}%
 }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .