1

Look at the text box I create with hyperref. I have documents with over 600 text fields, some of which are constantly changing. Is there any way in hperref to automatically assign the names of the text fields?

\begin{table}[!h]
        \tymin=50pt
        \tymax=\textwidth
        \caption{ASUS Rog Rampage VI Extreme Encore - Erklärung der Rückseitenanschlüsse}
        \begin{tabulary}{18cm}{|L|L|L|} 
            \hline
                Nr  &   Bezeichnung &   Erklärung\\\hline
                %\parbox[POS][HÖHE][POS-INNEN]{BREITE}{INHALT}
                1   &   \makecell[l]{\parbox[0pt][1cm][t]{7cm}{\TextField[name=field1,width=6cm,height=1cm,multiline=true, bordercolor=black]{}}}   & \makecell[l]{\parbox[0pt][1cm][t]{10cm}{\TextField[name=field2,width=9cm,height=1cm,multiline=true, bordercolor=black]{}}}\\ \hline
                2   &   \makecell[l]{\parbox[0pt][1cm][t]{7cm}{\TextField[name=field3,width=6cm,height=1cm,multiline=true, bordercolor=black]{}}}   & \makecell[l]{\parbox[0pt][1cm][t]{10cm}{\TextField[name=field4,width=9cm,height=1cm,multiline=true, bordercolor=black]{}}}\\ \hline   
                3   &   \makecell[l]{\parbox[0pt][1cm][t]{7cm}{\TextField[name=field5,width=6cm,height=1cm,multiline=true, bordercolor=black]{}}}   & \makecell[l]{\parbox[0pt][1cm][t]{10cm}{\TextField[name=field6,width=9cm,height=1cm,multiline=true, bordercolor=black]{}}}\\ \hline   
                4   &   \makecell[l]{\parbox[0pt][1cm][t]{7cm}{\TextField[name=field7,width=6cm,height=1cm,multiline=true, bordercolor=black]{}}}   & \makecell[l]{\parbox[0pt][1cm][t]{10cm}{\TextField[name=field8,width=9cm,height=1cm,multiline=true, bordercolor=black]{}}}\\ \hline   
                5   &   \makecell[l]{\parbox[0pt][1cm][t]{7cm}{\TextField[name=field9,width=6cm,height=1cm,multiline=true, bordercolor=black]{}}}   & \makecell[l]{\parbox[0pt][1cm][t]{10cm}{\TextField[name=field10,width=9cm,height=1cm,multiline=true, bordercolor=black]{}}}\\ \hline      
                6   &   \makecell[l]{\parbox[0pt][1cm][t]{7cm}{\TextField[name=field11,width=6cm,height=1cm,multiline=true, bordercolor=black]{}}}  & \makecell[l]{\parbox[0pt][1cm][t]{10cm}{\TextField[name=field12,width=9cm,height=1cm,multiline=true, bordercolor=black]{}}}\\ \hline
                7   &   \makecell[l]{\parbox[0pt][1cm][t]{7cm}{\TextField[name=field13,width=6cm,height=1cm,multiline=true, bordercolor=black]{}}}  & \makecell[l]{\parbox[0pt][1cm][t]{10cm}{\TextField[name=field14,width=9cm,height=1cm,multiline=true, bordercolor=black]{}}}\\ \hline  
                8   &   \makecell[l]{\parbox[0pt][1cm][t]{7cm}{\TextField[name=field15,width=6cm,height=1cm,multiline=true, bordercolor=black]{}}}  & \makecell[l]{\parbox[0pt][1cm][t]{10cm}{\TextField[name=field16,width=9cm,height=1cm,multiline=true, bordercolor=black]{}}}\\ \hline  
                9   &   \makecell[l]{\parbox[0pt][1cm][t]{7cm}{\TextField[name=field17,width=6cm,height=1cm,multiline=true, bordercolor=black]{}}}  & \makecell[l]{\parbox[0pt][1cm][t]{10cm}{\TextField[name=field18,width=9cm,height=1cm,multiline=true, bordercolor=black]{}}}\\ \hline  
                10  &   \makecell[l]{\parbox[0pt][1cm][t]{7cm}{\TextField[name=field19,width=6cm,height=1cm,multiline=true, bordercolor=black]{}}}  & \makecell[l]{\parbox[0pt][1cm][t]{10cm}{\TextField[name=field20,width=9cm,height=1cm,multiline=true, bordercolor=black]{}}}\\ \hline
                11  &   \makecell[l]{\parbox[0pt][1cm][t]{7cm}{\TextField[name=field21,width=6cm,height=1cm,multiline=true, bordercolor=black]{}}}  & \makecell[l]{\parbox[0pt][1cm][t]{10cm}{\TextField[name=field22,width=9cm,height=1cm,multiline=true, bordercolor=black]{}}}\\ \hline
                12  &   \makecell[l]{\parbox[0pt][1cm][t]{7cm}{\TextField[name=field23,width=6cm,height=1cm,multiline=true, bordercolor=black]{}}}  & \makecell[l]{\parbox[0pt][1cm][t]{10cm}{\TextField[name=field24,width=9cm,height=1cm,multiline=true, bordercolor=black]{}}}\\ \hline
                13  &   \makecell[l]{\parbox[0pt][1cm][t]{7cm}{\TextField[name=field25,width=6cm,height=1cm,multiline=true, bordercolor=black]{}}}  & \makecell[l]{\parbox[0pt][1cm][t]{10cm}{\TextField[name=field26,width=9cm,height=1cm,multiline=true, bordercolor=black]{}}}\\ \hline  
        \end{tabulary}
    \end{table}
Z.J
  • 389
  • 3
    make a complete and small example. There is no need to show 26 fields (which would have to be changed to show a solution). – Ulrike Fischer Jul 26 '22 at 11:46

1 Answers1

0

I would define a custom macro that takes an integer as argument and outputs one full table row consisting of a row number and the necessary fields with the appropriate names. If you combine this with a counter, you don't even need to input the number every time.

In the following example, I defined a new counter tablrownum that initially is set to 1. The value of this counter is taken as argument to the macro \tablrow if no explicit argument is provided. On each call of \tablrow, the counter is increased by one. If an explicit argument is provided, the counter is set to the value of this argument (and increased by one).

Note that you need to reset the counter to 1 inside the tabluary environment because tabulary will run the contents of the environment several times which would increase the counter every time.

The fields are automatically named nameX and descX where X is the number of the table row (or the number explicitly stated using the optional argument of \tablrow).

\documentclass{article}
\usepackage[margin=1.25cm]{geometry}
\usepackage{xcolor}
\usepackage{tabulary}
\usepackage{makecell}
\usepackage{hyperref}

\newcounter{tablrownum} \newcommand{\tablrow}[1][\thetablrownum]{ #1 &
\makecell[l]{\parbox[0pt][1cm][t]{7cm}{\TextField[name=name#1,width=6cm,height=1cm,multiline=true, bordercolor=black]{}}} & \makecell[l]{\parbox[0pt][1cm][t]{10cm}{\TextField[name=desc#1,width=9cm,height=1cm,multiline=true, bordercolor=black]{}}} \ifnum#1=\thetablrownum\stepcounter{tablrownum}\else\setcounter{tablrownum}{\numexpr#1+1\relax}\fi }

\begin{document}

\begin{table}[!h]
    \tymin=50pt
    \tymax=\textwidth
    \caption{ASUS Rog Rampage VI Extreme Encore -- Erklärung der Rückseitenanschlüsse}
    \begin{tabulary}{18cm}{|L|L|L|} 
        \hline\setcounter{tablrownum}{1}
        Nr & Bezeichnung & Erklärung \\ \hline
        \tablrow \\ \hline 
        \tablrow \\ \hline
        \tablrow \\ \hline
        \tablrow \\ \hline
        \tablrow \\ \hline
        \tablrow[20] \\ \hline
        \tablrow \\ \hline
    \end{tabulary}
\end{table}

\end{document}

enter image description here

  • Thank you. Question: How does your command \tablrow know to start with 1? – Z.J Jul 26 '22 at 13:05
  • At the beginning of the tabulary, I placed \setcounter{tablrownum}{1} which sets the counter tablrownum to 1. The value of this counter is taken as argument to \tablrow if you don't provide an explicit argument. On each call of \tablrow, the counter tablrownum is increased by one. If you provide an explicit argument to \tablrow, the counter tablrownum is set to this explicit value (and increased by one). – Jasper Habicht Jul 26 '22 at 13:13
  • 1
    Thank you very much. The example works well and has sparked my interest in macros. Unfortunately, I don't understand one part of your solution. What exactly is the purpose of [\thetablrownum] in the macro header. Are you defining an environment varaible here? – Z.J Jul 26 '22 at 13:40
  • No. If you define a counter, like I did with \newcounter{tablrownum}, then you can access the current value of this counter using \the<counter name>. Hence, \thetablrownum returns the current value of the counter tablrownum. The macro definition \newcommand{\tablrow}[1][\thetablrownum]{...} means: Create a new macro with the name \tablrow that takes one ([1]) optional argument which should take the value of \thetablrownum per default (if it is not explicitly given). – Jasper Habicht Jul 26 '22 at 13:42
  • Thanks for your help. Can you recommend a book or internet source where you can read about this? – Z.J Jul 26 '22 at 13:53
  • Maybe have a look at this question: https://tex.stackexchange.com/q/11/47927 – Jasper Habicht Jul 26 '22 at 14:26
  • 1
    Good link, quite long. @ZJ, you can also have a read here: https://en.wikibooks.org/wiki/LaTeX/Macros . // It's good practice to place a comment % immediately at the end of each macro-line to avoid spurious spaces in "print". // To find examples here, you might use https://tex.stackexchange.com/questions/tagged/macros and add more keywords to the search field. // BTW, \def was used in TeX, and should be \newcommand in LaTeX. – MS-SPO Aug 26 '22 at 06:44