Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using the package xcolor to provide colorful \section titles. It looks great but when I make a .pdf, the color name appears before the section name in the .pdf's hyperlinked organizational "tree".

For example, in the left pane of my .pdf reader I see the following:

ForestGreenIntroduction

I'd like it to read:

Introduction

Can I suppress the color name somehow?

share|improve this question
    
Please add an example that includes the relevant code, especially how the color is implemented in your section headers –  Martin H Sep 5 '12 at 11:31
    
The answer may be in the \texorpdfstring macro... But without a MWE, my crystal ball is broken. –  Paul Gaborit Sep 5 '12 at 11:33
    
I'm using the following code in the header: \usepackage[usenames,dvipsnames,svgnames,table]{xcolor} Here is the code for the sections themselves: \section{\color{ForestGreen}Rhetoric And Composition} –  Larry Tate Sep 5 '12 at 11:49
    
change the code for sections to : {\color{ForestGreen}\section{Rhetoric And Composition}} as a workaround. Depending on your used document class I'm sure there are better ways to define the section color. –  Kurt Sep 5 '12 at 12:02
add comment

4 Answers

up vote 3 down vote accepted

Using \textcolor instead of \color should work: replace

\section{\color{ForestGreen}Rhetoric And Composition}

by

\section{\textcolor{ForestGreen}{Rhetoric And Composition}}

Remember that it is always helpful for others to include a minimal working example to your question. In your case, it may have looked like (if I have understood properly):

\documentclass{article}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{hyperref}

\begin{document}

\tableofcontents

\section{\color{ForestGreen}Rhetoric And Composition}

\end{document}

Edit: as Kurt just commented, if you want to stick with \color, there is also this solution:

{\color{ForestGreen}\section{Rhetoric And Composition}}

Note that in this case the section title does not appeared colored in the table of contents, only in the body.

share|improve this answer
    
Thank you, that works perfectly. I'm rather new at LaTex but this site has been a great help. –  Larry Tate Sep 5 '12 at 12:12
add comment

The accepted answer will work (and I don't suggest you unaccept it:-) but it is wrong to use a color command in a section heading for the same reason that you should use \section rather than just going {\large\textbf{section 1}}.

You should view color changes like font changes and if your document style says that section headings should be in a large bold green font the green bit of that definition should be specified at the same place as the large and bold bits, which is in the definition of \section as provided by the class.

article class defines

\newcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\Large\bfseries}}

so if you had

\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\Large\bfseries\color{ForestGreen}}}
\makeatother

You could go

\section{Rhetoric And Composition}

and get Large bold green text without distorting the logical nature of the section heading (which can then be used for other purposes, in other sizes and colours in tables of contents and page headings)

share|improve this answer
    
I agree that this is much more elegant (and natural) than my proposed answer. Thanks for the explanation. –  Corentin Sep 5 '12 at 13:11
add comment

Addition to Corentin Herbert's answer:

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{hyperref}
\usepackage{bookmark}
\pdfstringdefDisableCommands{%
  \def\color#1#{\@gobble}%
}
\begin{document}
\section{\color{ForestGreen}Hello World}
\end{document}

If section titles including the number should be colored this way, then there are better ways, e.g.:

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{titlesec}
\usepackage{hyperref}
\usepackage{bookmark}
\bookmarksetup{
  numbered,
  open,
  addtohook={%
    \ifnum\bookmarkget{level}=1 %
      \bookmarksetup{color=ForestGreen}%
    \fi
  },
}
\titleformat*{\section}{\color{ForestGreen}}

\begin{document}
\tableofcontents
\section{Hello World}
\subsection{Foobar}
\end{document}

The example also uses color for section bookmarks.

Result

share|improve this answer
add comment

If you just want to change the color for one section you can use

\section[<Text>]{\color{<color>}<text>}

The text in the optional part, i.e., [<Text>] is used for the table of context and similar. A problem with the solution is that it does not change the color of the section number. For that you have to redefine the \section command. titlesec package offers simple ways to do it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.