# How to create a command for the sections with an svg next to it on the top of the page?

This is an addendum of a previous question: How to place a \draw near the page number using tikzpicture environment.

# What I want

I would like to have the section text moved to the top of every page, and place an image next to it. Look at this:

Why I mention sections? Because when the document is finished I want to make a ToC at the beginning.

• The image (svg file) is always the same.

For example:

• The full document has 8 pages in total.
• In page 1 there should be nothing.
• In pages 2-4, the green rectangle should have: Section One: Text with the image next to it.
• In pages 5-7, the green rectangle should have: Section Two: More text with the image next to it.
• In page 8, the green rectangle should have: Bibliography with the image next to it.

and we should be able to produce a ToC with those 3 sections (two sections and the bibliography).

# What I have done

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{graphicx}
\usepackage{tikz}
\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{}
%\newcommand{\sec}[1]{%
\begin{tikzpicture}[remember picture,overlay]%
\fill[green] (current page.north west) rectangle ++(\paperwidth,-1.5cm);%
\node[text=white,anchor=west,xshift=4cm,yshift=-.75cm,font=\LARGE\bfseries] at (current page.north west) (a) {Section One: Text};%
\end{tikzpicture}%
%}
}
\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})
\fi
\ifnum\value{page}>1
\path ([xshift=-\paperwidth/4]pageno-\number\value{page})
\fi % From https://tex.stackexchange.com/a/529698/152550
\end{tikzpicture}
}

\renewcommand{\footrulewidth}{0pt}

\begin{document}

%\sec{Section One: Text}
\tikz\node[circle,draw,
path picture={
\node at (path picture bounding box.center){
\includegraphics[width=2.5cm]{Example.png}
};
}]{}; % From https://tex.stackexchange.com/a/193558/152550

Example
\newpage
Another example

\end{document}


Problems:

• I don't know how to use \newcommand[1]{\sec}{...} to have different sections on pages, where the argument is the name of the section.
• The cropped image does not show on the 2.5cm circle (inside \begin{document}). (I have loaded graphicx and put \graphicspath. I tried with \includegraphics{Example.png} outside tikzpicture and it worked.)

One way is to use titlesec. That way you can use ordinary \section commands for that purpose. This has various advantages (table of contents, hyperlinks, ...). You then only need to type

\section{I am a cat}
Example
\newpage
\section{You are a duck}
Another example


in the body of your document.

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage[explicit]{titlesec}
\usepackage{tikz}
\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{}
\titleformat{\section}[display]{}{}{0pt}
{\begin{tikzpicture}[overlay,remember picture]
\fill[green] (current page.north west) rectangle
([yshift=-1.5cm]current page.north east);
\node[text=white,anchor=west,font=\LARGE\bfseries\sffamily,anchor=west]  (a)
at ([xshift=4cm,yshift=-.75cm]current page.north west)
{Section \thesection: #1};
\clip ([xshift=2cm,yshift=-.75cm]current page.north west)
\node at
([xshift=2cm,yshift=-.75cm]current page.north west)
{\includegraphics[width=2.5cm]{example-image-duck}};
\end{tikzpicture}
}[]

% see 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=-1.5cm]current page.north east);
\node[text=white,anchor=west,font=\LARGE\bfseries\sffamily,anchor=west]  (a)
at ([xshift=4cm,yshift=-.75cm]current page.north west)
{#1};
\clip ([xshift=2cm,yshift=-.75cm]current page.north west)
\node at
([xshift=2cm,yshift=-.75cm]current page.north west)
{\includegraphics[width=2.5cm]{example-image-duck}};
\end{tikzpicture}
}[]

\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})
\fi
\ifnum\value{page}>1
\path ([xshift=-\paperwidth/4]pageno-\number\value{page})
\fi % From https://tex.stackexchange.com/a/529698/152550
\end{tikzpicture}
}

\renewcommand{\footrulewidth}{0pt}

\begin{document}
\section{I am a cat}
Example
\newpage
\section{You are a duck}
Another example

\newpage
\section*{Bibliography}

• Thanks! This answer contemplate the possibility of adding a section that has no number? For example, a section called Bibliography. – manooooh Feb 23 '20 at 23:31