6

First of all, I have been searching on the web and I have found similar cases but nothing useful for my problem, and more over, I'm pretty new in LaTeX.

The Problem

  • If I take off the numbers from \section, then, numbering of subsections are equal in every section (this is in the Content itself).

                                  Centered Section Title
    1  Subsection
       1.1 Subsubsection
       1.2 Subsubsection
                                   Other Section Title
    1  Subsection
       1.1 Subsubsection
       1.2 Subsubsection
    
  • It is the same in the TOC and additionally, sections are right shifted. Represented with []:

                            Index
    
    Introduction (manually added)......................xx
    [ ]Section Title...................................xx
    [ ]1  Subsection...................................xx
    [ ]   1.1 Subsubsection............................xx
    [ ]   1.2 Subsubsection............................xx
    [ ]Other Section Title.............................xx
    [ ]1  Subsection...................................xx
    [ ]   1.1 Subsubsection............................xx
    [ ]   1.2 Subsubsection............................xx
    Bibliography (manually added)......................xx
    

What I want

  • I need to get sections without numbers neither in the title nor in the TOC, but \subsection and \subsubsection must have that numeration.

                                  Centered Section Title
    1.1  Subsection
       1.1.1 Subsubsection
       1.1.2 Subsubsection
                                   Other Section Title
    2.1  Subsection
       2.1.1 Subsubsection
       2.1.2 Subsubsection
    
  • Get aligned sections in TOC.

I'm so sorry if I have miswritten something, English is not my native language

My current code:

\documentclass[12pt]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[spanish,activeacute]{babel}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsmath,amsthm}
\usepackage[left=1.58in,right=0.98in,top=0.5in,bottom=0.5in]{geometry}

%to do not put numbers in sections
\usepackage{titlesec}
\titleformat{\section}{\centering}{\thesection}{0em}{\Large\bfseries}
    \renewcommand{\thesection}{}% Remove section references...
\renewcommand{\thesubsection}{\arabic{subsection}}%... from subsections

% to fill TOC with dots
\usepackage{tocloft}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill\hfill}%center TOC title

%to replace TOC title
\addto\captionsspanish{
  \renewcommand{\contentsname}{Indice General}
}

\setcounter{secnumdepth}{3}

\begin{document}
\tableofcontents

\section*{Introduction}
\addcontentsline{toc}{section}{Introduction}
\paragraph{About:} Some text over here...

\section[First Things]{Capítulo 1: First Things}
\subsection{Algo}
\subsubsection{Algo más}

\section[Title for TOC]{Capítulo 2: Title for section}
\subsection{Algo}
\subsubsection{Algo más}

\section[Again for TOC]{Capítulo 3: Title for Text}

\section[Conclutions]{Conclutions}

\clearpage
\addcontentsline{toc}{section}{Bibliography}
% Bibliography.
\begin{thebibliography}{99}
\bibitem{Someone}
\emph{...}.
\end{thebibliography}
\end{document}
2
  • I found some approach to answer my own question, surely there are better than this one. \titleformat{\section}{\centering}{}{0em}{\Large\bfseries} instead of \titleformat{\section}{\centering}{\thesection}{0em}{\Large\bfseries} to do not write the numbers in the pages header. and delete all \setcounter{secnumdepth}{X} in the document I have deleted the first and modified the document environment. But I still need to do not write the numbers in the TOC.
    – onlycparra
    Commented Nov 29, 2014 at 19:47
  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Commented Nov 29, 2014 at 20:52

2 Answers 2

3

I wouldn't recommend to hardcode something like "Capítulo 1: First Things" in a sectional heading. The following code looks a little bulky because it does a more than you requested, but it induces a more LaTeXnish manuscript file.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[spanish,activeacute]{babel}
\usepackage{tocloft}
  \renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
  \renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries}
  \renewcommand{\cftaftertoctitle}{\hfill\hfill}

\makeatletter
\renewcommand\section{\secdef\@section\@ssection}
\def\@section[#1]#2{%
  \ifnum \c@secnumdepth >\@ne
    \refstepcounter{section}%
    \typeout{\sectionname\space\thesection.}%
    \addcontentsline{toc}{section}%
                    {\protect#1}%
  \else
    \addcontentsline{toc}{section}{#1}%
  \fi
  \sectionmark{#1}%
  \if@twocolumn
    \@topnewpage[\@makesectionhead{#2}]%
  \else
    \@makesectionhead{#2}%
    \@afterheading
  \fi}
\def\@makesectionhead#1{%
  \vspace*{10\p@}%
  {\parindent \z@ \centering \normalfont
    \ifnum \c@secnumdepth >\@ne
      \interlinepenalty\@M
      \Large\bfseries \sectionname\space \thesection: #1\par\nobreak
    \fi
    \vskip 10\p@}}%
\def\@ssection#1{%
  \if@twocolumn
    \@topnewpage[\@makessectionhead{#1}]%
  \else
    \@makessectionhead{#1}%
    \@afterheading
  \fi}%
\def\@makessectionhead#1{%
  \vspace*{10\p@}%
  {\parindent \z@ \centering\normalfont
    \interlinepenalty\@M
    \Large \bfseries  #1\par\nobreak
    \vskip 10\p@}}%
\def\sectionname{Section}
\makeatother

\setcounter{secnumdepth}{3}
\addto\captionsspanish{%
  \renewcommand{\contentsname}{Indice General}
  \renewcommand{\sectionname}{Sección}}% or Capítulo of course...

\begin{document}
\tableofcontents

\section*{Introduction}
\addcontentsline{toc}{section}{Introduction}
\paragraph{About:} Some text over here...

\section{First Things}
\subsection{Algo}
\subsubsection{Algo más}

\section[Title for TOC]{Title for section}
\subsection{Algo}
\subsubsection{Algo más}
\end{document}

output

14
  • Hi Ruben. The OP wants sections (starred and non-) left-aligned in the TOC. Commented Nov 29, 2014 at 20:57
  • @karlkoeller, not so sure about this because in fact the sections are somehow numbered in the running text, i.e. "Capítulo 1: First Things". I was about to add a titletoc solution as an addendum to my answer, in order to have a less bulky option. Now that you have written one were pretty complete here, i'd say.
    – Ruben
    Commented Nov 29, 2014 at 21:01
  • @karlkoeller, ... and note that the alignment of the starred sections and the regular ones are differenetly sketched in the OP (regarding your answer). Don't knoe yet if it is important. But, it is worth a thought.
    – Ruben
    Commented Nov 29, 2014 at 21:03
  • @onlycparra, does the update cover anything you need now?
    – Ruben
    Commented Nov 29, 2014 at 21:45
  • Almost, because "Algo" from Section "First Things" should have number 1.1 and "Algo más" 1.1.1. "Algo" from next section should have 2.1 and "Algo más" 2.1.1... and so on Am I too confusing? :S
    – onlycparra
    Commented Nov 29, 2014 at 22:17
5

You can use the package titletoc instead of tocloft to achieve what you want.

First of all, forget about redefining \thesection, that is remove the lines

\renewcommand{\thesection}{}% Remove section references...
\renewcommand{\thesubsection}{\arabic{subsection}}%... from subsections

Then remove the stuff from tocloft and add these lines:

\usepackage{titletoc}
\titlecontents{section}
              [0em]
              {\addvspace{1pc}\bfseries}
              {}
              {}
              {\mdseries\titlerule*[.75pc]{.}\bfseries\contentspage}

This is the result:

enter image description here

Complete code:

\documentclass[12pt]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[spanish,activeacute]{babel}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsmath,amsthm}
\usepackage[left=1.58in,right=0.98in,top=0.5in,bottom=0.5in]{geometry}

%to do not put numbers in sections
\usepackage{titlesec}
\titleformat{\section}{\centering}{}{0em}{\Large\bfseries}

\usepackage{titletoc}
\titlecontents{section}
              [0em]
              {\addvspace{1pc}\bfseries}
              {}
              {}
              {\mdseries\titlerule*[.75pc]{.}\bfseries\contentspage}

%to replace TOC title
\addto\captionsspanish{
  \renewcommand{\contentsname}{Indice General}
}

\setcounter{secnumdepth}{3}

\begin{document}
\tableofcontents

\section*{Introduction}
\addcontentsline{toc}{section}{Introduction}
\paragraph{About:} Some text over here...

\section[First Things]{Capítulo 1: First Things}
\subsection{Algo}
\subsubsection{Algo más}

\section[Title for TOC]{Capítulo 2: Title for section}
\subsection{Algo}
\subsubsection{Algo más}

\section[Again for TOC]{Capítulo 3: Title for Text}

\section[Conclutions]{Conclutions}

\clearpage
\addcontentsline{toc}{section}{Bibliography}
% Bibliography.
\begin{thebibliography}{99}
\bibitem{Someone}
\emph{...}.
\end{thebibliography}
\end{document} 

EDIT

As per your comment, to have Roman numerals for sections in the TOC (although I don't approve this choice), do the following.

Declare \thesection as \Roman and \thesubsection as \arabic:

\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}

In this case it is better to use tocloft instead of titletoc.

Add to your original settings the following lines:

\cftsetindents{section}{0em}{3em}
\cftsetindents{subsection}{3em}{2.3em}
\cftsetindents{subsubsection}{5.3em}{3em}

and this is the result:

enter image description here

Note that the spacing between Roman numerals and titles is deliberately large so to leave space for large numerals.

Complete code:

\documentclass[12pt]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[spanish,activeacute]{babel}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsmath,amsthm}
\usepackage[left=1.58in,right=0.98in,top=0.5in,bottom=0.5in]{geometry}

%to do not put numbers in sections
\usepackage{titlesec}
\titleformat{\section}{\centering}{}{0em}{\Large\bfseries}

\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}

% to fill TOC with dots
\usepackage{tocloft}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill\hfill}%center TOC title
\cftsetindents{section}{0em}{3em}
\cftsetindents{subsection}{3em}{2.3em}
\cftsetindents{subsubsection}{5.3em}{3em}

%to replace TOC title
\addto\captionsspanish{
  \renewcommand{\contentsname}{Indice General}
}

\setcounter{secnumdepth}{3}

\begin{document}
\tableofcontents

\section*{Introduction}
\addcontentsline{toc}{section}{Introduction}
\paragraph{About:} Some text over here...

\section[First Things]{Capítulo 1: First Things}
\subsection{Algo}
\subsubsection{Algo más}

\section[Title for TOC]{Capítulo 2: Title for section}
\subsection{Algo}
\subsubsection{Algo más}

\section[Again for TOC]{Capítulo 3: Title for Text}

\section[Conclutions]{Conclutions}

\clearpage
\addcontentsline{toc}{section}{Bibliography}
% Bibliography.
\begin{thebibliography}{99}
\bibitem{Someone}
\emph{...}.
\end{thebibliography}
\end{document} 
2
  • just one more thing.... What if I would like to add Roman numbers in front of Sections in TOC?
    – onlycparra
    Commented Nov 29, 2014 at 22:29
  • @onlycparra See the edit. Commented Nov 30, 2014 at 6:28

You must log in to answer this question.

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