1

I have a large document that I've written in Overleaf (pdfLaTex 2020 compiler). Each section compiles fine, but the whole thing takes more than 4 minutes to compile, so I need to download and compile locally. It needs to compile as one document because of cross-references and page numbers.

I'm running texlive 2020 as suggested here.

However, I'm having a problem with the placement of tikzpicture boxes, which seem to be due to the update of everypage (I don't know for sure, but this is the only warning message I get in the log). It looks great on Overleaf but... not so nice when I compile on my computer. Pic below shows screenshot from overleaf on the left, and local compile on the right. Note the "The text here" in grey patch (grey patch is behind the text 1/2 way down in the local version). enter image description here I would like to update the code so it will work with the current version of everypage in texlive2020. MWE below. If anyone has some insights or suggestions, it's much appreciated. Thanks in advance!

\documentclass[twoside]{scrbook}
\usepackage[outer=2.25in, inner=.75in]{geometry}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\usepackage{ifthen,ifoddpage}
\usetikzlibrary{calc}

% CHapter number in margins
\usepackage{background}
\usetikzlibrary{calc}
\usepackage{ifthen}
\pagestyle{plain}

% background common settings
\SetBgScale{1}
\SetBgAngle{0}
\SetBgOpacity{1}
\SetBgContents{}


\makeatletter
\newcommand\ChapFrame{%
    \AddEverypageHook{%
        \ifthenelse{\isodd{\thepage}}
        {\SetBgContents{% right-side pages
                \begin{tikzpicture}[overlay,remember picture, text centered]
                \node[fill={black!10},inner sep=0pt,rectangle, 
                text width=1cm, text height=8cm, align=center,anchor=north east] 
                at ($ (current page.north east) + (-0cm,-2*\thechapshift cm) $) 
                {\rotatebox{90}{{\textcolor{black}{\centering\quad\scshape{\rightmark}}}}};
                \end{tikzpicture}}%
        }
        {\SetBgContents{%
                \begin{tikzpicture}[overlay,remember picture]
                \node[fill={black!10},inner sep=0pt,rectangle,text width=.75cm,
                text height=6cm,align=center,anchor=north west] 
                at ($ (current page.north west) + (-0cm,-2*\thechapshift cm) $) 
                {\rotatebox{90}{\hspace*{.3cm}\parbox[c][0cm][c]{5cm}{%
                            \centering\textcolor{black}{\scshape\leftmark}}}};
                \end{tikzpicture}}
        }
        \bg@material}%
    \stepcounter{chapshift}
}
\makeatother

% redefinition of \chaptermark to contain only the title
\renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}}
\newcounter{chapshift}
\addtocounter{chapshift}{-1}


\begin{document}
\chapter{The text here} \ChapFrame
\lipsum[1-10]
\end{document}

UPDATE: I changed the compiler to pdflatex (different from recommended in the previous link, but I don't have the stack-cred to comment on that post) and recompiled FOUR times. Now it's looking better (the first three compilations still had lots of formatting problems).

3
  • Have you typeset the document twice?
    – Ivan
    Jan 20, 2021 at 18:50
  • Thanks for the suggestion. I did, and the message was "Latexmk: All targets (mwe.dvi) are up-to-date" and no change in the dvi file. Jan 20, 2021 at 19:32
  • @Ivan Thanks for the inspiration; I changed compilers and re-compiled many times, and now it looks good. Jan 20, 2021 at 20:46

1 Answer 1

1

I simplified your code with extreme prejudice. \AddToHook is built in. [align] automatically puts the text into a tabular, while [text width] puts the text into a \parbox. [minimum height] and [minimum width] control the fill rectangle.

\documentclass[twoside]{scrbook}
\usepackage[outer=2.25in, inner=.75in]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{lipsum}

% CHapter number in margins
\pagestyle{plain}

\AddToHook{shipout/background}{\ifodd\value{page}%
       \sbox0{\begin{tikzpicture}
                \node[fill={black!10}, inner sep=0pt, align=center,
                  minimum height=1cm, minimum width=8cm, rotate=90] 
                {\quad\scshape\rightmark};
          \end{tikzpicture}}%
       \put({\dimexpr \paperwidth-\wd0},{\dimexpr -\ht0-\chapshift}) {\box0}%
     \else 
       \sbox0{\begin{tikzpicture}
                \node[fill={black!10},inner sep=0pt, align=center,
                minimum height=.75cm, minimum width=6cm, rotate=90] 
                {\scshape\leftmark};
          \end{tikzpicture}}
       \put(0pt,{\dimexpr -\ht0-\chapshift})  {\box0}%
     \fi}

% redefinition of \chaptermark to contain only the title
\renewcommand\chaptermark[1]{\markboth{\thechapter.~#1}{}}% ???
\newlength{\chapshift}
\setlength{\chapshift}{-2cm}


\begin{document}
\chapter{The text here} \addtolength{\chapshift}{2cm}
\lipsum[1-10]
\end{document}

You must log in to answer this question.

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