[Tex/LaTex] Alignment marginnotes

horizontal alignmentmarginnotemarginstitlesec

enter image description here

I am trying to write a report for Uni, where I need something like what marginnotes does. The problem is I would need two different margins on the left side of the page. One for the chapter or section title and one for the paragraph, and to the left side of the paragraph there should be a block title, horizontally aligned to the title, which doesn't appear in the toc. maybe this example can give you an idea of what I'm looking for.

\documentclass[10pt,twoside,a4paper,fleqn]{report}
\usepackage[utf8]{inputenc}
\usepackage[centering,left=4cm,right=1cm,top=1cm,bottom=1cm,includeheadfoot]{geometry}
\usepackage[german]{babel,varioref}
\usepackage{marginnote, scrextend, etoolbox, titlesec}

%always put marginals on the left side of the page
\makeatletter
\patchcmd{\@mn@margintest}{\@tempswafalse}{\@tempswatrue}{}{}
\patchcmd{\@mn@margintest}{\@tempswafalse}{\@tempswatrue}{}{}
\reversemarginpar 
\makeatother

\titlespacing*{\section}{-3cm}{\parskip}{\parskip}
\titlespacing*{\chapter}{-3cm}{\parskip}{\parskip}


\begin{document}
\chapter{Model chapter for a report}
This is the first chapter of the report.

\section{Model section}
\marginnote{This is a marginal}This is the first section of the first chapter of the report

\end{document}

The problem is, although the paragraph has an added 3cm of margin, the marginal will not be aligned to the title, and even be cut off by the page border. I know I could simply change the geometry settings, but this is not quite what I need, since the section and chapter titles will then also be moved into the page.

Best Answer

I think something along these lines can be achieved with the titlesec package (and no doubt others too!). I find it voodoo-ish (and, for a person like me, I could do with more examples in the documentation), but this seems to work:

For the section

\newcommand{\titlebox}[1]{%
\parbox[t]{2.5cm}{\raggedright #1}}

\titleformat{\section}
           [leftmargin]% type is "marginal"
           {\bfseries}%  format
           {}%           no label used
           {0pt}%        no need for any separation
           {\titlebox}%  command to set title

\titlespacing{\section}
             {3cm}%      width of marginal
             {*1}%       space before
             {*0}%       and after

We define \titlebox{} simply as a convenient way of having a single argument macro that will typeset the material in an appropriate box, ragged right. The key (I think) is the first argument in \titlespacing which controls the width of the marginal. (I have assumed that an extra 3 cm is added to the margin to allow for titles -- in the example I've set a 5cm left margin and a 2cm right margin.)

For the chapter title, we use a slightly different method to get it to hang appropriately into the left margin, but I think that's obvious from the example that follows.

\documentclass{report}
\usepackage[left=5cm,right=2cm,bottom=2cm,top=1cm,includeheadfoot]{geometry}

\usepackage{titlesec}

\newcommand{\titlebox}[1]{%
  \parbox[t]{2.5cm}{\raggedright #1}}

\titleformat{\section}
            [leftmargin]
            {\bfseries}
            {}
            {0pt}
            {\titlebox}

\titleformat{\chapter}
            [hang]
            {\bfseries\Large}
            {}
            {0pt}
            {}
            [{\titlerule[1pt]}]

\titlespacing{\section}
            {3cm}
            {*1}
            {*0}

\titlespacing{\chapter}
            {-3cm}
            {*2}
            {*2}


\setlength{\parindent}{0pt}
\setlength{\parskip}{1ex}


\begin{document}

\chapter{Chapter Heading}

\section{Summary of Work}


The object of this report is to show how one can produce marginal section headings, in this fashion. Similar things could and would need to be done for subsections and the like.

\section{Date}
May 10, 2013, London.

\section{Author}
Paul Stanley.

\end{document}

The end result:

Revised titles

Please note that I have manually set \parskip only for demonstration purposes: for a real document you might well want to use a package for such things.