1

I am trying to put braces into longtable (to span them on some rows). But if a table position on odd and even pages differs, there is a problem with vertical alignment of these braces (decorations): enter image description here enter image description here

MWE:

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

\setlength{\oddsidemargin}{-5mm}
\setlength{\evensidemargin}{-13mm}

\begin{document}
\begin{longtable}{p{3cm}>{\raggedleft\arraybackslash}p{5cm}}
    \toprule
    first column & second column%
    \smash{\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 & \smash{\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) {}; B%
    \tikz [overlay,remember picture]
          \draw [decoration={brace,amplitude=2mm},decorate,thick]
          (n1.north -| rightmark.east) -- (n2.south -| rightmark.east)
          node [midway,right=4mm,rotate=90,anchor=north] {brace};\\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    C & C \\
    D & \tikz [remember picture] \node (n3) {}; D\\*
    D & D \\
    D & D \\
    D & D \\
    D & D \\
    D & D \\
    D & D \\
    D & D \\
    D & \tikz [remember picture] \node (n4) {}; D%
    \tikz [overlay,remember picture]
          \draw [decoration={brace,amplitude=2mm},decorate,thick]
          (n3.north -| rightmark.east) -- (n4.south -| rightmark.east)
          node [midway,right=4mm,rotate=90,anchor=north] {brace};\\
    \bottomrule
\end{longtable}
\end{document}

I tried to add a code for storing horizontal table position (immediately below the command with node putting):

\makeatletter
\ifodd\c@page
    \def\refmargin{\the\oddsidemargin}
\else
    \def\refmargin{\the\evensidemargin}
\fi
\makeatother

but after first line break command \\ in the table the value of \refmargin can't be read. How to get the proper position of rightmark node in MWE above (both on even and on odd page)?

  • I can't read tikz that well but probably the problem is that the heading is only evaluated once and re-used as a box, so the tikz remember there probably does the wrong thing, why does that need to be in the heading rather than at the point that you need the brace? – David Carlisle Dec 8 '15 at 11:28
  • I looked for most transparent solution - in which for vertical alignment of braces only one node is used (I denoted it rightmark). Maybe I unnecessary complicated the way of putting the brackets - and I should span it on two nodes only, as you have suggested. Thanks. – forrest Dec 8 '15 at 12:02
  • This wouldn't work even if the header was evaluated on every page because tikzmark names must be unique. If the table spans more than one page, this won't be the case and will cause trouble if the header was evaluated more than once. [Just realised you're not using tikzmark but I assume the same thing applies.] – cfr Jan 18 '16 at 2:36
  • If you use geometry you ought never to set page layout dimensions manually but always use the package. Otherwise geometry doesn't know what changes you've made and so cannot take them into account, leading to likely weirdnesses. – cfr Jan 18 '16 at 2:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.