xdanaux / moderncv

A modern curriculum vitae class for LaTeX
1.8k stars 556 forks source link

table of contents #91

Closed alanlivio closed 2 years ago

alanlivio commented 4 years ago

How add a table of contents at the beginning of a moderncv document? The \tableofcontents command is not recognized by the class.

alanlivio commented 4 years ago

I resolve the issue using the following code from internet[1].

% For issuing \makecvtitle more than once
\patchcmd{\makecvtitle}{\newlength{\makecvtitledetailswidth}}{\let\makecvtitledetailswidth\relax\newlength{\makecvtitledetailswidth}}{}{}
\patchcmd{\makecvtitle}{\newlength{\makecvtitlepicturewidth}}{\let\makecvtitlepicturewidth\relax\newlength{\makecvtitlepicturewidth}}{}{}

\newcommand{\part}[1]{%
% \phantomsection%
\addcontentsline{toc}{part}{#1}%
}

\makeatletter
\newcommand\@pnumwidth{1.55em}
\newcommand\@tocrmarg{2.55em}
\newcommand\@dotsep{8}
\newcommand\contentsname{Contents}
\setlength\columnsep{20pt}
\setcounter{tocdepth}{0}
\newcommand\tableofcontents{%
  \addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
  \newbox{\makecvtitlenamebox}
  \savebox{\makecvtitlenamebox}{%
    \namestyle{\@firstname\ \@lastname}%
  }
  \section*{\contentsname}
  \@starttoc{toc}%
}
\usepackage{titletoc}
\titlecontents*{section}[0pt]
  {}{}{\textbullet}
  {\ \thecontentspage}[\\][]
\titlecontents{part}[0pt]
  {}{}{
    % \hspace*{5em}\normalsize
  }
  {\leaders\hbox{\normalfont$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$}\hfill\normalsize\thecontentspage
  % \hspace*{2em}
  }[]
\renewcommand\l@subsection[2]{}
\makeatother

[1] https://tex.stackexchange.com/questions/320193/class-moderncv-renewcommand-makecvtitle-results-in-undefined-control-sequence-e

alanlivio commented 2 years ago

closed in favor https://github.com/moderncv/moderncv/issues/93