6

Could anybody help me to remove the subsection of page number? Just want

enter image description here

to be like this

enter image description here

Thank you very much.

Here is my code

\documentclass[a4paper,12pt]{article} 
\date{} % Leave date blank 
\pagestyle{myheadings}   
\usepackage[top=1in,bottom=1in,left=1.05in,right=1.05in]{geometry} 

\usepackage[titles,subfigure]{tocloft} 
\usepackage{titletoc}  
\setcounter{tocdepth}{2}   
\titlecontents{section}[0ex]  
              {\addvspace{-0.4ex}\filright}  
              {\contentspush{\thecontentslabel\ \  }} 
              {}{\titlerule*[1em]{.}\contentspage}
\titlecontents{subsection}[14pt]   
              {\addvspace{-0.8ex}\filright \small}   
              {\contentspush{\thecontentslabel\ \ }} 
              {\empty}{\titlerule*[-0ex]{.}\contentspage}   

\usepackage{titlesec} 
\titlespacing{\section}{0ex}{*1.1}{*0}   
\titlespacing{\subsection}{0ex}{*0.8}{*0}   
\titleformat*{\section}{\large \bfseries}  
\titleformat*{\subsection}{\normalsize \bfseries}   

\usepackage{graphicx}
\usepackage{subfigure}  


\begin{document} 
\tableofcontents

\section{Three levels}
Computer vision

\section{Dating back}
\subsection{First}
\subsection{Second}

\end{document}
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – karlkoeller Feb 5 '15 at 9:39
  • The spacing is quite horrible. Why do you squeeze all the lines in the toc so together? – Ulrike Fischer Feb 5 '15 at 9:42
7

Simply change

\titlecontents{subsection}[14pt]   
              {\addvspace{-0.8ex}\filright \small}   
              {\contentspush{\thecontentslabel\ \ }} 
              {\empty}{\titlerule*[-0ex]{.}\contentspage}   

to

\titlecontents{subsection}[14pt]
              {\addvspace{-0.8ex}\filright \small}
              {\contentspush{\thecontentslabel\ \ }}
              {}{}

MWE

\documentclass[a4paper,12pt]{article}
\date{} % Leave date blank
\pagestyle{myheadings}
\usepackage[top=1in,bottom=1in,left=1.05in,right=1.05in]{geometry}

\usepackage[titles,subfigure]{tocloft}
\usepackage{titletoc}
\setcounter{tocdepth}{2}
\titlecontents{section}[0ex]
              {\addvspace{-0.4ex}\filright}
              {\contentspush{\thecontentslabel\ \  }}
              {}{\titlerule*[1em]{.}\contentspage}
\titlecontents{subsection}[14pt]
              {\addvspace{-0.8ex}\filright \small}
              {\contentspush{\thecontentslabel\ \ }}
              {}{}

\usepackage{titlesec}
\titlespacing{\section}{0ex}{*1.1}{*0}
\titlespacing{\subsection}{0ex}{*0.8}{*0}
\titleformat*{\section}{\large \bfseries}
\titleformat*{\subsection}{\normalsize \bfseries}

\usepackage{graphicx}
\usepackage{subfigure}


\begin{document}
\tableofcontents

\section{Three levels}
Computer vision

\section{Dating back}
\subsection{First}
\subsection{Second}

\end{document} 

Output

enter image description here

Note, however, that a better result can be obtained using tocloft instead of titlesec using these settings:

\setlength{\cftbeforesecskip}{3pt plus.2pt}
\renewcommand{\cftsecfont}{\normalfont}
\renewcommand{\cftsecpagefont}{\normalfont}
\renewcommand{\cftsecleader}{\normalfont\cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsecdotsep}{\cftdotsep}
\cftpagenumbersoff{subsection}

MWE

\documentclass[a4paper,12pt]{article}
\date{} % Leave date blank
\pagestyle{myheadings}
\usepackage[top=1in,bottom=1in,left=1.05in,right=1.05in]{geometry}

\usepackage[titles,subfigure]{tocloft}
\setcounter{tocdepth}{2}
\setlength{\cftbeforesecskip}{3pt plus.2pt}
\renewcommand{\cftsecfont}{\normalfont}
\renewcommand{\cftsecpagefont}{\normalfont}
\renewcommand{\cftsecleader}{\normalfont\cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsecdotsep}{\cftdotsep}
\cftpagenumbersoff{subsection}

\usepackage{titlesec}
\titlespacing{\section}{0ex}{*1.1}{*0}
\titlespacing{\subsection}{0ex}{*0.8}{*0}
\titleformat*{\section}{\large \bfseries}
\titleformat*{\subsection}{\normalsize \bfseries}

\usepackage{graphicx}
\usepackage{subfigure}


\begin{document}
\tableofcontents

\section{Three levels}
Computer vision

\section{Dating back}
\subsection{First}
\subsection{Second}

\end{document} 

Output:

enter image description here

  • It's great and working well! Thank you very much – Hyden Feb 5 '15 at 10:58
  • @Hyden You're welcome. Remember that you can accept the answer to mark the question as solved, if you want. See How do you accept an answer? – karlkoeller Feb 5 '15 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.