# Tikz - How to overlay Decorations over longtable

I asked similar question here Colored Curly Brackets spanning across multiple pages but may be I did not provide enough detail. On its own the solution works great.

I have about 32 longtables in my document with varying row numbers ranging anywhere from 40 to 250. Longtable was the choice because I wanted my data in a columns, which gave nice alignment and text wrapping. There are sections and subsections at the beginning of each longtable. Upto this point life is good. This is where I became bit greedy.

I wanted to show curly or square brackets on the left side, these braces needs to span across pages and can start from one table and terminate anywhere in the next table. Some braces need to span about 5 or 6 long tables.

I thought of using tikz overlay but could not find any example where I can see how to span braces across pages. I am attaching a sample image created in word to better explain the need. In the attached image the brown vertical and horizontal line are legacy of MS word screen shot and does have to the part of tex solution.

Any examples, help or documentation would be appreciated.

-
The reason for the absence of such examples is because I don't think it's is possible without manually breaking the brace at the page bottom and starting from above in the next page. Maybe something with mdframed mechanism can be hacked for this. Since it automatically breaks down boxes, it can keep track of started \tikzmarks. So I leave to floor to @MarcoDaniel . –  percusse Oct 26 '12 at 0:11

# Update 2

Well, with Andrew Stacey's everybody's favorite TikZ library tikzmark it is a little bit easier.
You need to download the file tikzmark.dtx and run it through pdflatex. If it requests and _example file, ignore. You'll get two files tikzlibrarytikzmark.code.tex and tikzlibrarytikzmarkextras.code.tex. Place them in the directory of your working .tex file or in your local texmf tree. Load it with \usetikzlibrary{tikzmark}.

I personally don't like the style of this brace, maybe I re-add my own style.

## Instruction

Place \bracestart{<identifier>} somewhere where you want the brace to start and \braceend{<identifier>} where it should end. On every page the brace should appear, you have to add

\bracedraw[<brace>]{<identifier>}{<level>}{<node [] argument>}{<node text>}


where <brace> will be used for the internally brace \draw.

At the moment, the brace's nipple middle part will be at the half of the brace.

### To do

• Automatically re-placement of the middle part and its text.
• Detection of left or right side placement (for twoside documents with different margins)
• Better interworking with pgf's key management (everything variable are TeX commands)

## Code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows,tikzmark,decorations.pathreplacing}
\tikzset{
next page=below,
mymarginbrace/.style={
decorate,
decoration={
brace,
amplitude=3em,
aspect=.5
},
thick,
rounded corners=10pt
}
}
\newcommand*{\tikzbracemargindistance}{12.5em} % probably should be some \marginwidth stuff and should handle even/odd pages (twoside)
\newcommand*{\tikzbraceleveldistance}{3em}
\newcommand*{\tikzbracestartheight}{1.5ex}
\newcommand*{\tikzbraceendheight}{\baselineskip-.5ex} % \tikzmark lands in the following par so we cheat ;)
\newcommand*{\tikzbracestartlength}{1.5em}

\newcommand{\bracestart}[1]{% #1 = name
\tikzmark{bracestart-#1}
}
\newcommand{\braceend}[1]{% #1 = name
\tikzmark{braceend-#1}
}
\newcommand{\bracedraw}[5][]{% #1 = optional argument for the brace line
% #2 = name
% #3 = level
% #4 = (mandatory) node argument
% #5 = node text
\tikz[overlay, remember picture] {
\draw[mymarginbrace, #1]
%           (pic cs:braceend-#2) -- node[#4] {#5} (pic cs:bracestart-#2);
(perpendicular cs:
horizontal line through = {(pic cs:braceend-#2)},
vertical line through = {($(current page.west)+(\tikzbracemargindistance-#3*\tikzbraceleveldistance,0pt)$)})
-- node[sloped,above=2.5em, #4] {#5}
(perpendicular cs: horizontal line through = {($(pic cs:bracestart-#2)+(0,\tikzbracestartheight)$)}, vertical line through = {($(current page.west)+(\tikzbracemargindistance-#3*\tikzbraceleveldistance,0pt)$)})
;
}
}
\usepackage{lipsum}
\begin{document}
\lipsum[1-4]
\bracestart{a}
\bracedraw[]{a}{0}{}{Hallo! Text a} % start of a = draw
\lipsum*[5-6]
\braceend{a}
\bracedraw[]{a}{0}{}{Hallo! Text a} % end of a = draw
%
\lipsum[7-9]
\bracestart{b}
\bracedraw[]{b}{1}{}{Text b} % start of b = draw
\lipsum[10-11]
\bracestart{c}
\bracedraw[]{c}{0}{}{Text c} % start of c = draw
\bracedraw[]{b}{1}{}{Text b} % somewhere bet start and end of b but certainly on another page than start and end
%
\bracedraw[green]{d}{2}{}{Text d} % start and end only on one page ...
\bracestart{d}
\lipsum*[12]
\braceend{d}

\lipsum*[13-17]
\braceend{c}
\braceend{b}
\bracedraw[]{c}{0}{}{Text c} % end of c = draw
\bracedraw[]{b}{1}{}{Text b} % end of b = draw
\end{document}


# First draft

I have something of the following in mind [no MWE :( and I haven't looked at your linked question].

Problem with braces will be to calculate the middle where that “nipple” part is.

## Code

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows}

\newcommand{\tikzmark}[3][]{\tikz[overlay,remember picture] \node[#1] (#2) at (#3) {};}
\usepackage{lipsum}
\begin{document}
\lipsum[1-4]
\tikzmark{up}{$(0,0)+(-2em,0)$}
\tikzmark{pageup}{$(current page.south west)+(4em,0em)$}
\tikz[overlay,remember picture] \draw[very thick] (up) to[out=180,in=95] node [sloped,midway,above] {Where do we go?} (pageup);
\lipsum[5-6]
\tikzmark{down}{$(0,0)+(-2em,0)$}
\tikzmark{pagedown}{$(current page.north west)+(4em,0em)$}
\tikz[overlay,remember picture] \draw[-latex,very thick] (pagedown) to[out=-85,in=180] node [above,sloped,pos=.8] {Whee!} (down);
\lipsum[7-9]
\end{document}


## Output

-
Wow, that's a very clever idea and you don't have to find the nipple (hey, focus here!) because both parts will be clipped by the page break anyway if you use the brace decoration. –  percusse Oct 26 '12 at 0:32
@Qrrbrbirlbel - I can let go braces, if I can make it a nice straight line with 90 degree turns. I asked for curly braces because they look cool but this serves the purpose. You included the names on the lines thats like bonus on my question. –  Raama Oct 26 '12 at 0:37
Very nice :-) +1, What is the document is two sided? –  Harish Kumar Oct 26 '12 at 2:30
@HarishKumar That depends of whether you want a fixed space between the side of your page and the braces or a fixed space between text and the braces. One could also decide to let the braces jump between left and right margins (i.e. outer or inner). From there it's only checking the oddness and a few calculations with margin dimensions. –  Qrrbrbirlbel Oct 26 '12 at 3:40
Sounds like it would be useful if \tikzmark remembered the page number as well as the position on the page. bazaar.launchpad.net/~tex-sx/tex-sx/development/revision/163 –  Loop Space Oct 26 '12 at 10:35