# What to renew to change LOF/LOT links?

Consider the MWE below. I use TIKZ-customization for nice link underlines. (using renewcommand for ref), which I for this MWE replace by \textcolor{red} (so textcolor is not the goal)

As you can see:

• The TOC has now a red pagenumber;
• The List of Tables (LOT) has NOT a red pagenumber;
• The link in the chapter is customized (red color).

The question now is: what do I need to redefine to get a red pagenumber in LOF as well (and \textcolor is here a proxy, so I need to be able to replace my my TIKZ-replacement)?

See this MWE:

Test.tex

\documentclass[10pt,fleqn,final]{extbook}
\usepackage{etoc}
\usepackage{xcolor}
\usepackage{titlesec}
\etocsetstyle{chapter}
{}
{\llap{\etocnumber\hspace{0.75cm}}\etocname\hspace{10pt}\titlerule*[1pc]{.}\hspace{10pt}%
\makebox[-0cm][l]{\makebox[0pt]{\etocpage}}\par}
{}
\makeatother
\let\oldref=\ref
\AtBeginDocument{\renewcommand\ref[1]{\textcolor{red}{\oldref{#1}}}}
\urlstyle{same}
\begin{document}
\tableofcontents
\listoftables
\chapter{Test}
\begin{table}[h]
\begin{tabular}{ c }
\hline
cell1 \\
\hline
\end{tabular}
\caption{This link is not customized in LOT}
\end{table}
\end{document}

• No answer has been posted, and I really want to know how I can customize the links in List of Tables/Figures. – robert Sep 18 '16 at 11:58
• Aren't there easier ways to underline links than this? Is there any particular reason you want to do it this way? – cfr Sep 18 '16 at 15:19
• The reason it works with etoc for the contents is probably that etoc explicitly checks for hyperref and adapts accordingly. If you just use \tableofcontents, you won't get the customisation there either. If you compare what you get in the .toc and .lot/.lof files, you can see what ends up doing the right thing in the ToC case and use this as a starting point. I can't do this because I don't have the means to recreate the .toc since the relevant code is not included in your question. – cfr Sep 18 '16 at 15:51
• Thanks cfr. In above MWE, I get the following .lotfile. My question is, in this MWE example which code is responsble for producing the content of those .lot files, so I can customize it. \contentsline {table}{\numberline {1}{\ignorespaces This link is not customized in LOT}}{1}{table.0.1} – robert Sep 18 '16 at 19:24
• @robert: Which parts of the element do you want to underline? Just the title, just the number, or both? – Werner Sep 18 '16 at 21:26

Imho there is no good way to change the hyperref commands. hyperref doesn't use a command with argument in this case. Probably the easiest is to redefine \@dottedtocline, e.g.

\def\@dottedtocline#1#2#3#4#5{%
\ifnum #1>\c@tocdepth \else
\vskip \z@ \@plus.2\p@
{\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
\parindent #2\relax\@afterindenttrue
\interlinepenalty\@M
\leavevmode
\@tempdima #3\relax
\tikzul[dotted]{#4}\nobreak
\leaders\hbox{$\m@th \mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$}\hfill
\nobreak
\hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #5}%
\par}%
\fi}


## Edit

as requested a full example with etoc, which changes the lot. etoc doesn't hook into the listoftables so one has to change again \@dottedtocline: The green and red color are placeholders for the tikz code:

\documentclass[10pt,fleqn,final]{extbook}
\usepackage{etoc}
\usepackage{xcolor}
\usepackage{titlesec}
\etocsetstyle{chapter}
{}
{\llap{\etocnumber\hspace{0.75cm}}\etocname\hspace{10pt}\titlerule*[1pc]{.}\hspace{10pt}%
\makebox[-0cm][l]{\makebox[0pt]{\etocpage}}\par}
{}
\makeatletter
\def\@dottedtocline#1#2#3#4#5{%
\ifnum #1>\c@tocdepth \else
\vskip \z@ \@plus.2\p@
{\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
\parindent #2\relax\@afterindenttrue
\interlinepenalty\@M
\leavevmode
\@tempdima #3\relax
\textcolor{green}{#4}\nobreak
\leaders\hbox{$\m@th \mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$}\hfill
\nobreak
\hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor \textcolor{red}{#5}}%
\par}%
\fi}

\makeatother
\let\oldref=\ref
\AtBeginDocument{\renewcommand\ref[1]{\textcolor{red}{\oldref{#1}}}}
\urlstyle{same}
\begin{document}
\tableofcontents
\listoftables
\chapter{Test}
\begin{table}[h]
\begin{tabular}{ c }
\hline
cell1 \\
\hline
\end{tabular}
\caption{This link is not customized in LOT}
\end{table}
\end{document}

• THANK YOU, this is getting closer. However (1) it also underline the spaces between the tablenumber and the caption. That part is not clickable. (2) I am not sure it also underlines the page number probably not because (3) I cannot test because it is not working (with pdflatex) if I paste this in. I have updated my openingspost. How can I get something like this in style of etoc+linktoc=all – robert Sep 19 '16 at 6:15
• The number and the space are clickable. hyperref puts the link start before the whole argument (that means before the \numberline command). If you want to underline also the page number you will have to add your command around the #5. Btw: Imho this looks all quite bad, to many dots everywhere. Beside this you should decide if you want to to use etoc or titletoc. Mixing both will give you only headache when trying to decide whose code is currently winning. – Ulrike Fischer Sep 19 '16 at 7:39
• Thanks. If I use linktoc=page (less verbose link) and add customization to #5 then this answer is the solution. HOWEVER, can you update your answer with the full MWE. If I add your snippet to my (original) MWE, it does not work (based on pdflatex). Does your customization work also together with etoc? – robert Sep 19 '16 at 16:46
• Could please decide first if you want to use etoc or titletoc or none of both and where you want the customization? I really don't want to write lots of variants. Btw: You can replace all your tikzurl code with e.g. \textcolor{red}. This should be enough in a minimal example. – Ulrike Fischer Sep 19 '16 at 16:57
• I updated my MWE in the first post. I used titletoc only for \titlerow, so I replaced this by titlesec. Can you update your answer, and post a full MWE which shows this LOT in red? – robert Sep 19 '16 at 17:42