表格中的词汇表超链接不起作用

表格中的词汇表超链接不起作用

我正在制作一个以两列表格形式显示的词汇表,但当我使用此自定义样式时,超链接现在不再起作用。有人能解释如何修复这个问题吗?

\documentclass{article}

\usepackage[cmyk]{xcolor}
\usepackage[colorlinks=true, urlcolor=blue]{hyperref}

\usepackage{calc}
\usepackage{booktabs}
\usepackage[toc]{glossaries}

\makeglossaries

\newglossaryentry{TE}
{
    name={TE},
    description={Time Electric\nopostdesc}
}

\glsaddall

\newlength\maxlength
\newlength\thislength

\newglossarystyle{mystyle}
{%
    \renewenvironment{theglossary}%
    {% start of glossary
        % Find maximum width of the first column:
        \setlength{\maxlength}{0pt}%
        \forglsentries[\currentglossary]{\thislabel}%
        {%
            \settowidth{\thislength}{\glsentryshort{\thislabel}}%
            \ifdim\thislength>\maxlength
            \setlength{\maxlength}{\thislength}%
            \fi
        }%
        % Now calculate the width of the second column:
%        \settowidth{\thislength}{\hspace{1.5em}=\hspace{1em}}%
        \setlength{\glsdescwidth}{\linewidth-\maxlength-\thislength-2\tabcolsep}%
        % Start the tabular environment
        \begin{tabular}{ccc@{}p{\glsdescwidth}}
            \toprule
            \toprule
            \multicolumn{1}{c}{\textbf{Abbreviation}} &
            \multicolumn{1}{c}{\textbf{Definition}}\\%
            \midrule
        }%
        {% end of glossary
            \bottomrule
        \end{tabular}%
    }%
    % Header has been incorporated into \begin{theglossary}
    \renewcommand*{\glossaryheader}{}%
    % Don't do anything between letter groups
    \renewcommand*{\glsgroupheading}[1]{}%
    \renewcommand*{\glsgroupskip}{}%
    % Set display for each the acronym entry
    \renewcommand{\glossentry}[2]{%
        \textbf{\glossentryname{##1}}{\glsentryshort{##1}}% short form
        &
        \glossentrydesc{##1}% long form
        \\% end of row
    }%
    % No sub-entries, so \subglossentry doesn't need redefining
}

\begin{document}

    Use: \gls{TE} \newpage

    \printglossary[nonumberlist, style=mystyle]
\end{document}

答案1

\glossentry命令缺少将命令\glstarget{##1}{...}的超目标设置\gls...为打印的词汇表。

\documentclass{article}

\usepackage[cmyk]{xcolor}
\usepackage[colorlinks=true, urlcolor=blue]{hyperref}

\usepackage{calc}
\usepackage{booktabs}
\usepackage[toc]{glossaries}

\makeglossaries

\newglossaryentry{TE}
{
    name={TE},
    description={Time Electric\nopostdesc}
}

\glsaddall

\newlength\maxlength
\newlength\thislength

\newglossarystyle{mystyle}
{%
    \renewenvironment{theglossary}%
    {% start of glossary
        % Find maximum width of the first column:
        \setlength{\maxlength}{0pt}%
        \forglsentries[\currentglossary]{\thislabel}%
        {%
            \settowidth{\thislength}{\glsentryshort{\thislabel}}%
            \ifdim\thislength>\maxlength
            \setlength{\maxlength}{\thislength}%
            \fi
        }%
        % Now calculate the width of the second column:
%        \settowidth{\thislength}{\hspace{1.5em}=\hspace{1em}}%
        \setlength{\glsdescwidth}{\linewidth-\maxlength-\thislength-2\tabcolsep}%
        % Start the tabular environment
        \begin{tabular}{ccc@{}p{\glsdescwidth}}
            \toprule
            \toprule
            \multicolumn{1}{c}{\textbf{Abbreviation}} &
            \multicolumn{1}{c}{\textbf{Definition}}\\%
            \midrule
        }%
        {% end of glossary
            \bottomrule
        \end{tabular}%
    }%
    % Header has been incorporated into \begin{theglossary}
    \renewcommand*{\glossaryheader}{}%
    % Don't do anything between letter groups
    \renewcommand*{\glsgroupheading}[1]{}%
    \renewcommand*{\glsgroupskip}{}%
    % Set display for each the acronym entry
    \renewcommand{\glossentry}[2]{%
      \phantomsection
        \glstarget{##1}{\textbf{\glossentryname{##1}}{\glsentryshort{##1}}}% short form
        &
        \glossentrydesc{##1}% long form
        \\% end of row
    }%
    % No sub-entries, so \subglossentry doesn't need redefining
}

\begin{document}

    Use: \gls{TE} \newpage

    \printglossary[nonumberlist, style=mystyle]
\end{document}

相关内容