I was trying to do an enumeration with columns, which references one item from another one in the same list. I figured out that the best way is to make a table with enumerated rows. I had a working solution, however next thing I tried to do was to add PDF references with hyperref
package. However, this produces quite strange results.
My solution is three column table: first one is right-aligned for the number of the row, next one has some specified length and the third one uses all the remaining space, therefore tabularx
is needed. A short code sample:
\usepackage{tabularx}
\usepackage{hyperref}
\newcounter{hdItemCounter}
\setcounter{hdItemCounter}{0}
\begin{document}
\begin{tabularx}{\textwidth}{@{}rp{50pt}X}
\refstepcounter{hdItemCounter}\thehdItemCounter.\label{hdItem1} & Some text to fill at least two lines. & Some text\\
\refstepcounter{hdItemCounter}\thehdItemCounter.\label{hdItem2} & Some text. & Some text\\
\refstepcounter{hdItemCounter}\thehdItemCounter.\label{hdItem3} & Some text. & Some text \ref{hdItem2} ir \ref{hdItem1}\\
\refstepcounter{hdItemCounter}\thehdItemCounter.\label{hdItem4} & Some text. & Some text\\
\refstepcounter{hdItemCounter}\thehdItemCounter.\label{hdItem5} & Some text. & Some text \ref{hdItem3} ir \ref{hdItem4} \\
\end{tabularx}
%Some text to fill at least several pages to see the strange effect with hyperref.
\end{document}
I need a lot of such tables, therefore, I created new environment and new \item
-style command:
\newenvironment{someenvironment}[1]%
{\tabularx{\textwidth}{@{}rp{#1}X}}
{\endtabularx}
\newcommand{\someitem}[1]{\refstepcounter{hdItemCounter}\thehdItemCounter.\label{#1} &}
First I was trying to do this with listliketab
, but I wasn't able to put it inside my new environment. However, even without the new environment hyperref
acts strangely. All the references are produced, however they point to wrong places: top of the page is at the line bottom and not at the top:
This can be changed by changing the type of first column to p
:
\begin{tabularx}{\textwidth}{@{}p{10pt}p{50pt}X}
But then again - I need right-aligned first column. Nevertheless, this produces even stranger results: now references point to the top of the number, but the number is placed not at the top of the row:
This problem can be solved by writing something in front of \refstepcounter
:
I\refstepcounter{hdItemCounter}\thehdItemCounter.\label{hdItem1}
By the way, \phantom{I} does not work, however forced space symbol does:
\ \refstepcounter{hdItemCounter}\thehdItemCounter.\label{hdItem1}
I am sorry for the lengthy post, but I wanted to be as specific as I can. Can anyone, please, suggest a better solution to my problem? I need every pt
of the page width in order to display formulas as clearly as possible, therefore it would be very nice to have the r
column and avoid putting space in every line.
I will be really grateful for any help and comments.