0

The goal is to place a brackets into the table (longtable) to embrace some rows of this table: enter image description here

The solution which involves rdelim and \multirows command (described here: usage of \rdelim) gives not uniform bracket widths as well as not uniform bracket line widths while distinct brackets have various span: \rdelim example

So the natural solution of the problem is usage of putting "remembered pictures" into the table and spanning brackets that are "decorations": decorations in \longtable

But the problem is that the nodes can travel to the next page: enter image description here enter image description here

What to do, to prevent nodes against escaping to the next page?

The solution given for mathematical formulas (forcing nodes to not travel to the next page) does not work here.

MWE:

\documentclass[12pt,a5paper,twoside]{article}
\usepackage[polish]{babel}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{tikz}
\usepackage[a5paper]{geometry}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}
\begin{longtable}{p{3cm}p{3cm}}
    \toprule
    first column & second column\tikz [remember picture] \node (rightmark) {};\\
    \midrule
    \endhead
    A & A \\
    A & A \\
    A & A \\
    A & A \\
    A & A \\
    A & A \\
    A & A \\
    A & A \\
    A & A \\
    B & B \tikz [remember picture] \node (n1) {};\\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \tikz [remember picture] \node (n2) {};\\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    \bottomrule
\end{longtable}
% curly brace
\tikz [overlay,remember picture]
      \draw [decoration={brace,amplitude=2mm},decorate,thick]
      (n1.north -| rightmark) -- (n2.south -| rightmark)
      node [midway,right=4mm,align=left] {The bracket\\spanned on\\some rows};
\end{document}
1

1 Answer 1

2

The solution given in the question you linked (How can I keep my TikZ overlay picture on the same page?) does work here, in the following sense:

\begin{longtable}{p{3cm}p{3cm}}
    \toprule
    first column & second column\tikz [remember picture] \node (rightmark) {};\\
    \midrule
    \endhead
    A & A \\
    A & A \\
    A & A \\
    A & A \\
    A & A \\
    A & A \\
    A & A \\
    A & A \\
    A & A \\
    B & B \tikz [remember picture] \node (n1) {};\\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \\*
    B & B \tikz [remember picture] \node (n2) {};%
    \tikz [overlay,remember picture]
      \draw [decoration={brace,amplitude=2mm},decorate,thick]
      (n1.north -| rightmark) -- (n2.south -| rightmark)
      node [midway,right=4mm,align=left] {The bracket\\spanned on\\some rows};\\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    \bottomrule
\end{longtable}%

output

Note the % after the draw command; otherwise the first entry C will be shifted to the right. Clearly, this solution only works as long as both nodes are on the same page.

Otherwise, you would have to look at the answer of the question Tikz - How to overlay Decorations over longtable that you linked already.

7
  • Thx. I released that your solution is reliable in all cases only if `\\` command is after tikz-picture with bracket (not immediately before).
    – forrest
    Nov 23, 2015 at 20:08
  • You mean the last \tikz should be moved before the \` so that two \tikz` commands follow right after each other? What is the problem with the current setup?
    – jarauh
    Nov 23, 2015 at 20:40
  • Yes. In my source file some commands are between these two \tikz commands (but I think it is not important here). If the bracket have to reach the last line of the page (rows with "B" ends at the last row and rows with "C" begins at the top line of the next page) the bracket still escape to the next page (while \\ is not after the second \tikz but after previous one).
    – forrest
    Nov 23, 2015 at 20:52
  • I edited my answer correspondingly.
    – jarauh
    Nov 23, 2015 at 20:57
  • OK - afrer this change is ok. Thx.
    – forrest
    Nov 23, 2015 at 21:00

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.