更新 20220906

更新 20220906

我想在索引条目中显示行号,就像这个问题显示词汇表中的行号. 测试代码如下

\documentclass{report}

\usepackage{xcolor}

%%%%%%%%LINE NUMBER
\usepackage[running]{lineno} %[switch,columnwise,pagewise]

\renewcommand\thelinenumber{{\arabic{linenumber}}}
\renewcommand\linenumberfont{\color{red}}
\modulolinenumbers[1]

\usepackage[centering,top=4cm,bottom=4cm,left=4cm,right=4cm,headsep=0.5cm,footskip=0cm,columnsep=50pt]{geometry}
\setlength\linenumbersep{0.29cm}
\setlength{\linenumberwidth}{4mm}

\usepackage{etoolbox}
\preto{\sffamily}{\resetlinenumber}%resetting line num to 1 per page

\usepackage[pagestyles]{titlesec}
\newpagestyle{mapage}{%
    \sethead[][\sffamily\bfseries\textcolor{blue}{\thepage}][]
    {}{\sffamily\bfseries\textcolor{blue}{\thepage}}{}%odd head
    \setfoot[][][]%even foot
    {}{}{}
}



\newcommand{\llabel}[1]{\hypertarget{llineno:#1}{\linelabel{#1}\labelcolumnline{#1}}}
\newcommand{\lref}[1]{\hyperlink{llineno:#1}{\ref*{#1}}}
\newcommand{\lpageref}[1]{\hyperlink{llineno:#1}{\pageref*{#1}}}


% https://tex.stackexchange.com/questions/516140/columnwise-line-numbering-in-a-two-column-environment-with-multicol
% \setlength{\columnsep}{1cm}
\newlength{\midpage}
\setlength{\midpage}{.5\paperwidth}
\usepackage{zref-savepos}
\newcommand\labelcolumnline[1]{%
    \hypertarget{llineno:#1}{\zsavepos{#1}%
        \linelabel{#1}}%
}

\newcommand\refcolumnline[1]{%
    \ifnum\number\zposx{#1}>\number\midpage\relax \textbf{R}\else \textbf{L}\fi%
    \hyperlink{llineno:#1}{\ref{#1}}%
}

%%%%%%%%
\newcommand{\pclref}[1]{[\textit{P\lpageref{#1}/\refcolumnline{#1}}]}

\usepackage[hidelinks,colorlinks=false,breaklinks=true,urlcolor=red]{hyperref}

\usepackage{imakeidx}
\usepackage{blindtext}
\makeindex[name=lineno,title={Index with Line Number}]


%%%%%%DEFINE LINE NUMBER INDEX
\newcommand{\lindex}[1]{\textcolor{blue}{\textbf{\textit{#1}}}\index[lineno]{#1| \textbf{L\thelinenumber}-P}}%% ?????????

\pagestyle{mapage}
\begin{document}
    \twocolumn
    \linenumbers
    
    \textbf{TEST Left}\llabel{TEST1}
    
LONDON, Sept 5 (Reuters) - Liz Truss will become Britain's next prime minister after winning a leadership race for the governing \lindex{Conservative Party} on Monday, vowing to press ahead with promised tax cuts and action to tackle a deepening energy and cost of living crisis.Register now for \lindex{FREE} unlimited access to Reuters.com

Truss beats ex-finance minister Sunak to be new PM
Boris Johnson to formally step down on Tuesday
New leader faces cost of living, energy price crisis

LONDON, Sept 5 (Reuters) - Liz Truss will become Britain's next prime minister after winning a leadership race for the governing Conservative Party on Monday, vowing to press ahead with promised tax cuts and action to tackle a deepening energy and cost of living crisis.

After weeks of an often bad-tempered and divisive leadership contest, Truss, currently the foreign minister and the favourite to win, beat former finance minister Rishi Sunak in a vote of Conservative Party members, winning by 81,326 votes to 60,399.
Advertisement · Scroll to continue

"I will deliver a bold plan to cut taxes and grow our economy," Truss said after the result was announced. "I will deliver on the energy crisis, dealing with people's energy bills, but also dealing with the long-term issues we have on energy supply." read more

Truss takes over as the country faces a crunch on household finances, industrial unrest, a recession and war in Europe, where Britain has been a leading backer of Ukraine. She appeared to rule out another national election before 2024, when she promised to deliver a great victory for her party.

After weeks of an often bad-tempered and divisive leadership contest, Truss, currently the foreign minister and the favourite to win, beat former finance minister Rishi Sunak in a vote of Conservative Party members, winning by 81,326 votes to 60,399.
    
    \textbf{TEST Right}
     \llabel{TEST2} 
    
    LONDON, Sept 5 (Reuters) - Liz Truss will become Britain's next prime minister after winning a leadership race for the governing Conservative Party on Monday, vowing to press ahead with promised tax cuts and action to tackle a deepening energy and cost of living crisis.
    
    After weeks of an often bad-tempered and divisive leadership contest, Truss, currently the foreign minister and the favourite to win, beat former finance minister \lindex{Rishi Sunak} in a vote of Conservative Party members, winning by 81,326 votes to 60,399.Register now for FREE unlimited access to Reuters.com
    
    Summary
    
    Truss beats ex-finance minister Sunak to be new PM
    \lindex{Boris Johnson} to formally step down on Tuesday
    New leader faces cost of living, energy price crisis
    
    LONDON, Sept 5 (Reuters) - Liz Truss will become Britain's next prime minister after winning a leadership race for the governing Conservative Party on Monday, vowing to press ahead with promised tax cuts and action to tackle a deepening energy and cost of living crisis.
    
    After weeks of an often bad-tempered and divisive leadership contest, Truss, currently the foreign minister and the favourite to win, beat former finance minister Rishi Sunak in a vote of Conservative Party members, winning by 81,326 votes to 60,399.
    Advertisement · Scroll to continue
    
    "I will deliver a bold plan to cut taxes and grow our economy," Truss said after the result was announced. "I will deliver on the energy crisis, dealing with people's energy bills, but also dealing with the long-term issues we have on energy supply." read more
    
    Truss takes over as the country faces a crunch on \lindex{household} finances, industrial unrest, a recession and war in Europe, where Britain has been a leading backer of Ukraine. She appeared to rule out another national election before 2024, when she promised to deliver a great victory for her party.\llabel{TEST3} 
    
    
    \pclref{TEST1} in Page \lpageref{TEST1} Left Line \lref{TEST1}
    
    \pclref{TEST2} in Page \lpageref{TEST2} Right Line \lref{TEST2}
    
    \pclref{TEST3} in Page \lpageref{TEST3} Left Line \lref{TEST3}
    
    \onecolumn
    \nolinenumbers
    \printindex[lineno]
\end{document}

然后输出的是错误的行信息,如何获取像P7/L16或P7/R17这样的索引条目页面样式?

谢谢!

应该是这个

错误输入信息

更新 20220906

参照@Cicada的笔记,我通过 重置了每页的行数\usepackage{etoolbox}\preto{\sffamily}{\resetlinenumber},并使用 引入了 lineno 包跑步标签。然后索引中的行号显示几乎正确,但不正确。

输出的行号是该条目所在段落第一行的行号:

在此处输入图片描述

索引输出如下: 在此处输入图片描述

那么为什么这么奇怪?

相关内容