\pageref, pero para la parte superior/media/inferior de la página

\pageref, pero para la parte superior/media/inferior de la página

He elaborado mi pregunta como MWE:

\documentclass[twocolumn]{article}
\usepackage{lipsum}
\newcommand{\topbottom}[1]{top}
\newcommand{\leftright}[1]{right}
\begin{document}
    \lipsum[1-4]
    Look for this! \label{mylabel}
    \lipsum[5-7]

    What you are looking for would be so much easier to find if you knew 
    not only that it's on page \pageref{mylabel}, but also, that it's at 
    the \topbottom{mylabel} of the \leftright{mylabel} column. 

    How to do this?
\end{document}

Desde entonces he encontrado\pageref, pero para columnas, que responde a la segunda parte de mi pregunta, sugiriendo efectivamente una implementación a \leftrighttravés de \columnref. Pero para el primero y \topbottomrealmente no encuentro nada útil.

Respuesta1

Esto funciona sorprendentemente bien, con y sin hyperref/ cleveref:

\documentclass[twocolumn]{article}
% optional package for testing
\usepackage{hyperref}

% Solution: put *after* \usepackage{hyperref}, but *before* \usepackage{cleveref}
% ===============================================================================
\RequirePackage[savepos]{zref}
\RequirePackage{ifthen}
\makeatletter
\newlength{\ref@loc}%
\newcommand{\refloc}[4]{%
    \zref@ifrefundefined{#1}{\PackageWarning{\string\refloc}{Location of `#1' on page \thepage \space  undefined}\textbf{???}}{%
        \setlength{\ref@loc}{#2}%
        \ifthenelse{\lengthtest{\ref@loc < 0pt}}{#3}{#4}%
    }%
}
\makeatother

\RequirePackage{calc}
\newcommand{\topbottom}[1]{\refloc{#1}{\zposy{loc:ref}sp-\zposy{#1}sp-\textheight/2}{top}{bottom}}
\newcommand{\leftright}[1]{\refloc{#1}{\zposx{#1}sp-\zposx{loc:ref}sp-\textwidth/2}{left}{right}}

% http://tex.stackexchange.com/a/351172/30810
\RequirePackage{regexpatch}
\AtBeginDocument{%
    \zsavepos{loc:ref}%
    \makeatletter%
    \regexpatchcmd{\label}{\A}{\c{zsavepos}\cB\{\cP\#1\cE\}}{}{\err}%
    \makeatother%
}
% ===============================================================================

% optional package for testing
\usepackage{cleveref}
\providecommand{\cref}[1]{\ref{#1}}

% for example output only
\usepackage{lipsum}
\usepackage[columnwise,switch]{lineno}
\linenumbers
\begin{document}
    \section{Section}

    \label{mylabel1} 1 \lipsum[1]
    \label{mylabel2} 2 \lipsum[2]
    \label{mylabel3} 3 \lipsum[3]
    \label{mylabel4} 4 \lipsum[2]
    \label{mylabel5} 5 \lipsum[2]

    \label{mylabel6} 6 (line 23/46 =  top)

    \label{mylabel7} 7 (line 24/46 = bottom)

    \label{mylabel8} 8 \lipsum[2]
    \label{mylabel9} 9 \lipsum[2]

    What you are looking for is so much easier to find
    when you know that it's 
    \begin{enumerate}
        \item at the \topbottom{mylabel1} of the \leftright{mylabel1} column on page \pageref{mylabel1},
        \item at the \topbottom{mylabel2} of the \leftright{mylabel2} column on page \pageref{mylabel2},
        \item at the \topbottom{mylabel3} of the \leftright{mylabel3} column on page \pageref{mylabel3},
        \item at the \topbottom{mylabel4} of the \leftright{mylabel4} column on page \pageref{mylabel4},
        \item at the \topbottom{mylabel5} of the \leftright{mylabel5} column on page \pageref{mylabel5},
        \item at the \topbottom{mylabel6} of the \leftright{mylabel6} column on page \pageref{mylabel6},
        \item at the \topbottom{mylabel7} of the \leftright{mylabel7} column on page \pageref{mylabel7},
        \item at the \topbottom{mylabel8} of the \leftright{mylabel8} column on page \pageref{mylabel8},
        \item at the \topbottom{mylabel9} of the \leftright{mylabel9} column on page \pageref{mylabel9},
        \item at the \topbottom{mylabelX} of the \leftright{mylabelX} column on page \pageref{mylabelX}.
    \end{enumerate}

    A test clevereference: \cref{mylabel1}
\end{document}

información relacionada