2

Does it exist a command like pageref with which I can indicate the column too? (I am writing a two-column text and I would like to give an indication more precise than the simple page).

2
  • Do you just want to print 1 or 2 as the output?
    – Werner
    Commented Feb 11, 2021 at 23:28
  • Yes, or something like 5/1 and 5/2 (or 5-1 and 5-2) for page and column. Any suggestion would be appreciated.
    – Gippo
    Commented Feb 11, 2021 at 23:31

1 Answer 1

1

Detecting/tracking the (current) column is not easy. However, a somewhat simplistic yet effective way of identifying the column can be done by labelling the x-coordinate on the page. If that x-coordinate is less than half the page width, you should be within the left (first) column, otherwise you're in the right (second) column.

Here is that implementation using the savepos module from zref:

enter image description here

\documentclass[twocolumn]{article}

\usepackage{xcolor}
\usepackage[savepos]{zref}

\newcommand{\columnlabel}[1]{\label{#1}\zsaveposx{#1}}
\newcommand{\columnref}[1]{%
  \ifdim\zposx{#1}sp<.5\pdfpagewidth
    left% column 1
  \else
    right% column 2
  \fi
}

\usepackage{lipsum}

\begin{document}

\sloppy% Just for this example
\lipsum[1-5]
\textcolor{red}{\columnlabel{important}Some important text}%

\lipsum[6-10]

See \textcolor{red}{page~\pageref{important} (\columnref{important} column)}.

\end{document}

You could update \columnref to output something of the format <page>-<column> in the following way:

% Output <page>-<column> as a reference
\newcommand{\columnref}[1]{%
  \pageref{#1}-%
  \ifdim\zposx{#1}sp<.5\pdfpagewidth
    1% column 1
  \else
    2% column 2
  \fi
}
2
  • Thanks. Just a minor esthetic thing. I am sorry but I do not undersand how to properly write a code section in a comment. I want to add an hyperlink with something like this code \lipsum[1-5] \phantomsection\label{mylabel}{Important text} \lipsum[6-10] Check out in the document at Pag.~\columnref{mylabel}. code The red box of the link is only around the page number. Is it poss ible to make it larger so as to include the column number too?
    – Gippo
    Commented Feb 11, 2021 at 23:54
  • 1
    @Gippo: Use the definitions in this example.
    – Werner
    Commented Feb 11, 2021 at 23:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .