0

I want to make my own command to deal with hyperref incompatibility with footnotes inside tabularx. I can't use hyperfootnotes=false option for hyperref.

It seems I'm in a half way to get what I want but I'm not enough experienced in LaTeX.

The problems are:

  1. Footnotes are displayed three times instead of once.
  2. Numbering is wrong.
  3. Links are missing.

Code:

\documentclass{article}
\usepackage{tabularx}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\usepackage[%
%    hyperfootnotes=false,
]{hyperref} 

\newcommand\tikznode[3][]%
    {\tikz[remember picture,baseline=(#2.base)]
        \node[minimum size=0pt,inner sep=0pt,#1](#2){#3};%
    }


\begin{document}
Some text. This is the main text.\footnote{This is a footnote in the main text.}

\fbox{
    \begin{minipage}{\linewidth}
        This is a quotation with a footnote in it.\footnote{A footnote in the minipage} The footnote is numbered independently of the rest of the text\footnote{test}.
\end{minipage}
}

\fbox{
    \begin{minipage}[t]{\textwidth}
        \tikzstyle{every picture}+=[remember picture]
        \renewcommand{\arraystretch}{1.00}
        \newcounter{cntasterisk}
        \newcommand{\TypeAsterisk}{\stepcounter{cntasterisk}\tikznode{gw-\arabic{cntasterisk}}{*}}
        \newcounter{cntoption}
        \newcommand{\OptionAsterisk}[1]{\stepcounter{cntoption}\tikznode{op-\arabic{cntoption}}{#1}}
        \NewDocumentCommand{\TypeName}{sm}{%
            \IfBooleanTF{#1}{%
                {\bf #2}&\multicolumn{2}{l|}{}\\[1ex]%
            }{%
                {\bf #2}&\multicolumn{2}{l|}{}\\%
            }
        }
        \NewDocumentCommand{\OptName}{sm}{%
            \IfBooleanTF{#1}{%
                &\multicolumn{2}{l|}{\OptionAsterisk{\it #2:}}\\[1ex]%
            }{%
                &\multicolumn{2}{l|}{\OptionAsterisk\it #2:}\\%
            }
        }
        \NewDocumentCommand{\OptValue}{smm}{%
            \IfBooleanTF{#1}{%
                &\makebox[1ex]{}{\bf #2}&#3\\[1ex]%
            }{%
                &\makebox[1ex]{}{\bf #2}&#3\\%
            }
        }

        \newcommand\savedfootnotes{}        
        \newcommand\MyFootnote[1]{%
            \stepcounter{mpfootnote}$^\textrm{\scriptsize\thempfootnote}$
            \xdef\savedfootnotes%
            {\unexpanded\expandafter{\savedfootnotes}\noexpand\footnotetext{#1}}%
        }

         \begin{tabularx}{\textwidth}{|l<{\makebox[1em]{}}|l@{\makebox[2ex]{--}\makebox[1ex]{}}X|}
        \hline
        \TypeName{name\TypeAsterisk\TypeAsterisk\TypeAsterisk\TypeAsterisk}
        \hline
        \OptName{option 1}
        \hline
        \OptValue{V1}{vlaue 1}
        \hline
        \OptValue{V2}{vlaue 2\MyFootnote{whatever}}
        \hline
        \OptValue{V3}{vlaue 3\MyFootnote{anything}}
        \hline
        \OptName{option 2}
        \hline
        \OptValue{V4}{vlaue 4}
        \hline
        \OptValue{V5}{vlaue 5}
        \hline
        \OptName{option 3\MyFootnote{even more}}
        \hline
        \OptValue{V6}{vlaue 6}
        \hline
        \OptName{option 4}
        \hline
        \OptValue{X\textit{n}}{special}
        \hline
        \end{tabularx}

        \savedfootnotes

        \begin{tikzpicture}[overlay]
        \foreach \x in {1,...,\arabic{cntasterisk}} {%
            \draw [red, -{Stealth}, thick] (gw-\x) |- (op-\x);
            }
        \end{tikzpicture}

        text\footnote{text}

   \end{minipage}
}
\end{document}

enter image description here

Sebastiano
  • 54,118
Simon
  • 351
  • I don't quite understand what you want. A tabularx and hyperref working, like described here: https://tex.stackexchange.com/a/114147/4736 ? And why the tikz? Maybe edit your question: What is the problem you want to solve with this code? – Keks Dose Feb 21 '19 at 12:58
  • Yep, it's similar but I want to automate it and have a single command to put footnotes. I added pic with pointed what's wrong. – Simon Feb 21 '19 at 13:34

0 Answers0