2

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:

Collision with the header

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:

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.

  • 1
    How about \usepackage[a4paper,margin=.25in,top=2cm,bottom=2cm,footskip=0.25in]{geometry} or something like this, i.e. just increase the margins? – user194703 Feb 25 at 16:07
  • @Schrödinger'scat if I set those top and bottom values then the first page has a lot of space between the green and white shapes. In the second page, the section still missing: i.imgur.com/yXTGn0r.png I will try changing its value to obtain a better result, thank you! – manooooh Feb 25 at 16:16
  • I guess this is partly my fault. In your previous question you were asking to create these shapes with TikZ, which is what my answer did. While writing this I was considering suggesting the tcolorbox package, 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 in tcolorbox to make them breakable. This would cure the problem of huge gaps when the last big shape does not fit on the page. – user194703 Feb 25 at 16:20
  • @Schrödinger'scat thanks. Using tcolorbox will be worth for image shapes, too? Because in my document I will mostly use images, some text and some sample code. – manooooh Feb 25 at 16:27
  • 1
    I'll try to convert those into tcolorboxes later. It should be very easy with frame code. – user194703 Feb 28 at 19:58
1
+300

This code translates the TikZ-based shapes into tcolorboxes. This has the benefit that they are breakable. so you waste less space. If you use the graphics key, the box will adjust its size to the content.

\documentclass{article}
\usepackage{lipsum}
\def\maxwidth{16cm}
\def\maxheight{20cm}

\usepackage[a4paper,margin=.25in,top=0.2cm,bottom=1.4cm,footskip=0.25in]{geometry}


% From https://tex.stackexchange.com/a/529773/152550
\newif\ifStart
\Startfalse
\newif\ifImage
\Imagefalse
\newif\ifCalloutRight
\CalloutRightfalse


\usepackage[skins,breakable]{tcolorbox}

\tcbset{start/.code={\Starttrue},callout right/.code={\CalloutRighttrue},
graphics/.code={\tcbset{whatsapp cont/.style={hbox}}},
whatsapp cont/.style={width=\maxwidth},
whatsapp/.style={empty,breakable,
left=2mm,right=2mm,top=2mm,bottom=2mm,fontupper=\sffamily,
whatsapp cont,after skip=1ex},
whatsap skin/.style={% code for unbroken boxes:
frame code={%
\ifStart
 \ifCalloutRight
    \path[fill=#1]([xshift=-3mm]frame.north east) -- ++ (9mm,0) 
    -- ([yshift=-6mm]frame.north east); 
 \else
    \path[fill=#1]([xshift=3mm]frame.north west) -- ++ (-9mm,0) 
    -- ([yshift=-6mm]frame.north west); 
 \fi
\fi},
interior code={
\path[fill=#1,rounded corners=3mm] 
 (frame.south west) rectangle (frame.north east);
},  
% code for the first part of a break sequence: 
skin first is subskin of={emptyfirst}{%
frame code={%
\ifStart
 \ifCalloutRight
    \path[fill=#1]([xshift=-3mm]frame.north east) -- ++ (9mm,0) 
    -- ([yshift=-6mm]frame.north east); 
 \else
    \path[fill=#1]([xshift=3mm]frame.north west) -- ++ (-9mm,0) 
    -- ([yshift=-6mm]frame.north west); 
 \fi
\fi},
interior code={
\path[fill=#1] 
 (frame.south west) [rounded corners=3mm] |-
 (frame.north)  -|  (frame.east) [rounded corners=0mm] |- cycle;
},  
},
% code for the middle part of a break sequence: 
skin middle is subskin of={emptymiddle}{%
frame code={%
},
interior code={
\path[fill=#1] 
 (frame.south west) rectangle (frame.north east);
},  
},
% code for the last part of a break sequence: 
skin last is subskin of={emptylast}{%
frame code={%
},
interior code={
\path[fill=#1] 
 (frame.north west) [rounded corners=3mm] |-
 (frame.south)  -|  (frame.east) [rounded corners=0mm] |- cycle;
},  
}}}

\newtcolorbox{Mebox}[1][]{#1,whatsapp,flush left,whatsap skin=white}
\newcommand{\Me}[2][]{\begin{Mebox}[#1]
#2
\end{Mebox}}


\newtcolorbox{Youbox}[1][]{#1,whatsapp,flush right,right skip=15mm,callout right,
    whatsap skin=green!60!black}
\newcommand{\You}[2][]{\begin{Youbox}[#1]
#2
\end{Youbox}}

\newtcolorbox{Exercisebox}[1][]{#1,whatsapp,coltext=white,center,whatsap skin=blue}
\newcommand{\Exercise}[2][]{\begin{Exercisebox}[#1]
#2
\end{Exercisebox}}


\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]
  \path[left color=red!40!black,right color=red!60!black,middle color=red] 
  (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}
}[\vspace{1cm}]

% From https://tex.stackexchange.com/a/236778
\titleformat{name=\section,numberless}[display]{}{}{0pt}
  {\begin{tikzpicture}[overlay,remember picture]
  \path[left color=red!40!black,right color=red!60!black,middle color=red] 
  (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]{\lipsum[1]\\ Text}

\Me[graphics]{\includegraphics[scale=0.75]{example-image}}

\You[start,graphics]{\includegraphics{example-image-duck}}

\Exercise{How many marmots?}

\You[start]{\lipsum[2]}

\Me[start]{\lipsum[1-3]}

\Me{\lipsum[4]}

\newpage

\section{You are a duck}

\Me{\lipsum[1]}

\You{\lipsum[2]}


\newpage 
\section*{Bibliography}

\end{document}

enter image description here

And this is a version in which the boxes shrink if they are smaller than \maxwidth i.e. you do no longer need the graphics key.

\documentclass{article}
\usepackage{lipsum}
\def\maxwidth{16cm}
\def\maxheight{20cm}

\usepackage[a4paper,margin=.25in,top=0.2cm,bottom=1.4cm,footskip=0.25in]{geometry}


% From https://tex.stackexchange.com/a/529773/152550
\newif\ifStart
\Startfalse
\newif\ifImage
\Imagefalse
\newif\ifCalloutRight
\CalloutRightfalse


\usepackage[skins,breakable]{tcolorbox}
\newsavebox\OurNiceSandBox
\tcbset{start/.code={\Starttrue},callout right/.code={\CalloutRighttrue},
shrink/.code={\tcbset{whatsapp cont/.style={hbox}}},
whatsapp cont/.style={width=\maxwidth},
whatsapp/.style={empty,breakable,
left=2mm,right=2mm,top=2mm,bottom=2mm,fontupper=\sffamily,
whatsapp cont,after skip=1ex},
whatsap skin/.style={% code for unbroken boxes:
frame code={%
\ifStart
 \ifCalloutRight
    \path[fill=#1]([xshift=-3mm]frame.north east) -- ++ (9mm,0) 
    -- ([yshift=-6mm]frame.north east); 
 \else
    \path[fill=#1]([xshift=3mm]frame.north west) -- ++ (-9mm,0) 
    -- ([yshift=-6mm]frame.north west); 
 \fi
\fi},
interior code={
\path[fill=#1,rounded corners=3mm] 
 (frame.south west) rectangle (frame.north east);
},  
% code for the first part of a break sequence: 
skin first is subskin of={emptyfirst}{%
frame code={%
\ifStart
 \ifCalloutRight
    \path[fill=#1]([xshift=-3mm]frame.north east) -- ++ (9mm,0) 
    -- ([yshift=-6mm]frame.north east); 
 \else
    \path[fill=#1]([xshift=3mm]frame.north west) -- ++ (-9mm,0) 
    -- ([yshift=-6mm]frame.north west); 
 \fi
\fi},
interior code={
\path[fill=#1] 
 (frame.south west) [rounded corners=3mm] |-
 (frame.north)  -|  (frame.east) [rounded corners=0mm] |- cycle;
},  
},
% code for the middle part of a break sequence: 
skin middle is subskin of={emptymiddle}{%
frame code={%
},
interior code={
\path[fill=#1] 
 (frame.south west) rectangle (frame.north east);
},  
},
% code for the last part of a break sequence: 
skin last is subskin of={emptylast}{%
frame code={%
},
interior code={
\path[fill=#1] 
 (frame.north west) [rounded corners=3mm] |-
 (frame.south)  -|  (frame.east) [rounded corners=0mm] |- cycle;
},  
}}}

\newtcolorbox{Mebox}[1][]{#1,whatsapp,flush left,whatsap skin=white}
\newcommand{\Me}[2][]{\begin{lrbox}{\OurNiceSandBox}
#2
\end{lrbox}%
\ifdim\wd\OurNiceSandBox<\maxwidth
\begin{Mebox}[shrink,#1]
#2
\end{Mebox}
\else
\begin{Mebox}[#1]
#2
\end{Mebox}
\fi}


\newtcolorbox{Youbox}[1][]{flush right,right skip=15mm,#1,whatsapp,callout right,
    whatsap skin=green!60!black}
\newcommand{\You}[2][]{\begin{lrbox}{\OurNiceSandBox}
#2
\end{lrbox}%
\ifdim\wd\OurNiceSandBox<\maxwidth
\begin{Youbox}[shrink,#1]
#2
\end{Youbox}
\else
\begin{Youbox}[#1]
#2
\end{Youbox}
\fi}

\newtcolorbox{Exercisebox}[1][]{#1,whatsapp,coltext=white,center,whatsap skin=blue}
\newcommand{\Exercise}[2][]{\begin{lrbox}{\OurNiceSandBox}
#2
\end{lrbox}%
\ifdim\wd\OurNiceSandBox<\maxwidth
\begin{Exercisebox}[shrink,#1]
#2
\end{Exercisebox}
\else
\begin{Exercisebox}[#1]
#2
\end{Exercisebox}
\fi}


\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]
  \path[left color=red!40!black,right color=red!60!black,middle color=red] 
  (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}
}[\vspace{1cm}]

% From https://tex.stackexchange.com/a/236778
\titleformat{name=\section,numberless}[display]{}{}{0pt}
  {\begin{tikzpicture}[overlay,remember picture]
  \path[left color=red!40!black,right color=red!60!black,middle color=red] 
  (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]{\lipsum[1]\\ Text}

\Me{\includegraphics[scale=0.75]{example-image}}

\You[start]{\includegraphics{example-image-duck}}

\Exercise{How many marmots?}

\You[start]{\lipsum[2]}

\Me[start]{\lipsum[1-3]}

\Me{\lipsum[4]}

\You[start,spread sidewards=-3cm]{Quick and dirty.}

\Me[start,left skip=2cm]{MEOW!}

\newpage

\section{You are a duck}

\Me{\lipsum[1]}

\You{\lipsum[2]}


\newpage 
\section*{Bibliography}

\end{document}

enter image description here

| improve this answer | |
  • Thank you!! The text is cropped correctly. You have done a nice refactoring!! I need some stuff of the previous answers, though. As you have mention, there is a problem with the image boxes; they have a lot of space on its right, because the images are also aligned to the left. I need the shapes to fit without spaces, including images (i.e. automatically). See the comparison: imgur.com/e5VtIgT.png I have defined \maxwidth{16cm} for the max width for any shape (it can be an image, normal text etc.). But I defined \maxheight{20cm} only for max height of shapes containing only images. – manooooh Feb 29 at 3:24
  • This maximums values are only in case the text or image are too long; but adjustable shapes according to the text length (like your previous source codes, which are also nice) must be included on this new version. – manooooh Feb 29 at 3:27
  • 1
    @manooooh As for 2) : fixed and 3) good catch! fixed. As for 1), I do not understand this item. What should the usage look like? – user194703 Mar 1 at 0:54
  • 1
    @manooooh My bad! Fixed it now. (I misunderstood what \newtcbox does. I will also add an experimental version which makes the width as you intend. – user194703 Mar 1 at 1:20
  • 1
    @manooooh This is the difference between having a fixed width and not having a fixed width. Unfortunately, there is no really stable way to let LaTeX decide whether or not is should have a fixed width. You could do \Me{\begin{tabular}{@{}l@{}}Hello\\ bye\end{tabular}}, though. – user194703 Mar 4 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.