# Text placement after overlay TikZ picture

Suppose I want to customize a title with TikZ using relative placement to the node current page. I would typically do something as:

\documentclass[10pt,english,a4paper]{article} %

\usepackage{tikz}
\usepackage{lipsum}

\title{My very fancy cute title, that I make long for expository
purpose}%
\author{John Doe}%
\date{Today}%
%

\makeatletter

\pgfmathsetmacro\barshift{\marginparwidth}%
\pgfmathsetmacro\frombar{\marginparsep}%
\pgfmathsetmacro\topshift{1in+\voffset+\topmargin}%

\def\@bgcolor{blue!70!green!90!red!90!white}

\renewcommand{\maketitle}{%
\begin{tikzpicture}[remember picture,overlay]
% title placement
\coordinate (top-bar) at ([xshift=\barshift,yshift=-\topshift]
current page.north west);%
\node [anchor=north west,xshift=\frombar] (title) at (top-bar) {%
\begin{minipage}{.7\linewidth} %
\Huge \color{black} \sffamily \@title %
\end{minipage} %
};%
\coordinate (bottom-bar) at ([xshift=-\frombar] title.south west);
\draw [\@bgcolor,line width=.5em] (top-bar) -- (bottom-bar);
\end{tikzpicture}
}

\makeatother

\begin{document}

\maketitle
% \vskip 5em
\lipsum % HERE, without the \vskip, the beginning is printed on top of the title !

\end{document}


But now, if I write some text in the document (\lipsum in the MWE), the overlay option (needed to reference to current page) prints it on top of my fancy title. Something that I obviously don't want...

For a one time title customization, it is ok as I can add something as \vskip 5em and adjust the spacing by hand just before typing my text. But if I'm coding a package, I need to find this spacing automatically. There I'm stuck... How can I detect the end of an overlay TikZ picture?

• Please make your code complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but I think it is necessary to better understand your problem and help you. – CarLaTeX Nov 12 '16 at 10:30
• @CarLaTeX Done. Hope it helps to understand the problem better. – Pece Nov 12 '16 at 12:16

One solution is to not use overlay at all, and calculate the title's position relative to the top corner of the text (its default position) instead of relative to the page:

\documentclass[10pt,english,a4paper]{article} %

\usepackage{tikz}
\usepackage{lipsum}

\title{My very fancy cute title, that I make long for expository purpose}%
\author{John Doe}%
\date{Today}%
%

\makeatletter

\def\@bgcolor{blue!70!green!90!red!90!white}

\pgfmathsetmacro\barshift{1in+\hoffset+\oddsidemargin-\marginparwidth}%
\pgfmathsetmacro\frombar{\marginparsep}%
\renewcommand{\maketitle}{%
\begin{tikzpicture}
% title placement
\coordinate (top-bar) at (-\barshift pt,\topshift pt);%
\node [anchor=north west, inner xsep=\frombar] (title) at (top-bar) {%
\begin{minipage}{.7\linewidth} %
\Huge \color{black} \sffamily \@title %
\end{minipage} %
};%
\coordinate (bottom-bar) at (title.south west);
\draw [\@bgcolor,line width=.5em] (top-bar) -- (bottom-bar);
\pgfresetboundingbox
\path[use as bounding box] (0,0) rectangle (title.south east);
\end{tikzpicture}

}

\makeatother

\begin{document}
\maketitle
\lipsum

\end{document}


EDIT: If you must use overlay, you can extract and globally store the y coordinate of the bottom of the title, which will of course be in the (offset) page coordinates:

\documentclass[10pt,english,a4paper]{article} %

\usepackage{tikz}
\usepackage{lipsum}

\title{My very fancy cute title, that I make long for expository
purpose}%
\author{John Doe}%
\date{Today}%
%

\makeatletter

\pgfmathsetmacro\barshift{\marginparwidth}%
\pgfmathsetmacro\frombar{\marginparsep}%
\pgfmathsetmacro\topshift{1in+\voffset+\topmargin}%

\def\@bgcolor{blue!70!green!90!red!90!white}

\newdimen\titlebottom
\renewcommand{\maketitle}{%
\begin{tikzpicture}[remember picture,overlay]
% title placement
\coordinate (top-bar) at ([xshift=\barshift,yshift=-\topshift]
current page.north west);%
\node [anchor=north west,xshift=\frombar] (title) at (top-bar) {%
\begin{minipage}{.7\linewidth} %
\Huge \color{black} \sffamily \@title %
\end{minipage} %
};%
\coordinate (bottom-bar) at ([xshift=-\frombar] title.south west);
\draw [\@bgcolor,line width=.5em] (top-bar) -- (bottom-bar);
\pgfextracty{\global\titlebottom}{\pgfpointanchor{title}{south}}
\end{tikzpicture}
\vspace{-1\titlebottom}
}

\makeatother

\begin{document}

\maketitle

\lipsum[1]

\end{document}

• Thanks for your answer. But what if I really need the relative positioning to current page? TikZ & pgf manual is so heavy, I don't know where to search for that inside it. (Of course, my example here does not match my exact need, it is just for the sake of simplicity.) – Pece Nov 12 '16 at 14:22
• @Pece Okay, I've added another solution which uses overlay. – Emma Nov 13 '16 at 2:36
• @cfr Thanks for the suggestion. I've changed it. – Emma Nov 13 '16 at 2:43
• Tanks, the extraction is exactly what I needed ! – Pece Nov 13 '16 at 6:33