1

I have an issue with paracol and background, they work fine on their own when there is a need for another page but when they are used together, it doesn't compile. Here is a MWE:

\documentclass[a4]{article}
\usepackage{lipsum}
\usepackage{paracol}
\usepackage{background}
\usepackage{tikz}
\RequirePackage[left=0.3cm,top=0.3cm,right=0.3cm,bottom=0.3cm,nohead,nofoot]{geometry}
\newlength{\leftcolumn}
\setlength{\leftcolumn}{.35\paperwidth}
\newcommand{\bghelper}[2]{
    \begin{tikzpicture}[remember picture,overlay]
    \fill[fill=#1](0,0) rectangle (\leftcolumn,\paperheight);
    \fill[fill=#2](\leftcolumn, 0) rectangle (\paperwidth, \paperheight);
    \end{tikzpicture}%
}
\backgroundsetup{scale=1,color=black,opacity=1,contents=\bghelper{gray!25}{white},
    angle=0,position=current page.south west,nodeanchor=south west}

\begin{document}
\columnratio{0.35, 0.65}
\begin{paracol}{2}
\switchcolumn[0]
\lipsum[1-4]%When it is 1-4 it fits into a page
%but when it is 1-5 it requires a second page
%and it doesn't compile
\switchcolumn[1]
\lipsum[1-5]
\end{paracol}%
\end{document}

If you take out paracol part and make the text longer, background works for the second page too as intended, and similarly if you take out background part paracol works fine.

Thanks in advance to all people who will have a look at the problem.

2
  • 1
    better save your tikzpicture in a box and then insert the box. paracol is messing around with the output routine, and this is quite fragile. Commented Oct 1, 2020 at 21:55
  • @UlrikeFischer How can I do that? Can you elaborate a little bit?
    – uxsu
    Commented Oct 1, 2020 at 22:27

1 Answer 1

0

Easier to show than explain. Also should be much faster to implement this way.

\documentclass[a4]{article}
\usepackage{lipsum}
\usepackage{paracol}
\usepackage{background}
\usepackage{tikz}
\RequirePackage[left=0.3cm,top=0.3cm,right=0.3cm,bottom=0.3cm,nohead,nofoot]{geometry}
\newlength{\leftcolumn}
\setlength{\leftcolumn}{.35\paperwidth}
\newcommand{\bghelper}[2]{
    \begin{tikzpicture}[remember picture,overlay]
    \fill[fill=#1](0,0) rectangle (\leftcolumn,\paperheight);
    \fill[fill=#2](\leftcolumn, 0) rectangle (\paperwidth, \paperheight);
    \end{tikzpicture}%
}
\newsavebox{\bgbox}
\savebox{\bgbox}{\bghelper{gray!25}{white}}
\backgroundsetup{scale=1,color=black,opacity=1,contents=\usebox{\bgbox},
    angle=0,position=current page.south west,nodeanchor=south west}

\begin{document}
\columnratio{0.35, 0.65}
\begin{paracol}{2}
\switchcolumn[0]
\lipsum[1-4]%When it is 1-4 it fits into a page
%but when it is 1-5 it requires a second page
%and it doesn't compile
\switchcolumn[1]
\lipsum[1-5]
\end{paracol}%
\end{document}
3
  • Thanks for the answer, it works for me but I cannot upvote your answer due to my poor reputation point :). So adding a level of indirection helps resolve the paracol's messing with the output?
    – uxsu
    Commented Oct 2, 2020 at 8:30
  • @UlrikeFische might have a better answer. Think of tikzpicture as creating an image and the savebox as holding the image in "output ready" form. For example, you cannot run a tikzpicture inside another tikzpicture, but you can record the image in a savebox and use it instead. Commented Oct 2, 2020 at 15:54
  • Yeah I made my research around the web and understood the mechanism behind, and it also explains why it is much faster this way, thanks again for the answer and explanation, I was having a big problem making this work.
    – uxsu
    Commented Oct 2, 2020 at 17:00

You must log in to answer this question.

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