6

I create a link with \nameref:

\section*{\Huge {\color{DarkRed}This is a headline}}
\label{sec:headline}

When I reference to this section with

\nameref{sec:headline}

The link is displayed the same size (Huge) and color (Dark Red) as the section title.

The hyperref setup is:

\usepackage[colorlinks=true,linkcolor=black]{hyperref}

How can I avoid that link color and size are taken from the section setup. I want to keep them independent from one another.

EDIT: Minimal working example:

\documentclass{article}

\usepackage[colorlinks=true,linkcolor=black]{hyperref}
\begin{document}

\nameref{sec:headline}

\newpage
\section*{\Huge {\color{red}This is a headline}}
 \label{sec:headline}

\end{document}
2
  • Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. Feb 23, 2013 at 14:47
  • 1
    Don't use any font commands as an argument of \section! Feb 23, 2013 at 14:48

2 Answers 2

3

If you want to change the appearance in general, then use a more powerful class (scrartcl/KOMA-Script, memoir, …) or a package (sectsty, …):

  • Then you have a clean markup.
  • It also works for the table of contents or the page headers.

Package gettitlestring

Package hyperref uses package nameref. Since 2009/12/08 it uses package gettitlestring to get and process the title data. With method expand commands can be redefined via \GetTitleStringDisableCommands similar to hyperref's \pdfstringdefDisableCommands for bookmarks.

\documentclass{article}

\usepackage[colorlinks=true,linkcolor=black]{hyperref}
\usepackage{nameref}[2009/12/08]% uses package `gettitlestring'

\GetTitleStringSetup{expand}
\GetTitleStringDisableCommands{%
  \let\Huge\empty % disables \Huge
  % or \renewcommand*{\Huge}{}%
  \let\color\@gobble % disables \color{...}
  % or \renewcommand*{\color}[1]{}%
}

\begin{document}

\nameref{sec:headline}

\newpage
\section*{\Huge {\color{red}This is a headline}}
 \label{sec:headline}

\end{document}

However, only expandable redefinitions can be used. LaTeX's scanning for optional arguments does not work.

2
  • In my opinion you has provided a workaround instead of a "clear" solution. With the mentioned classes of KOMA you can set the font eg. by addkomafont what should be the correct answer here (This is my personal opinion) Feb 23, 2013 at 15:51
  • 1
    @MarcoDaniel The question is not clear, if a solution for all sections headers is needed or if only a particular \section is affected. Right at the beginning I have given the general solutions. The documentation of the classes and packages should be sufficient and there are probably quite a few "duplicate" questions. However I have some doubts that the workaround solution, which is useful for some circumstances, has already hit common knowledge. Feb 23, 2013 at 16:14
0

If I understand it correctly with komascript it is fairly easy:

\documentclass{scrartcl}

\usepackage[colorlinks=true,linkcolor=black]{hyperref}

 \setkomafont{section}{\Huge \color{red}}                                                                                                                 
\begin{document}

\nameref{sec:headline}

\newpage
\section*{This is a headline}
\label{sec:headline}

\end{document}

You must log in to answer this question.

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