Make a clickable table of contents in LaTeX
In LaTeX, you can easily create a table of contents with the \tableofcontents
command and it will generate the table of contents with all the sections and subsections. But in this case, the generated table of contents is not clickable.
To make this clickable you have to use the hyperref
package and use [hidelinks]
option to remove the annoying red border.
\documentclass{article} \usepackage[hidelinks]{hyperref} \title{Clickable Table of contents} \author{Parvez A.P} \date{\today} \begin{document} \maketitle \tableofcontents \section{This is a section} \subsection{This is a subsection} \subsection{This is a subsection too} \section{This is a section} \subsection{This is a subsection} \subsection{This is a subsection too} \section{This is a section} \subsection{This is a subsection} \subsection{This is a subsection too} \end{document}
Output:
You can customize the color of the table of contents with \hypersetup{colorlinks=true, linkcolor=<color-name>,}
and make it better.
\documentclass{article} \usepackage{hyperref} \hypersetup{ colorlinks=true, linkcolor=blue, } \title{Clickable Table of contents} \author{Parvez A.P} \date{\today} \begin{document} \maketitle \tableofcontents \section{This is a section} \subsection{This is a subsection} \subsection{This is a subsection too} \section{This is a section} \subsection{This is a subsection} \subsection{This is a subsection too} \section{This is a section} \subsection{This is a subsection} \subsection{This is a subsection too} \end{document}
Output:
You can also add a color box with the table of contents to make it more beautiful. Personally, I recommend using the \begin{tcolorbox} ... \end{tcolorbox}
provided by the tcolorbox
package. This will give you a beautiful color box around the table of contents. Take a look.
\documentclass{article} \usepackage{tcolorbox} \usepackage[hidelinks]{hyperref} \title{Clickable Table of contents} \author{Parvez A.P} \date{\today} \begin{document} \maketitle \begin{tcolorbox} \tableofcontents \end{tcolorbox} \section{This is a section} \subsection{This is a subsection} \subsection{This is a subsection too} \section{This is a section} \subsection{This is a subsection} \subsection{This is a subsection too} \section{This is a section} \subsection{This is a subsection} \subsection{This is a subsection too} \end{document}
Output:
Customize your color box with this,
\newtcolorbox{<name>}{colback=<color-name>,colframe=<color-name>}
In this case, you have to replace the tcolorbox
environment with <name>
. Let’s make my color box with my custom color.
\documentclass{article} \usepackage{tcolorbox} \newtcolorbox{mybox}{colback=red!5!white,colframe=red!75!black} % Color box \usepackage{hyperref} \hypersetup{ colorlinks=true, linkcolor=green!45!black} \title{Clickable Table of contents} \author{Parvez A.P} \date{\today} \begin{document} \maketitle \begin{mybox} \tableofcontents \end{mybox} \section{This is a section} \subsection{This is a subsection} \subsection{This is a subsection too} \section{This is a section} \subsection{This is a subsection} \subsection{This is a subsection too} \section{This is a section} \subsection{This is a subsection} \subsection{This is a subsection too} \end{document}
Output:
Leave a Reply