1

I am using Arabic language so the alignment should be from the right to left.

What I have so far for the table of contents is:

enter image description here

and I have three problems:

  1. the roman numbering doesn't apply for the pages before chapter 1 (المبحث ١: علوم الحاسوب)
  2. The right alignment for the section and subsection is wrong and I tried all the solutions on this website and couldn't fix it.
  3. I want to change the chapter numbering to alphabetical one. Instead of chapter 1, I wanted chapter one. In my case for the Arabic version, instead of (المبحث ١) I want (المبحث الأول).

My code is

\documentclass[11pt,a4paper]{report}
\usepackage{arabtex}
\usepackage[utf8]{inputenc}
\usepackage[LFE,LAE]{fontenc}
\usepackage[arabic]{babel}

\usepackage{lipsum}

\usepackage{setspace}

\usepackage{titlesec}


\usepackage{tocloft}


\usepackage{titletoc}%
\titlecontents{chapter}% <section-type>
[0pt]% <left>
{\bfseries}% <above-code>
{\chaptername\ \thecontentslabel:\quad}% <numbered-entry-format>
{}% <numberless-entry-format>
{\hfill\contentspage}% <filler-page-format>




\addto\captionsarabic{%
\renewcommand\chaptername{المبحث}
}

\addto{\captionsarabic}{\renewcommand*{\contentsname}{قائمة المحتويات}}



\title{
\Huge\textsc{اللغة العربية}
}
 \author{سالم البوزيدي} 

\begin{document}
\maketitle
\tableofcontents


\pagenumbering{roman}
\clearpage
\setcounter{page}{5}

\chapter*{الملخص}
\addcontentsline{toc}{chapter}{الملخص}



\chapter*{شكر وثناء}
\addcontentsline{toc}{chapter}{شكر وثناء}


\chapter*{اهداء}
\addcontentsline{toc}{chapter}{اهداء}


\pagenumbering{arabic}


\chapter{علوم الحاسوب}
\section{تاريخ}


\subsection{تاريخ}
\section{تاريخ}
\subsection{تاريخ}
\subsection{تاريخ}


\chapter{علوم الحاسوب}

\chapter{علوم الحاسوب}

\begin{thebibliography}{99}
[1]
من ويكيبيديا، الموسوعة الحرة
\end{thebibliography}
\end{document}

I appreciate any help in this.

EDIT: My code now after the Pieter van Oostrum suggenstion is:

   \documentclass[12pt,a4paper]{report} %Same
   \usepackage{fontspec} % Added
    \defaultfontfeatures{Ligatures=TeX} % Added%Use    "Ligatures=TeX"     instead of "Mapping=tex-text"
   \usepackage{polyglossia}% Added
    \setdefaultlanguage{arabic}% Added
    \setmainfont{Times New Roman}% Added

     \usepackage{lipsum} %Same
      \usepackage{setspace}%Same
      \usepackage{titlesec}%Same
       \usepackage{tocloft}%Same

      \usepackage{geometry} %Same
      \geometry{
      a4paper,
      total={170mm,257mm},
      left=25mm,
      right=25mm,
      top=30mm,
      bottom=30mm,
     }

   \usepackage{biblatex}  %Same
   \addbibresource{sample.bib}  %Same

   \usepackage{graphicx}  %Same
   \usepackage{tikz}  %Same
   \usepackage{eso-pic}  %Same
   \usepackage{atbegshi,picture}  %Same
   \usepackage{array,graphicx,lipsum}  %Same
   \usepackage[export]{adjustbox}  %Same
   \usepackage{titling}  %Same


   %\TOCLanguage{arabic} % arabic is the main language 
   %\newcommand\lr[1]{\textLR{#1}}
   %\newcommand\rl[1]{\textRL{#1}}


   \makeatletter
   \def\ps@plain{\ps@empty\SAV@ps@plain}
   \makeatletter
   \pagestyle{plain}




    \newcommand\numberstring[1]{%   %Same
    \ifcase #1
    % zero
    \or الأول%
    \or الثاني%
    \or الثالث%
    \or الرابع%
    \or الخامس%
    \else I don't know%
    \fi
     }

    %\makeatletter
    \renewcommand{\thechapter}{\numberstring{\c@chapter}}
    %\makeatother

    \setlength{\cftbeforetoctitleskip}{-3em}

     \usepackage{titletoc}%
    \titlecontents{chapter}% <section-type>
    [0pt]% <left>
    {\bfseries}% <above-code>
    {\chaptername\ \thecontentslabel:\quad}% <numbered-entry-format>
    {}% <numberless-entry-format>
     {\titlerule*[.5pc]{.}\contentspage}
     \titlecontents{section}
                  [0pt]
                  {}
                  {\thecontentslabel {  } }
                  {}
                  {\titlerule*[.5pc]{.}\contentspage}
    \titlecontents*{subsection}
                  [0pt]
                  {}
                  {\thecontentslabel{  }}
                  {}
                  {\titlerule*[.5pc]{.}\contentspage}



    \addto\captionsarabic{%
    \renewcommand\chaptername{المبحث}
    }

   \addto{\captionsarabic}{\renewcommand*{\contentsname}{قائمة المحتويات }}

    \usepackage{titling}
    \newcommand{\subtitle}[1]{%
     \posttitle{%
     \par\end{center}
     \begin{center}\large#1 \end{center}
      \vskip0.5em}%
      }
     \newcommand{\subsubtitle}[1]{%
     \preauthor{%
     \begin{center}
     \large #1 \vskip0.5em
      \begin{tabular}[t]{c}
       }%
      }




   \makeatletter         
   \def\@maketitle{
   \raggedright
    \includegraphics[width = 40mm]{logo.png}\\[8ex]
     }
   \makeatother



    %\titlegraphic{\includegraphics[width=4cm]{logo.png}}



    \newlength{\myspace}
     \setlength{\myspace}{10em}

     \makeatletter
      \xpatchcmd{\@maketitle}{\vskip.5em}{\vskip\myspace}{}{}
      \makeatother

        \AtBeginShipoutNext{\AtBeginShipoutUpperLeft{%
         \put(\dimexpr\paperwidth-1cm\relax,-1.5cm){\makebox[0pt]    [r]{\framebox{

     \\جمهورية العراق
     \\ وزارة التعليم العالي والبحث العلمي
     \\ الجامعة العراقية
     \\ كلية الادارة والاقتصاد
  
  
    }}}%
    }}



      \begin{document}



    \begin{titlepage}

     \begin{center}



            
       \vspace*{1cm}
       \begin{center}

      \Large{  أثر المعرفة في تعزيز
            الميزة التنافسية}

       \vspace{0.5cm}
             \large
              بحث مقدم الى مجلس كلية الادارة والاقتصاد-   
              الجامعة العراقية وهو جزء من متطلبات نيل شهادة البكالوريوس في الادارة           والاقتصاد - قسم ادارة الاعمال    

        
      \vspace{1.5cm}
   
     اعداد الطالب\\
      \text{مصطفى محمد عفر}\\
       \vspace*{2cm}
       باشراف

      \text{ م . د وسن سعد }

     \vfill
   
     \vspace{1cm}
 
   
     ٢٥ نيسان ٢٠٢١
   
     \end{center}
   
        
     \end{center}
    \end{titlepage}
    %٪\maketitle

   \newpage


    \pagenumbering{Roman}
     \renewcommand{\thepage}{\protect\textLR{\Roman{page}}}

    \clearpage
    \setcounter{page}{1}



     \tableofcontents




     %\usepackage{titlesec}
     \titleformat{\chapter}[display]   
    {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge}   
    \titlespacing*{\chapter}{0pt}{-50pt}{40pt}


     \newpage
      \doublespacing
      \begin{doublespace}
      \input{الملخص}
      \end{doublespace}


        \newpage
         \doublespacing
          \begin{doublespace}
          \input{المقدمة}
           \end{doublespace}

           \newpage
           \doublespacing
           \begin{doublespace}
            \input{الاية القرانية}
             \end{doublespace}

          \newpage
           \doublespacing
          \begin{doublespace}
           \input{شكر وثناء}
            \end{doublespace}


           \newpage
           \doublespacing
          \begin{doublespace}
         \input{اهداء.tex}
           \end{doublespace}

           \pagenumbering{arabic}
           %\renewcommand{\thepage}{\protect          \textLR{\arabic{page}}}


            \newpage
            \doublespacing
             \begin{doublespace}
              \input{المبحث الأول}
              \end{doublespace}


              \begin{thebibliography}{99}


              \end{thebibliography}


                  \end{document}


                    %------------------------

My problem now is the Chapter numbering doesn't match the section numbering. I wanted before to change the chapter number to letter instead like chapter 1 to Chapter One and I succeeded in that applying Pieter van Oostrum suggestion but now I am having another problem which is the section numbering is also converted to the letters like 1.1 is converted to One.1 and I don't want this behavior. Is there any solution for this.

5
  • It might have something to do with arabic changing page styles. See tex.stackexchange.com/questions/587259 Mar 14, 2021 at 18:35
  • You want section and subsection numbers in the TOC, using alphabetical numbering, like the chapters not stared? Apr 6, 2021 at 23:19
  • I you put \pagenumbering{arabic} % move here <<<< AFTER \chapter{<the first>} it works as you wanted. See my example where \chapter{Introduce} is the first numbered chapter. page 1. Before that every page is with roman numbering. Apr 6, 2021 at 23:32
  • The Arabic numbering works fine, but before the chapters, the number is still Arabic too. I have like 1, 2, 3, then restart at chapter page to 1, 2, 3, and so on.
    – W. Sam
    Apr 6, 2021 at 23:48
  • Consider accepting one of the provided answers. Apr 26, 2021 at 20:25

3 Answers 3

2

I guess the first two problems are caused by arabtex and babel. For some reason the page numbers are written to the .aux and .toc files without any formatting. That is the reason it doesn't use roman numbering. And anyway, the \pagenumbering{roman} should be done before the \tableofcontents just in case that takes more than one page. Also there must be a \clearpage or \newpage before \pagenumbering{arabic}.

I would suggest to forget arabtex and babel, and instead run XeTeX and polyglossia instead.

\usepackage{polyglossia}
\setdefaultlanguage{arabic}
\setotherlanguage{english}

The third problem could have been solved by fmtcount, as @Simon Dispa writes, but that doesn't support Arabic, unfortunately. You could try to make a copy, for example of the Spanish or French files, but that would be a lot of work. As you need only a few numbers, I think you can do it yourself, see the following code and replace the English words with Arabic ones.

\newcommand\numberstring[1]{%
  \ifcase #1
  % zero
  \or one%
  \or two%
  \or three%
  \or four%
  \or five%
  \or six%
  \or seven%
  \else I don't know%
  \fi
}

\makeatletter
\renewcommand{\thechapter}{\numberstring{\c@chapter}}
\makeatother
2
  • I switched to XeLatex as you said and it works better with me. regarding the third problem, I applied what you wrote, it works with the chapter heading like Chapter 1 is converted to Chapter One, but there is another problem that happened which is the subtitle under it also converted to an aliphatic ones, like ( 1.1) is converted to (One.1) and I don't want this behavior, is there any solution for this
    – W. Sam
    Jun 14, 2021 at 10:42
  • knowing that this problem doesn't happen when I am using the pdfLatex engine, but it happened only with the XeLatex engine. And I needed to use the XeLatex engine as all other problems are solved with it. I appreciate if you can give me some help in this.
    – W. Sam
    Jun 14, 2021 at 10:56
2

If LuaLaTeX is an option (I strongly recommend it) and your system is up to date, try the following preamble (the document body is the same). There are a few comments:

\documentclass[11pt,a4paper]{report}

% Basic setup for Arabic. With the second option
% counters are (visually) subsec.sec.chap.
\usepackage[bidi=basic, layout=counters]{babel}

% Load the locale and define a new counter for it, with
% a space-separated list.
\babelprovide[
  import, main,
  counters/alphabetic = واحد إثنان ثلاثة أربعة خمسة]
  {arabic}

\babelfont{rm}{Amiri}

% Redefine the chapter ‘number’. It's now based on the
% counter just defined.
\renewcommand{\thechapter}{\localecounter{alphabetic}{chapter}}

\setlocalecaption{arabic}{chapter}{المبحث}
\setlocalecaption{arabic}{contents}{قائمة المحتويات}

\usepackage{lipsum}
\usepackage{setspace}
\usepackage{titlesec}
\usepackage{tocloft}
\usepackage{titletoc}%

% These are the setting in the OP. Note the overlapping
% because the chapter ‘number’ is long. 
\titlecontents{chapter}% <section-type>
  [0pt]% <left>
  {\bfseries}% <above-code>
  {\chaptername\ \thecontentslabel:\quad}% <numbered-entry-format>
  {}% <numberless-entry-format>
  {\hfill\contentspage}% <filler-page-format>

\title{\Huge\textsc{اللغة العربية}}
\author{سالم البوزيدي} 

enter image description here

2
  • can you show me the full code?
    – W. Sam
    Apr 3, 2021 at 14:32
  • I've extended a liitle bit the answer. Use this preamble with the original document body. Apr 4, 2021 at 9:45
1

I couldn't compile in Arabic, nor from right to left, so I made a mockup of your document in another language (Spanish, using some fake Spanish words) to avoid English and check the settings.

  1. \pagenumbering{arabic} should be after the first numbered chapter.

  2. Using

     \usepackage{fmtcount}
     \renewcommand{\thechapter}{\numberstring{chapter}} % or \Numberstring
    

you can change from chapter 1 to chapter one, etc. Note also the \def\captionsspanish{% to change the names from their default for the language.

  1. Section and subsection alignment looks correct after defining \titlecontents{section} and \titlecontents{subsection} (I reproduce the same setup you used for the chapter), but I don't know what happens to the writing from right to left!

A

\documentclass[11pt,a4paper]{report}
%\usepackage{arabtex}
\usepackage[utf8]{inputenc}
\usepackage{fontenc}
\usepackage[spanish]{babel}

\usepackage{lipsum}
\usepackage{setspace}
\usepackage{titlesec}
\usepackage{tocloft}

\usepackage{titletoc}%
\titlecontents{chapter}% <section-type>
[0pt]% <left>
{\bfseries}% <above-code>
{\chaptername\ \thecontentslabel:\quad}% <numbered-entry-format>
{}% <numberless-entry-format>
{\hfill\contentspage}% <filler-page-format>

\titlecontents{section} % added <<<<
[0pt]% <left>
{}% <above-code>
{\sectionname\ :\quad}% <numbered-entry-format>
{}% <numberless-entry-format>
{\hfill\contentspage}% <filler-page-format>

\titlecontents{subsection} % added <<<<
[0pt]% <left>
{\small}% <above-code>
{\subsectionname\ :\quad}% <numbered-entry-format>
{}% <numberless-entry-format>
{\hfill\contentspage}% <filler-page-format>

\def\captionsspanish{% % added <<<<
    \def\chaptername{Xapítulo}% 
    \def\sectionname{Xection}% 
    \def\subsectionname{Xubec}% 
    \def\figurename{Figura}%
    \def\tablename{Tabla}%
    \def\partname{Parte}%}
    \def\contentsname{Contenido completo}%
    \def\listtablename{Lista de Tablas}%
}

\title{%
\Huge\textsc{Un titulo}
}
 \author{Mi Nombre}
 
 \usepackage{fmtcount}
 \renewcommand{\thechapter}{\numberstring{chapter}} % or \Numberstring

\begin{document}
\maketitle
\tableofcontents

\pagenumbering{roman}

\clearpage
\setcounter{page}{5}

\chapter*{Presenta}
\addcontentsline{toc}{chapter}{Presenta}

\chapter*{Agradece}
\addcontentsline{toc}{chapter}{Agradece}

\chapter*{Resumen}
\addcontentsline{toc}{chapter}{Resumen}


\chapter{Introduce}
\pagenumbering{arabic}  % move here <<<<

\section{A}
\subsection{aa}
\section{B}
\subsection{bb}
\subsection{cc}

\chapter{Desarrollo}

\chapter{Conclusiones}

%\begin{thebibliography}{99}
%[1]
%من ويكيبيديا، الموسوعة الحرة
%\end{thebibliography}
\end{document}
2
  • can you add the numbers of sections and subsections in your code?
    – W. Sam
    Apr 6, 2021 at 22:59
  • @W. Sam In the table of content or in the document ? Apr 6, 2021 at 23:07

You must log in to answer this question.

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