8

I need to point to a label on a page, but as my text is layed out in two columns, I'd also like to include the column (1 or 2). Is there a way to find out which column a label is in?

\documentclass{icgg}
\begin{document}
\section{First chapter}
\label{explanation}
Some text explaining some things.
...
... see page \pageref{explanation} for ...

\end{document}    

I'd like to use something like:

see page \pageref{explanation}, column \columnref{explanation} for ...

Possible?

ps. the document class is provided by someone else and it defines the two-column format.

4

1 Answer 1

4

This is an attempt.

The class icgg.cls loads hyperref. We create a new command \collabel which is executed each time a \label command is issued.

If, for example, you issue \label{foo} a new label called col:foo is created at the same point of the document. if you want to know the column to which \label{foo} refers to, you have to use the command \columnref{col:foo}.

Here's an example (replace \documentclass[twocolumn]{article} \usepackage{hyperref} with \documentclass{icgg} in your document):

\documentclass[twocolumn]{article}
\usepackage{hyperref}
\usepackage{lipsum} %only for the example

\makeatletter
\AtBeginDocument{%
\let\oldlabel\label
\newcommand*\collabel[1]{%
  \begingroup
    \protected@write\@auxout{}{%
      \string\newlabel{col:#1}{%
        {\if@firstcolumn 1\else 2\fi}%
        {}%
        {}%
        {}%
        {}%
      }%
    }%
  \endgroup
}
\renewcommand*\label[1]{%
  \collabel{#1}\oldlabel{#1}
}
\def\columnref#1{%
  \HyRef@StarSetRef{#1}\@firstoffive
}
}
\makeatother

\begin{document}

\section{First section}\label{sec:first}
\lipsum[1-4]

\section{Second section}\label{sec:second}
\lipsum[1-3]\label{sec:third}

Section \ref{sec:first} starts at page \pageref{sec:first} in column \columnref{col:sec:first}, 
while section \ref{sec:second} starts at page \pageref{sec:second} in column \columnref{col:sec:second}

\end{document} 

Output:

enter image description here

Zoom on the relevant part:

enter image description here

Note that the command \if@firstcolumn sometimes fails to detect the right column, so you may have some wrong references.

You must log in to answer this question.

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