将附录作为 LOF 和 LOT 中的一章,并将 lof 和 lot 中的章节格式包括在内

将附录作为 LOF 和 LOT 中的一章,并将 lof 和 lot 中的章节格式包括在内

我正在做我的论文,我需要更好地展示 LoT 和 LoF 上显示的章节,同时我想将其\appendix作为 LoT 和 LoF 的一个章节(请注意\appendixname下面 LoT 图片中的“Anexo”)。

我读过一个答案这里建议使用:\addcontentsline{lot}{chapter}{Anexo},它完美地将“Anexo”章节添加到 LoT 和 LoF。问题是,正如您在下图中看到的,“Anexo”带有超链接和页码(其他颜色)。关键是它与其他章节的风格相比看起来很糟糕。我希望所有章节看起来都一样,如果可能的话,字体更大:-)。为了添加所有章节(不包括“Anexo”,即 II. Estado del Arte 和 III. Métodos y Materiales)中显示的章节,我使用了建议的答案这里

我的代码如下:

\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}

我很可能遗漏了某些内容(我试图只写出我认为必要的东西,因为我的序言中有数百行代码),因此我会对任何问题和/或答案保持高度警惕。因此,总而言之,我要解决的问题如下:

  1. \appendix章节(LoT 中的“Anexo”)与其他章节(即 Estado del Arte 和 Métodos ymateriales)具有相同的风格。

  2. 修改 LoT 和 LoF 中的章节样式(更改字体大小、颜色……这样就完美了!)。

我将非常感激您的帮助!

如下图所示

答案1

您缺少hyperref定义的锚行\apptocmd{\@chapter},由以下人员完成:

\global\let\thischapterHref\@currentHref

用以下定义替换您的定义:

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

而且列单的时候还要呼唤主播:

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

此外,抑制目录条目上的页码添加\addtocontents您应该使用下面的代码,而不是\addcontentsline{lot}{chapter}{Anexo},其中最后一个参数chapter\thepage指的是hyperref的链接锚点:

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

完整的(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}

结果,您以超链接的形式获得了所有章节:

编译结果

相关内容