如何将标题设为链接目标?

如何将标题设为链接目标?

在此处输入图片描述 第二个框的链接有效,但第一个框无效。我想链接标题,这样BCMP我就可以在任何位置使用链接词到达标题。完整源文件 --

    \documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[utf8]{inputenc}
\else % if luatex or xelatex
  \ifxetex
    \usepackage{mathspec}
    \usepackage{xltxtra,xunicode}
  \else
    \usepackage{fontspec}
  \fi
  \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
  \newcommand{\euro}{€}
\fi
% use microtype if available
\IfFileExists{microtype.sty}{\usepackage{microtype}}{}
\usepackage{longtable,booktabs}
\ifxetex
  \usepackage[setpagesize=false, % page size defined by xetex
              unicode=false, % unicode breaks when used with xetex
              xetex]{hyperref}
\else
  \usepackage[unicode=true]{hyperref}
\fi
\hypersetup{breaklinks=true,
            bookmarks=true,
            pdfauthor={},
            pdftitle={BCMP(3)},
            colorlinks=true,
            citecolor=blue,
            urlcolor=blue,
            linkcolor=magenta,
            pdfborder={0 0 0}}
\urlstyle{same}  % don't use monospace font for urls
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\setcounter{secnumdepth}{0}
\usepackage{pagecolor}

% Set background colour (of the page)
\definecolor{weirdbgcolor}{HTML}{FCF4F0}
\pagecolor{weirdbgcolor}

% Make bold text appear in a particular colour
\definecolor{boldcolor}{HTML}{6E0002}
\let\realtextbf=\textbf
\renewcommand{\textbf}[1]{\textcolor{boldcolor}{\realtextbf{#1}}}

% Use underlines instead of emphasis (ugh)
\renewcommand{\emph}[1]{\underline{#1}}

% % Use fixed-width font by default
% \renewcommand*\familydefault{\ttdefault}

\hyperdef{}{BCMP}{\title{BCMP(3)}\label{BCMP}}
\author{}
\date{}

\begin{document}
\maketitle

\begin{longtable}[c]{@{}lll@{}}
\toprule\addlinespace
\hyperdef{}{BCMP}{BCMP\label{BCMP}}(3) & Linux Programmer's Manual & BCMP(3)
\\\addlinespace
\bottomrule
\end{longtable}

\hyperdef{}{NAME}{\section{\hyperref[NAME]{NAME}}\label{NAME}}

bcmp - compare byte sequences

\hyperdef{}{SYNOPSIS}{\section{\hyperref[SYNOPSIS]{SYNOPSIS}}\label{SYNOPSIS}}

\begin{verbatim}
#include <strings.h>

int bcmp(const void *s1, const void *s2, size_t n);
\end{verbatim}

\hyperdef{}{DESCRIPTION}{\section{\hyperref[DESCRIPTION]{DESCRIPTION}}\label{DESCRIPTION}}

\hyperref[BCMP]{BCMP}The \textbf{bcmp}() function compares the two byte sequences \emph{s1}
and \emph{s2} of length \emph{n} each. If they are equal, and in
particular if \emph{n} is zero, \textbf{bcmp}() returns 0. Otherwise it
returns a nonzero result.

\hyperdef{}{RETURNux5fVALUE}{\section{\hyperref[RETURNux5fVALUE]{RETURN
VALUE}}\label{RETURNux5fVALUE}}

The \textbf{bcmp}() function returns 0 if the byte sequences are equal,
otherwise a nonzero result is returned.

\hyperdef{}{CONFORMINGux5fTO}{\section{\hyperref[CONFORMINGux5fTO]{CONFORMING
TO}}\label{CONFORMINGux5fTO}}

4.3BSD. This function is deprecated (marked as LEGACY in POSIX.1-2001):
use \textbf{memcmp}(3) in new programs. POSIX.1-2008 removes the
specification of \textbf{bcmp}().

\hyperdef{}{SEEux5fALSO}{\section{\hyperref[SEEux5fALSO]{SEE
ALSO}}\label{SEEux5fALSO}}

\textbf{memcmp}(3), \textbf{strcasecmp}(3), \textbf{strcmp}(3),
\textbf{strcoll}(3), \textbf{strncasecmp}(3), \textbf{strncmp}(3)

\hyperdef{}{COLOPHON}{\section{\hyperref[COLOPHON]{COLOPHON}}\label{COLOPHON}}
\hyperref[BCMP]{BCMP}

This page is part of release 3.54 of the Linux \emph{man-pages} project.
A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.

\begin{longtable}[c]{@{}ll@{}}
\toprule\addlinespace
2008-08-06 & Linux
\\\addlinespace
\bottomrule
\end{longtable}

\end{document}

这是延伸问题如何从 Linux 手册页创建 pdf 以保留样式?

答案1

从显示的 hacking 来看,\hyperdef我不太明白你在做什么。但你应该注意,\title{…}不打印任何内容,而只定义一个内部值,该值用于\maketitle打印标题。因此,如果你想有一个带标题的超级目标,那么超级目标的定义必须在参数内\title。出于同样的原因,\label文档序言后面的a 和之前的\title{…}一样没用。\label\begin{document}

另外,章节标题的超目标定义最好在\section参数内部定义,但在这种情况下,这样的定义大多是不需要的,因为你可以用来\nameref链接到章节名称和\autoref/或\ref链接到章节编号:

\documentclass[]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{hyperref}
\title{\hypertarget{BCMP}{BCMP(3)}}
\author{}
\date{}

\begin{document}
\maketitle

\section{NAME}\label{NAME}

\clearpage

\section{Next}\label{sec:Next}

\hyperlink{BCMP}{BCMP} and \nameref{NAME} to \autoref{NAME}.


\end{document}

最后一页有链接

相关内容