[Tex/LaTex] left and right aligned section title on one line

horizontal alignmentsectioningtitlesec

I am trying to have a simple bilingual title for a section. The English text should align to the left and the Arabic text should align to the right, both on the same line.

The following line of code almost does the job, but the Arabic text is not fully right aligned——it looks like there is an extra margin, compared to the rest of the document.

\section{English Title \hfill\textarabic{كلمة}}


I tried titlesec's block shape, but that didn't do the trick.

How can I fix it?

Best Answer

\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{arabic}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.2]{Arabic Typesetting}
\usepackage{titlesec}
\usepackage{lipsum}

\titleformat{\section}
[block]{\normalfont\bfseries\Large}{\rlap{\thesection}}{0em}
{\hspace{.05\linewidth}\begin{minipage}[t]{.95\textwidth}}[\end{minipage}]

\begin{document}
\section{A section in English \hfill \textarabic{فصل باللغة العربية}}
\lipsum[1]
\section{English Title \hfill \textarabic{عنوان بالعربي}}
\lipsum[2]
\end{document}


You can use a minipage inside your section title to perform whatever alignment you need. Of course titlesec is essential in this situation. The block shape can be defined as this:

\titleformat{\section}
[block]{\normalfont\bfseries\Large}{\rlap{\thesection}}{0em}
{\hspace{.05\linewidth}\begin{minipage}[t]{.95\textwidth}}[\end{minipage}]


where we left .05\linewidth for section numbering and the remaining .95\textwidth for the bilingual title.