3

I want to put some marks in the document and place desciptions of these marks in the margin area, one below another.

It works fine, however if I place a mark inside align environment corresponding node is vertically misplaced.

\documentclass{article}
\usepackage[a5paper,textwidth=9cm]{geometry}
\usepackage{tikzpagenodes}
\makeatletter
\protected\def\note#1{%
  \textcolor{red}{!}%
  \ifmeasuring@\else % do nothing during the measuring phase
    \tikzpicture[remember picture,overlay]
        \@ifundefined{pgf@sh@ns@note}
            {\coordinate (pos) at (0,0-|current page marginpar area.north west);}
            {\coordinate (pos) at (note.south west);}
        \node (note) [anchor=north west,inner sep=0pt,text=red] at (pos) {#1};
        \draw[red] (note.south west) rectangle (note.north east);
    \endtikzpicture
  \fi}
\makeatother
\usepackage{amsmath}
\usepackage{tabu}
\begin{document}
Some text, more\note{text 1st} text, even more text.
\begin{displaymath}
    a+b+c =\note{math 1st} d+e+f = g+h
\end{displaymath}
Some text, more\note{text 2nd} text, even more text.
\begin{align}
    a+b+c &=\note{align 1st} d+e+f \\
    &= g\note{align 2nd}+h
\end{align}
Some text, more\note{text 3rd} text, even more text.
\begin{center}
    \begin{tabu}{|c|c|c|}
        \hline
        Column 1&Column 2\note{tabu 1st}&Column3\\\hline
        Cell 1&Cell 2&Cell 3\\\hline
        Cell 4&Cell 5\note{tabu 2nd}&Cell 6\\\hline
    \end{tabu}
\end{center}
Some text, more\note{text 4th} text, even more text.
\end{document}

mwe

The same thing occurs if I use tabu tabular environment. Meanwhile displaymath and tabular do no harm.

What is the reason?

Edit: Included tabu in MWE

4

I don't really know, but probably the space you see is reserved and not filled because align does two passes over the contents, throwing away the result of the first pass, only keeping the measurements for sizing the columns in the second phase. You can work around this by setting the picture only in the final typesetting phase, not when amsmath measures the parts of the display:

\documentclass{article}
\usepackage[a5paper,textwidth=9cm]{geometry}
\usepackage{tikzpagenodes}
\makeatletter
\protected\def\note#1{%
  \textcolor{red}{!}%
  \ifmeasuring@\else % do nothing during the measuring phase
    \tikzpicture[remember picture,overlay]
        \@ifundefined{pgf@sh@ns@note}
            {\coordinate (pos) at (0,0-|current page marginpar area.north west);}
            {\coordinate (pos) at (note.south west);}
        \node (note) [anchor=north west,inner sep=0pt,text=red] at (pos) {#1};
        \draw[red] (note.south west) rectangle (note.north east);
    \endtikzpicture
  \fi}
\makeatother
\usepackage{amsmath}
\begin{document}
Some text, more\note{text 1st} text, even more text.
\begin{displaymath}
    a+b+c =\note{math 1st} d+e+f = g+h
\end{displaymath}
Some text, more\note{text 2nd} text, even more text.
\begin{align}
    a+b+c &=\note{math 2nd} d+e+f \\
    &= g+h
\end{align}
Some text, more\note{text 3rd} text, even more text.
\end{document}

enter image description here

  • Halfway there - works fine for align, fails for tabu. I didn't originally include tabu in mwe, because I thought misplacement had the same origin as for align. Please take a look at updated example. – Paul Sep 29 '13 at 17:30
  • @Paul Also tabu does multiple passes over the material, but, as far as I know, it doesn't provide a mechanism similar to \ifmeasuring@ – egreg Sep 29 '13 at 17:55
  • After 4 hrs of trials-and-errors I'm just out of ideas... Is there really no workaround? It seemed so trival at first... – Paul Sep 29 '13 at 21:54
  • @Paul I abandoned trying to tame tabu in this respect time ago. – egreg Sep 29 '13 at 22:04

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.