The TOC of the book I translate, includes mandatory sections (required for study), for example, 1.1, 1.2, 1.3, optional sections denoted by a * before section number, for example, *1.4 and sections with no numbers (questions, problems, etc) .. the TOC aligns the section numbers as in the attached figure .. the five main cases are as follows : (for chapter 16, for example)
*16- 8 Section A the 1-digit section number is aligned with the righmost
16- 9 Section B digit of a section number of 2 digits
16-10 Section C no * in the beginning - section number with 2 digits
*16-11 Section D a * in the beginning - section number with 2 digits
Questions (unnumbered section)
Problems (unnumbered section)
Is it possible to implement such an alignment? i use memoir class
I provide a minimal working example that shows the current situation, and i would like to modify the code to give the result described above .. thanks a lot for your support (if it is not possible to get EXACTLY this result, i hope we can at least right justify the section numbers and the unnumbered sections under the numbered ones)
\documentclass[a4paper,twoside,10pt]{memoir}
%\usepackage[american,greek]{babel}
%\usepackage[iso-8859-7]{inputenc}
\usepackage{alphabeta}
\def\eng#1{\textlatin{#1}}
%\newcommand{\sg}{\selectlanguage{greek}}
%\newcommand{\sa}{\selectlanguage{american}}
%\usepackage{textgreek}
%\usepackage{lua-visual-debug}
%\usepackage{pst-solides3d} % 3D drawing
%\usepackage{pgfplots} % 3D drawing
\usepackage{textcase}
\usepackage{silence}
\usepackage{kerkis}
\usepackage{color}
\usepackage[svgnames,x11names,named]{xcolor}
\WarningFilter*{mdframed}{You got a bad break}
\WarningFilter{latex}{Text page}
\usepackage[usetwoside]{mdframed}
\usepackage[LGR,T1]{fontenc}
\usepackage{anyfontsize}
\usepackage{lipsum}
\def\wlog#1{}
\DeclareRobustCommand{\GenericInfo}[2]{}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{systeme}
\usepackage{wrapfig}
\usepackage{afterpage}
\usepackage{tocloft}
\usepackage[figuresright]{rotating}
\usepackage{parskip}
\usepackage{caption}
\usepackage{enumitem}
\usepackage{titletoc}
\usepackage{calc}
%\usepackage{subcaption}
\usepackage{pstricks}
\usepackage{bbm}
%\usepackage{newlfont}
\usepackage{textcomp}
\usepackage{upgreek}
\usepackage{ifthen}
\usepackage{extramarks}
\usepackage{bm}
%\usepackage{pdfcolmk}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{colortbl}
\usepackage[symbol]{footmisc}
\setlength{\cftsectionnumwidth}{3.5em}% Width of \section numbers in ToC
\renewcommand{\cftsectionpresnum}{\hfill}% Inserted before \section numbers in ToC
\renewcommand{\cftsectionaftersnum}{\quad}% Inserts after \section numbers in ToC
\xdef\Sep{;}
\newcommand{\optionalsection}[2][]{%
\renewcommand\thesection{*\arabic{chapter}.\arabic{section}}%
\ifx#1\empty
\section{#2}
\else
\StrBefore{#1}{\Sep}[\First]
\StrBehind{#1}{\Sep}[\Second]
\ifx\First\empty
\ifx\Second\empty
\section{#2}
\else
\section[#2][\Second]{#2}
\fi
\else
\ifx\Second\empty
\section[\First]{#2}
\else
\section[\First][\Second]{#2}
\fi
\fi
\fi
\renewcommand\thesection{\arabic{chapter}.\arabic{section}}%
}
\begin{document}
\tableofcontents
\chapter [chapToc1][chapHeader1]{chapTitle1}
\section [textForTOC1][textForHeader1]{Section Title 1}
\lipsum[1-2]
\section [textForTOC2][textForHeader2]{Section Title 2}
\lipsum[1-2]
\optionalsection [textForTOC3;textForHeader3]{Section Title 3}
\lipsum[1-2]
\section [textForTOC4][textForHeader4]{Section Title 4}
\lipsum[1-2]
\section [textForTOC5][textForHeader5]{Section Title 5}
\lipsum[1-2]
\section [textForTOC6][textForHeader6]{Section Title 6}
\lipsum[1-2]
\section [textForTOC7][textForHeader7]{Section Title 7}
\lipsum[1-2]
\section [textForTOC8][textForHeader8]{Section Title 8}
\lipsum[1-2]
\section [textForTOC9][textForHeader9]{Section Title 9}
\lipsum[1-2]
\section [textForTOC10][textForHeader10]{Section Title 10}
\lipsum[1-2]
\optionalsection [textForTOC11;textForHeader11]{Section Title 11}
\lipsum[1-2]
\optionalsection [textForTOC12;textForHeader12]{Section Title 12}
\lipsum[1-2]
\addcontentsline{toc}{section}{Unnumbered Section 1}
\section * {Unnumbered Section 1}
\lipsum[1-2]
\addcontentsline{toc}{section}{Unnumbered Section 2}
\section * {Unnumbered Section 2}
\lipsum[1-2]
\end{document}
The \optionalsection command was implemented after my request by coleygr and it can be found here



16-9denotes Chapter 16, section 9? And you're using\chapterand\section... not some other contrived macro for this? What about your preamble? What sectional unit packages do you load? As a matter of fact, how about creating a minimal example showing what you currently use. We want to copy-and-paste-and-compile and see what you're seeing at the moment. – Werner Sep 13 '18 at 20:28