# Tikzmark Annotations Overlapping with Footer

Currently, my tikzmark annotations overlap with my footer defined by the fancyhdr package.

Currently I have my equation with the annotation defined like

$$\tikzmarknode{A}{2}$$
\begin{tikzpicture}[overlay,remember picture, shorten <= 1mm, font=\footnotesize]
\draw[red,<-] (A.south) -- ++ (-0.3,-1) node[below] {2 spin states};
\end{tikzpicture}


I presume I have to put the equation and the tikzmark annotation in the same box so LaTeX knows to put the entire box on the next page. What's the proper way to do this?

EDIT: My equation looks something more like this

$$\tikzmarknode{A}{2}\left[\frac{\tikzmarknode{B}{(2k_{F})}}{\tikzmarknode{C}{\left(\frac{2\pi}{Na}\right)}}\right]=\tikzmarknode{D}{n}\tikzmarknode{E}{(Na)}$$
\begin{tikzpicture}[overlay,remember picture,shorten <=1mm,font=\footnotesize]
\draw[red,<-] (A.south) -- ++ (-0.3,-0.3) node[left,xshift=0.1cm,yshift=-0.1cm] {2 spin states};
\draw[red,<-] (B.east) -- ++ (1,0.6) node[right] {volume of Fermi sea};
\draw[red,<-] (C.south) -- ++ (0.2,-0.4) node[below right,xshift=-0.1cm,yshift=0.2cm] {volume corresponding to a single $k$ since $k$ is quantized as $k=\frac{2\pi m}{Na}$, $m\in\mathbb{Z}$};
\draw[red,<-] (D.south) -- ++ (0.3,-0.3) node[right,xshift=-0.1cm,yshift=-0.1cm] {number density};
\draw[red,<-] (E.east) -- ++(0.8,0.2) node[right] {length of chain};
\end{tikzpicture}

• What is the rationale for using tikzmark in this case at all? Can't you just put an ordinary tikzpicture in the equation? – Schrödinger's cat Feb 2 at 21:00
• If you really have this equation, use \documentclass{article} \usepackage{tikz} \begin{document} $$\begin{tikzpicture}[shorten <= 1mm,baseline={(A.base)}] \node (A){2}; \draw[red,<-] (A.south) -- ++ (-0.3,-1) node[below,font=\footnotesize] {2 spin states}; \end{tikzpicture}$$ \end{document}. If you have a more complex setup, please provide a self-contained example. – Schrödinger's cat Feb 2 at 21:06
• Hi, my apologies, I thought it would be better to just give a minimal example. I've edited my original question. – D W Feb 2 at 21:35
• Do you use fleqn or not? You can use e.g. this post where the vertical post is computed and inserted in the equation (rather than afterwards), but this depends a bit on whether or not you use fleqn. Another possibility is using \subnodes. – Schrödinger's cat Feb 2 at 22:01
• I typically use the equation and aligned environment. I saw on that post they use [ ], but I wanted to retain the numbering somehow. I'll take a look at \subnode. Thank you – D W Feb 2 at 22:35

You can measure the dimensions of the annotations and add the corresponding space in the equation. It is still less automatic than one may wish.

\documentclass[fleqn]{article}
\usepackage{amssymb}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc}
\begin{document}
\lipsum[1]
$$\tikzmarknode{A}{2}\left[\frac{\tikzmarknode{B}{(2k_\mathrm{F})}}{\tikzmarknode{C}{\left(\frac{2\pi}{Na}\right)}}\right]=\tikzmarknode{D}{n}\tikzmarknode{E}{(Na)} \begin{tikzpicture}[overlay,remember picture,shorten <=1mm,font=\footnotesize] \begin{scope}[local bounding box=annotations] \draw[red,<-] (A.south) -- ++ (-0.3,-0.3) node[left,xshift=0.1cm,yshift=-0.1cm] {2 spin states}; \draw[red,<-] (B.east) -- ++ (1,0.6) node[right] {volume of Fermi sea}; \draw[red,<-] (C.south) -- ++ (0.2,-0.4) node[below right,xshift=-0.1cm,yshift=0.2cm] {volume corresponding to a single k since k is quantized as k=\frac{2\pi m}{Na}, m\in\mathbb{Z}}; \draw[red,<-] (D.south) -- ++ (0.3,-0.3) node[right,xshift=-0.1cm,yshift=-0.1cm] {number density}; \draw[red,<-] (E.east) -- ++(0.8,0.2) node[right] {length of chain}; \end{scope} \path let \p1=((annotations.north)-(annotations.south)), \p2=((annotations.center)-(A.center)),\n1={\y1-\baselineskip} in \pgfextra{\xdef\myht{\n1}\xdef\mylift{\y2}}; \end{tikzpicture} \raisebox{\mylift}{\begin{array}{@{}c@{}}\vspace{\myht}\end{array}} \typeout{\myht}$$
\lipsum[2]
\end{document}


tikzmark may overlap anything on a page by itself meaning and motivation. To avoid overlapping, you can manually add a \vspace{8mm} (and followed by a blank line), for example.

\documentclass{article}
\usepackage{tikz,lipsum}
\usetikzlibrary{tikzmark}
\begin{document}
\lipsum[1]
$$\tikzmarknode{A}{2}=1+1$$
\begin{tikzpicture}[overlay,remember picture, shorten <= 1mm, font=\footnotesize]
\draw[red,<-] (A.south) -- ++ (-0.3,-1) node[below] {2 spin states};
\end{tikzpicture}
\vspace*{8mm}

\lipsum[1]
\end{document}

• @Vincent and @hkh: vspace*{8mm} need to be followed by a blank line to get effect – Black Mild Feb 2 at 21:29
• Is manually adding vertical white space the only way to do it? Understandably, I could have the equation start on the next page to avoid this issue, but if I need to go back to edit my document around this equation, it seems sort of a hassle to have to redistribute white space. – D W Feb 2 at 21:38