1

I want to align sections titles with margin notes as shown below.

\documentclass[12pt,a4paper,twoside,openright]{book}
% Page format
\usepackage[left=2cm,right=6cm,top=3cm,bottom=2.5cm,
headsep=1.5cm,headheight=1cm,marginparwidth=3.5cm, marginparsep=5mm,bindingoffset=0mm]{geometry}

\usepackage{amsfonts}
\usepackage[x11names]{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}
\usepackage{todonotes}

\newlength{\myoddoffset}
\setlength{\myoddoffset}{\marginparwidth + \marginparsep}
\usepackage{fancyhdr}
\makeatletter
\fancypagestyle{mypagestyle}{
\fancyheadoffset[LO,LE]{\myoddoffset}
%\fancyfootoffset[LO,LE]{\marginparsep+\marginparwidth}
\fancyhead{}
\fancyhead[LE]{\thepage}
\fancyhead[RO]{\thepage}
\fancyhead[RE]{\leftmark}
\fancyhead[LO]{\rightmark}
\fancyfoot{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
\makeatother
\pagestyle{mypagestyle}


\reversemarginpar

\usepackage{xltxtra}
\usepackage{polyglossia}
\setdefaultlanguage[calendar=gregorian,hijricorrection=1,locale=morocco]{arabic} 

\defaultfontfeatures{Ligatures=TeX,%
Mapping=tex-text,%
AutoFakeSlant=0.2%Simulate Italic%
}
\newfontfamily\arabicfont[Script = Arabic,Scale=1.0]{Amiri} 


\makeatletter
\tikzset{notestyle/.append style={
    align=right}}

\renewcommand{\@todonotes@drawMarginNote}{%
\if@todonotes@dviStyle%
    \begin{tikzpicture}[remember picture]%
        \draw node[notestyle] {};%
    \end{tikzpicture}\\%
    \begin{minipage}{\@todonotes@textwidth}%
    \if@todonotes@authorgiven%
      \@todonotes@sizecommand \@todonotes@author \@todonotes@text%
    \else%
      \@todonotes@sizecommand \@todonotes@text%
    \fi%
    \end{minipage}\\%
    \begin{tikzpicture}[remember picture]%
        \draw node[notestyle] (inNote) {};%
    \end{tikzpicture}%
\else%
    \let\originalHbadness\hbadness%
    \hbadness 100000%
    \begin{tikzpicture}[remember picture,baseline=(X.base)]%
        \node(X){\vphantom{X}};%
        \draw node[notestyle,font=\@todonotes@sizecommand,anchor=north] (inNote) at (X.north)%
            {\@todonotes@text};%
        \if@todonotes@authorgiven%
            \draw node[notestyle,font=\@todonotes@sizecommand,anchor=north] (inNote) at (X.north)%
                {\@todonotes@sizecommand\@todonotes@author};%
            \node(Y)[below=of X]{};%
            \draw node[notestyle,font=\@todonotes@sizecommand,anchor=north] (inNote) at (X.south)%
                {\@todonotes@text};%
        \else%
            \draw node[notestyle,font=\@todonotes@sizecommand,anchor=north] (inNote) at (X.north)%
                {\@todonotes@text};%
        \fi%
    \end{tikzpicture}%
    \hbadness \originalHbadness%
\fi}
\makeatother

\begin{document}


\section{مجموعات الأعداد}

 قسمة عددين صحيحين هو عدد نسبي، أي أنه عنصر من مجموعة 
{\bfseries الأعداد النسبية}:
$$
\vadjust{\todo{\RL{مجموعة العناصر 
$\frac{m}{n}$
 حيث $m$ عدد صحيح و $n$ عدد طبيعي.
 }}}
\mathbb{Q} = \left\{\frac{m}{n} : m\in \mathbb{Z} , n\in\mathbb{N}\right\}. 
$$

\end{document}

Desired Output

  • Could you make your MWE a little more minimal? From what I can gather, all you really want is to move the section titles into the margin. This can be done with \leftskip or \rightskip (depending which side of the page}. – John Kormylo Mar 6 '16 at 15:38
  • @JohnKormylo I want all the sections titles in the whole document to be aligned with margin notes and headings. So I don't want really to do it manually for each sequence. What I put in the MWE is what is really needed: RTL, twoside, todonotes, fancyhdr. – user46994 Mar 6 '16 at 18:29
  • Since \section is used for lots of other things (\tableofcontents for example), it would be better to create a new macro (\mysection) than redefine the old one. – John Kormylo Mar 6 '16 at 21:01
1

This will move the section title into the left margin (for left to right). I used [oneside] so that the left margin would be big enough.

The only way I know to use right to left is to switch languages (BTW \rightskip works there) which leads to errors about not being able to find the needed font.

\documentclass[oneside]{book}
\usepackage{showframe}

\reversemarginpar

\newlength{\offset}
\setlength{\offset}{\dimexpr \marginparwidth+\marginparsep}

\newcommand{\mysection}[2][]{%
  \rightskip=-\offset
  \section[#1]{#2}%
  \rightskip=0pt}

\begin{document}

\leftskip=-\offset
\section{I wonder what happens if I use a very very very very long title?}
\leftskip=0pt

\end{document}

left margin

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.