0

I'm doing my thesis and I need a better display of the chapters that are shown on LoT and LoF, as well as I want to include the \appendix as a Chapter to LoT and LoF (notice that \appendixname is "Anexo" in the LoT picture below).

I read an answer here which recommends to use: \addcontentsline{lot}{chapter}{Anexo}, and it adds perfectly the "Anexo" chapter to LoT & LoF. The thing is that, as you can see on the image below, the "Anexo" is with hyperlink and with the page number also (in other color). The point is that it looks bad comparing to the other chapters style. I'd like all to look the same, with a bigger font size if possible :-). In order to add the chapters as it is shown for all chapters (not counting "Anexo", i.e II. Estado del Arte and III. Métodos y materiales), I used an answer suggested here.

My code is the following:

\documentclass[11pt,a4paper,twoside,openright]{report}
\usepackage[spanish,es-lcroman]{babel}
\addto\shorthandsspanish{\spanishdeactivate{~<>}}

\usepackage[utf8x]{inputenc}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{booktabs}
\usepackage{caption}
   \captionsetup{labelfont=bf}
\usepackage{amsmath}

\usepackage{etoolbox}

    \makeatletter 
    % initial definitions of the chapter info (name and number)
    \def\thischaptertitle{}\def\thischapternumber{}
    \newtoggle{noFigs}

    \apptocmd{\@chapter}%
    {\gdef\thischaptertitle{#1}\gdef\thischapternumber{\thechapter}%
        \global\toggletrue{noFigs}}{}{}

    % the figure environment does the job: the first time it is used after a \chapter command, 
    % it writes the information of the chapter to the LoF
    \AtBeginDocument{%
        \AtBeginEnvironment{figure}{%
            \iftoggle{noFigs}{
                \addtocontents{lof}{\protect\contentsline {chapter}%
                    {\protect\numberline {\thischapternumber} {\thischaptertitle}}{}{} }
                \global\togglefalse{noFigs}
            }{}
        }%
    }

    \makeatother


    \makeatletter 
    \def\thischaptertitle{}\def\thischapternumber{}
    \newtoggle{noTabs}

    \apptocmd{\@chapter}%
    {\gdef\thischaptertitle{#1}\gdef\thischapternumber{\thechapter}%
        \global\toggletrue{noTabs}}{}{}

    % the figure environment does the job: the first time it is used after a \chapter command, 
    % it writes the information of the chapter to the LoF
    \AtBeginDocument{%
        \AtBeginEnvironment{table}{%
            \iftoggle{noTabs}{
                \addtocontents{lot}{\protect\contentsline {chapter}%
                    {\protect\numberline {\thischapternumber} {\thischaptertitle}}{}{} }
                \global\togglefalse{noTabs}
            }{}
        }%
    }
    \makeatother

\addto\captionsspanish{
\def\tablename{Tabla}
\def\listtablename{\'Indice de tablas}
}


\usepackage[margin=25mm,inner=30mm]{geometry}


\usepackage[colorlinks=true,
            linkcolor=blue,
            urlcolor=blue,
            citecolor=blue]{hyperref}


\usepackage{sectsty}

\usepackage[nottoc,notlof,notlot]{tocbibind} 

\makeatletter
\def\tableofcontents{%
 \newpage
 \centerline{\Large\scshape Índice General} 
 \vspace*{0.3in}
 \@mkboth{Contenidos}{}
 \@starttoc{toc}
}
\makeatother

\makeatletter
\def\listoftables{%
 \newpage
 \centerline{\Large\scshape Índice de Tablas} 
 \vspace*{0.3in}
 \@mkboth{Contenidos}{}
 \@starttoc{lot}
}
\makeatother

\makeatletter
\def\listoffigures{%
 \newpage
 \centerline{\Large\scshape Índice de Figuras} 
 \vspace*{0.3in}
 \@mkboth{Contenidos}{}
 \@starttoc{lof}
}
\makeatother


\usepackage{appendix}
\usepackage{titlesec}
\usepackage[dotinlabels]{titletoc}

\usepackage{longtable}
\usepackage{tabularx}
\usepackage{bigstrut}
\usepackage{bigdelim}
\usepackage{ltxtable}
\usepackage{chngcntr}

\begin{document}
\selectlanguage{spanish}

%------------------------- TOC.

\cleardoublepage
\phantomsection
\tableofcontents
\addcontentsline{toc}{chapter}{Índice General}

%------------------------- LOF.

\cleardoublepage
\phantomsection
\listoffigures
\addcontentsline{toc}{chapter}{\listfigurename}

%------------------------- LOT.

\cleardoublepage
\phantomsection
\listoftables
\addcontentsline{toc}{chapter}{\listtablename}

\clearpage
\chapter{Capítulo 1}
% There are no tables here...

\clearpage
\chapter{Estado del Arte}

\begin{table}[h!]
\centering
\caption{Grupos de códigos de área.}\label{tab:1}
\begin{tabular}{cc}
   \toprule
   hola & chao\\
   \midrule
   bla & blabla\\
   alb & albalb\\
   \bottomrule
   \end{tabular}
\end{table}
%and many other tables...
\clearpage
\chapter{Métodos y materiales}

\begin{table}[h!]
\centering
\begin{tabular}{lc}
    \toprule
    \multicolumn{2}{c}{\textbf{CARACTERÍSTICAS TÉCNICAS DEL ESPECTRÓMETRO STS-NIR }} \\
    \midrule
    Fabricante & OceanOptics \\
    bla & blabla\\
    \bottomrule
   \end{tabular}%
   \caption{Características del espectrómetro y de la fibra óptica.}\label{tab:car_espectrometro}%
\end{table}

% Here's much more... (bla bla... + bibliography...)
% And at the end (the appendix):

\clearpage
\renewcommand{\appendixname}{Anexo}
\renewcommand{\appendixtocname}{Anexo}
\renewcommand{\appendixpagename}{Anexo}
\renewcommand{\thesection}{\Alph{section}}

\appendix       
\phantomsection
\addcontentsline{lot}{chapter}{Anexo} %This is the first approach.
\clearpage
\addappheadtotoc
\appendixpage

\counterwithin{table}{section}
\counterwithin{figure}{section}
\counterwithin{equation}{section}


\refstepcounter{section}% 
\section*{\thesection. \quad Características generales de las agujas y conos de pino.}

\begin{table}[h!]
    \centering
    \begin{tabular}{lcc}
        \toprule
        & bla & blabla \\
        \midrule
        Moisture (wt.\%) & 12     & 8,9 \\
        bla bla          & bla    & bla \\
        \bottomrule
    \end{tabular}%
    \caption{Características generales de agujas y conos de pino.}
\end{table}%

\end{document}

It is very possible that I'm missing something (I'm trying to put just what I think It's necessary, because I've got hundreds of code lines in my preamble), therefore I'll be very alert for any question and/or answer. So, to conclude, the things that I'm asking to solve are:

  1. That \appendix chapter ("Anexo" in LoT) has the same style as the other chapters (i.e Estado del Arte and Métodos y materiales).

  2. To modify the chapters style in both LoT and LoF (to change the font size, color...with that it's perfect!).

I'd really appreciate some help!

on the image below

2
  • Welcome to TeX.SX! Please provide a Minimal Working Example (MWE). The code you provided is far too long to be minimal and has missing packages, so it's not working. A MWE should have only the necessary packages, be compilible and have enough code to show the issue. Providing a MWE will definetely increase your chances of getting help as it makes the helpers lives much easier! :D Nov 8, 2016 at 11:59
  • @GuilhermeZ.Santos, I already modified the code to run perfectly. Thank you.
    – Jorge V
    Nov 9, 2016 at 15:43

1 Answer 1

2

You're missing the hyperref anchor line on your definition of \apptocmd{\@chapter}, done by:

\global\let\thischapterHref\@currentHref

Replace your definition by this:

\apptocmd{\@chapter}{%
    \gdef\thischaptertitle{#1}%
    \gdef\thischapternumber{\thechapter}%
    \global\let\thischapterHref\@currentHref % hyperref
    \global\toggletrue{noFigs}%
    \global\toggletrue{noTabss}%
}{}{}

And you also have to call the anchor when making the list:

\AtBeginDocument{%
    \AtBeginEnvironment{table}{%
        \iftoggle{noTabs}{
            \addtocontents{lot}{\protect\contentsline{chapter}%
                {\protect\numberline {\thischapternumber} {\thischaptertitle}}%
                {}%
                {\thischapterHref}% << for hyperlink
                }
            \global\togglefalse{noTabs}
        }{}
    }%
}

Furthermore, to supress the page number on ToC entries added with \addtocontents instead of the \addcontentsline{lot}{chapter}{Anexo} you should use the below code, where the last argument chapter\thepage refers to hyperref's link anchor:

\addtocontents{lot}{\protect\contentsline{chapter}{Anexo}{}{chapter\thepage}}

The complete (M)WE:

\documentclass[11pt,a4paper,twoside,openright]{report}
\usepackage[spanish,es-lcroman]{babel}
\addto\shorthandsspanish{\spanishdeactivate{~<>}}

\usepackage[utf8x]{inputenc}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage{booktabs}
\usepackage{caption}
\captionsetup{labelfont=bf}
\usepackage{amsmath}

\usepackage{etoolbox}

\makeatletter 
% initial definitions of the chapter info (name and number)
\def\thischaptertitle{}\def\thischapternumber{}
\newtoggle{noFigs}
\newtoggle{noTabs}

\apptocmd{\@chapter}{%
    \gdef\thischaptertitle{#1}%
    \gdef\thischapternumber{\thechapter}%
    \global\let\thischapterHref\@currentHref % hyperref
    \global\toggletrue{noFigs}%
    \global\toggletrue{noTabs}%
}{}{}


% the figure environment does the job: the first time it is used after a \chapter command, 
% it writes the information of the chapter to the LoF
\AtBeginDocument{%
    \AtBeginEnvironment{figure}{%
        \iftoggle{noFigs}{
            \addtocontents{lof}{%
                \protect\contentsline{chapter}%
                {\protect\numberline {\thischapternumber} {\thischaptertitle}}{}{\thischapterHref} }
            \global\togglefalse{noFigs}
        }{}
    }%
}

% the figure environment does the job: the first time it is used after a \chapter command, 
% it writes the information of the chapter to the LoF
\AtBeginDocument{%
    \AtBeginEnvironment{table}{%
        \iftoggle{noTabs}{
            \addtocontents{lot}{\protect\contentsline {chapter}%
                {\protect\numberline {\thischapternumber} {\thischaptertitle}}{}{\thischapterHref} }
            \global\togglefalse{noTabs}
        }{}
    }%
}
\makeatother

\addto\captionsspanish{
    \def\tablename{Tabla}
    \def\listtablename{\'Indice de tablas}
}


\usepackage[margin=25mm,inner=30mm]{geometry}


\usepackage[colorlinks=true,
            linkcolor=blue,
            urlcolor=blue,
            citecolor=blue]{hyperref}

\usepackage{sectsty}
\usepackage[nottoc,notlof,notlot]{tocbibind} 

\makeatletter
\def\tableofcontents{%
    \newpage
    \centerline{\Large\scshape Índice General} 
    \vspace*{0.3in}
    \@mkboth{Contenidos}{}
    \@starttoc{toc}
}

\def\listoftables{%
    \newpage
    \centerline{\Large\scshape Índice de Tablas} 
    \vspace*{0.3in}
    \@mkboth{Contenidos}{}
    \@starttoc{lot}
}

\def\listoffigures{%
    \newpage
    \centerline{\Large\scshape Índice de Figuras} 
    \vspace*{0.3in}
    \@mkboth{Contenidos}{}
    \@starttoc{lof}
}
\makeatother


\usepackage{appendix}
\usepackage{titlesec}
\usepackage[dotinlabels]{titletoc}

\usepackage{longtable}
\usepackage{tabularx}
\usepackage{bigstrut}
\usepackage{bigdelim}
\usepackage{ltxtable}
\usepackage{chngcntr}

\begin{document}
    \selectlanguage{spanish}

    %------------------------- TOC.

    \cleardoublepage
    \phantomsection
    \tableofcontents
    \addcontentsline{toc}{chapter}{Índice General}

    %------------------------- LOF.

    \cleardoublepage
    \phantomsection
    \listoffigures
    \addcontentsline{toc}{chapter}{\listfigurename}

    %------------------------- LOT.

    \cleardoublepage
    \phantomsection
    \listoftables
    \addcontentsline{toc}{chapter}{\listtablename}

    \clearpage
    \chapter{Capítulo 1}
    % There are no tables here...

    \clearpage
    \chapter{Estado del Arte}

    \begin{table}[h!]
        \centering
        \caption{Grupos de códigos de área.}\label{tab:1}
        \begin{tabular}{cc}
            \toprule
            hola & chao\\
            \midrule
            bla & blabla\\
            alb & albalb\\
            \bottomrule
        \end{tabular}
    \end{table}
    %and many other tables...
    \clearpage
    \chapter{Métodos y materiales}

    \begin{table}[h!]
        \centering
        \begin{tabular}{lc}
            \toprule
            \multicolumn{2}{c}{\textbf{CARACTERÍSTICAS TÉCNICAS DEL ESPECTRÓMETRO STS-NIR }} \\
            \midrule
            Fabricante & OceanOptics \\
            bla & blabla\\
            \bottomrule
        \end{tabular}%
        \caption{Características del espectrómetro y de la fibra óptica.}\label{tab:car_espectrometro}%
    \end{table}

    % Here's much more... (bla bla... + bibliography...)
    % And at the end (the appendix):

    \clearpage
    \renewcommand{\appendixname}{Anexo}
    \renewcommand{\appendixtocname}{Anexo}
    \renewcommand{\appendixpagename}{Anexo}
    \renewcommand{\thesection}{\Alph{section}}

    \appendix       
    \phantomsection
    \addtocontents{lot}{\protect\contentsline{chapter}{Anexo}{}{chapter\thepage}}
    \clearpage
    \addappheadtotoc
    \appendixpage

    \counterwithin{table}{section}
    \counterwithin{figure}{section}
    \counterwithin{equation}{section}


    \refstepcounter{section}% 
    \section*{\thesection. \quad Características generales de las agujas y conos de pino.}

    \begin{table}[h!]
        \centering
        \begin{tabular}{lcc}
            \toprule
            & bla & blabla \\
            \midrule
            Moisture (wt.\%) & 12     & 8,9 \\
            bla bla          & bla    & bla \\
            \bottomrule
        \end{tabular}%
        \caption{Características generales de agujas y conos de pino.}
    \end{table}%

\end{document}

In result you have all your chapters as hyperlinks:

compilation result

8
  • You actually changed the color (because of hyperlink), what it's only missing would be to take the page number of "Anexo" (\appendix) of LoT and LoF so it can be shown just as the other chapters. Do you know how to do it? Thank you for your time!
    – Jorge V
    Nov 10, 2016 at 2:11
  • @JorgeV, you're welcome, don't forget to upvote helpful questions and answers as well as accepting correct answers. See edited answer above, I think everything is clear now! :D Nov 10, 2016 at 6:48
  • Amazing! Works great, thank you very much :D!!!
    – Jorge V
    Nov 11, 2016 at 2:19
  • @Guilherme_Zanotelli I found a little problem in the code. When I add another chapter (call it chapter "x"), the title of it ("x") goes inside of "Anexo" in LoT. I tried a lot in order to find out why, and the result was because there was no table in chapter ("x"). Do you know what should I modify in order to change that? I mean, I don't have tables in all my chapters, and if I do not add one, the problem will remain. Thanks!
    – Jorge V
    Dec 6, 2016 at 18:52
  • I'm sorry @JorgeV, but I don't understant the problem you're stating. You're supposed to be using \section not \chapter. Also, if you undo the changes I proposed and the problem persists, than it's unrelated to this question. Can you please check that? And if the problem is being caused by the proposed solution, add a new MWE showing it, if not, please ask a new question then! :) Dec 6, 2016 at 19:57

You must log in to answer this question.

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