This is a combination of two previous questions (with their respective answers):How to create a command for the sections with an svg next to it on the top of the page? and How to make a conversation with rectangle shapes using tikzpicture environment?
The problem
Please consider this MWE (it is long because I need to show the actual header and footer):
\documentclass{article}
\usepackage{blindtext}
\def\maxwidth{16cm}
\def\maxheight{20cm}
\usepackage[a4paper,margin=.25in,top=1cm,footskip=0.25in]{geometry}
\usepackage[export]{adjustbox} % Loads also graphicx
\graphicspath{ {./images/} }
\usepackage{varwidth}
% From https://tex.stackexchange.com/a/529773/152550
\newif\ifStart
\Startfalse
\newif\ifImage
\Imagefalse
\usepackage{tikz}
\usetikzlibrary{shapes.misc, positioning}
\tikzset{basic/.style={rounded corners=.2cm,inner sep=.3cm},
basic L/.style={basic,align=left,fill=white,anchor=north west,
font=\sffamily,outer sep=0pt},
my callout L/.style={basic L,
append after command={pic[fill=white]{callout corner L}}},
basic R/.style={basic,align=right,fill=green!60!black,anchor=north east,
font=\sffamily,outer sep=0pt},
my callout R/.style={basic R,
append after command={pic[fill=green!60!black]{callout corner R}}},
pics/callout corner L/.style={code={
\path[pic actions] ([xshift=3mm]\tikzlastnode.north west) -- ++ (-9mm,0)
-- ([yshift=-6mm]\tikzlastnode.north west);}},
pics/callout corner R/.style={code={
\path[pic actions] ([xshift=-3mm]\tikzlastnode.north east) -- ++ (9mm,0)
-- ([yshift=-6mm]\tikzlastnode.north east);}},
exercise/.style={rounded corners=.2cm,inner sep=.25cm,align=right,
fill=blue,anchor=north,font=\sffamily,text=white},
whatsapp/.cd,vdist/.initial=3mm,hdist/.initial=6mm,
start/.is if=Start,
image/.code=\Imagetrue\tikzset{whatsapp/graphics pars/.cd,#1},
graphics pars/.cd,scale/.initial=1 %add additional keys here
}
% Added varwidth to set a max width for each of the shapes. From https://tex.stackexchange.com/a/46479/152550
% Me
\newcommand{\Me}[2][]{\noindent\begin{tikzpicture}
\tikzset{whatsapp/.cd,#1}
\ifStart
\path (0,0) (\pgfkeysvalueof{/tikz/whatsapp/hdist},0)
node[my callout L,alias=tmp] {\ifImage
\includegraphics[max height=\maxheight,max width=\maxwidth,
scale=\pgfkeysvalueof{/tikz/whatsapp/graphics pars/scale}]{#2}%
\else
\begin{varwidth}{\maxwidth}#2\end{varwidth}%
\fi};
\else
\path (0,0) (\pgfkeysvalueof{/tikz/whatsapp/hdist},0)
node[basic L,alias=tmp] {\ifImage
\includegraphics[max height=\maxheight,max width=\maxwidth,
scale=\pgfkeysvalueof{/tikz/whatsapp/graphics pars/scale}]{#2}%
\else
\begin{varwidth}{\maxwidth}#2\end{varwidth}%
\fi};
\fi
\path (tmp.south) ++ (0,-\pgfkeysvalueof{/tikz/whatsapp/vdist});
\end{tikzpicture}\par}
% You
\newcommand{\You}[2][]{\noindent\begin{tikzpicture}
\tikzset{whatsapp/.cd,#1}
\ifStart
\path (0,0) (\textwidth-\pgfkeysvalueof{/tikz/whatsapp/hdist},0)
node[my callout R,alias=tmp] {\ifImage
\includegraphics[max height=\maxheight,max width=\maxwidth,
scale=\pgfkeysvalueof{/tikz/whatsapp/graphics pars/scale}]{#2}%
\else
\begin{varwidth}{\maxwidth}#2\end{varwidth}%
\fi};
\else
\path (0,0) (\textwidth-\pgfkeysvalueof{/tikz/whatsapp/hdist},0)
node[basic R,alias=tmp] {\ifImage
\includegraphics[max height=\maxheight,max width=\maxwidth,
scale=\pgfkeysvalueof{/tikz/whatsapp/graphics pars/scale}]{#2}%
\else
\begin{varwidth}{\maxwidth}#2\end{varwidth}%
\fi};
\fi
\path (tmp.south) ++ (0,-\pgfkeysvalueof{/tikz/whatsapp/vdist});
\end{tikzpicture}\par}
\newcommand{\Exercise}[2][]{\noindent\begin{tikzpicture}
\path (0,0) (\textwidth/2,0) node[exercise,alias=tmp,#1] {#2};
\path (tmp.south) ++ (0,-\pgfkeysvalueof{/tikz/whatsapp/vdist});
\end{tikzpicture}\par}
\usepackage[explicit]{titlesec}
\usepackage{eso-pic}
\AddToShipoutPictureBG{\includegraphics[width=\paperwidth,height=\paperheight]{example-image}}
%%%%%%%%%%%%%%%%%%%%
\usepackage[hidelinks]{hyperref}
\usepackage{lastpage}
\usepackage{refcount}
\usepackage{fancyhdr}
\pagestyle{fancy}
\newsavebox{\arrowL}
\newsavebox{\arrowR}
\sbox\arrowR{\begin{tikzpicture}
\draw[line width=1mm,white,line cap=round,line join=round]
(0,0) -- (7pt,8pt) -- (0pt,16pt);
\end{tikzpicture}}
\sbox\arrowL{\begin{tikzpicture}
\draw[line width=1mm,white,line cap=round,line join=round]
(0,0) -- (-7pt,8pt) -- (0pt,16pt);
\end{tikzpicture}}
\fancyhf{}
% From https://tex.stackexchange.com/a/529755/152550
\titleformat{\section}[display]{}{}{0pt}
{\begin{tikzpicture}[overlay,remember picture]
\fill[green] (current page.north west) rectangle
([yshift=-2cm]current page.north east);
\node[text=white,anchor=west,font=\LARGE\bfseries\sffamily,anchor=west] (a)
at ([xshift=3.5cm,yshift=-1cm]current page.north west)
{Section \thesection: #1};
\clip ([xshift=2cm,yshift=-1cm]current page.north west)
circle[radius=1.2cm];
\node at
([xshift=2cm,yshift=-1cm]current page.north west)
{\includegraphics[width=1.8cm]{example-image}};
\end{tikzpicture}
}[]
% From https://tex.stackexchange.com/a/236778
\titleformat{name=\section,numberless}[display]{}{}{0pt}
{\begin{tikzpicture}[overlay,remember picture]
\fill[green] (current page.north west) rectangle
([yshift=-2cm]current page.north east);
\node[text=white,anchor=west,font=\LARGE\bfseries\sffamily,anchor=west] (a)
at ([xshift=3.5cm,yshift=-1cm]current page.north west)
{#1};
\clip ([xshift=2cm,yshift=-1cm]current page.north west)
circle[radius=1.2cm];
\node at
([xshift=2cm,yshift=-1cm]current page.north west)
{\includegraphics[width=1.8cm]{example-image}};
\end{tikzpicture}
}[\vspace{-1cm}]
\rfoot{
\begin{tikzpicture}[remember picture,overlay]
\fill[black] (current page.south west) rectangle ++(\paperwidth,1.5cm)
node[midway,align=center,font=\LARGE\bfseries,text=white,xscale=1.5]
(pageno-\number\value{page})
{\thepage}; % From https://tex.stackexchange.com/a/443744/152550
\ifnum\value{page}<\getpagerefnumber{LastPage}
\path ([xshift=\paperwidth/4]pageno-\number\value{page})
node{\hyperlink{page.\the\numexpr\value{page}+1}{\usebox\arrowR}};
\fi
\ifnum\value{page}>1
\path ([xshift=-\paperwidth/4]pageno-\number\value{page})
node{\hyperlink{page.\the\numexpr\value{page}-1}{\usebox\arrowL}};
\fi % From https://tex.stackexchange.com/a/529698/152550
\end{tikzpicture}
}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\begin{document}
\section{I am a cat}
\Me[start]{\blindtext[1]\\ Text}
\Me[image={scale=0.75}]{example-image}
\You[start,image={scale=1}]{example-image-duck}
\Exercise{How many marmots?}
\You[start]{\blindtext[2]}
\Me[start]{\blindtext[1]}
\Me{\blindtext[2]}
\newpage
\section{You are a duck}
\Me{\blindtext[1]}
\newpage
\section*{Bibliography}
\end{document}
This combined source code comes from @Schrödinger's cat who kindly made modifications once the answers of the cited questions were accepted.
Look at the output:
There is a missing header. And sometimes it collides with the shapes.
Moreover, if we, for example, increase one image size, let's say we change \You[start,image={scale=1}]{example-image-duck} to \You[start,image={scale=1.35}]{example-image-duck}, there is a collision with the footer:
Question
Is there any way to prevent these collisions with the header and footer, preserving sizes? I don't care if one shape that does not fit in the page must go to the next page. I don't want collisions.




\usepackage[a4paper,margin=.25in,top=2cm,bottom=2cm,footskip=0.25in]{geometry}or something like this, i.e. just increase the margins? – Feb 25 '20 at 16:07topandbottomvalues then the first page has a lot of space between the green and white shapes. In the second page, the section still missing: https://i.imgur.com/yXTGn0r.png I will try changing its value to obtain a better result, thank you! – manooooh Feb 25 '20 at 16:16tcolorboxpackage, which allows you to produce breakable variants of such shapes. Now that I see that some of them are enormous, I am tempted to suggest to redo them intcolorboxto make them breakable. This would cure the problem of huge gaps when the last big shape does not fit on the page. – Feb 25 '20 at 16:20tcolorboxwill be worth for image shapes, too? Because in my document I will mostly use images, some text and some sample code. – manooooh Feb 25 '20 at 16:27frame code. – Feb 28 '20 at 19:58