[Tex/LaTex] Alignment of marginnote independently of main paragraph

horizontal alignmentmarginnote

I've noticed that when a \marginnote is added (edit: using the marginnote package), the horizontal alignment of that note is inherited from wherever the note is placed. In my case, I wish to have a margin note defined inside a section heading, which makes the margin note centred.

If I try to add \raggedleft or \raggedright to the instruction, then it is either ignored, or overwrites the formatting of the section header (depending on whether it is in the left or right margin).

Is there some way to change the horizontal alignment of the marginal text independently of the text in which it is defined?

Edit:
My apologies, in constructing the minimum working example, I realise I've embarrassingly omitted the important detail of how I (almost certainly incorrectly) set the centering of the section header. Below is a minimum working example of what I want.

\documentclass{article}
\RequirePackage{sectsty}
\allsectionsfont{\centering\sc} % <-- this is probably wrong!

\usepackage[fulladjust]{marginnote}

\begin{document}
\section*{This is a section header\marginnote{I really really want this 
margin note to be raggedright, and not centred like it is here.}}
\end{document}

Another point to note is that I actually want the text flushed left or right depending on whether the note is in the left or the right margin. This means is think I do need to change the alignment of the marginal text.

Best Answer

I assume (but you don;t say) that you are using \marginnote from the marginnote package. That like a standard \marginpar does not pick up the current alignment. The following shows the note is justified as normal whether it is used in a justified paragraph, or a flushleft or centred one.

enter image description here

\documentclass{article}

\usepackage{marginnote}

\begin{document}

one two three one two three one two three one two three one two three one two three%
\marginnote{a a a a a a a a a a} 
one two three one two three one two three one two three one two three one two three 

\begin{flushleft}
one two three one two three one two three one two three one two three one two three%
\marginnote{a a a a a a a a a a} 
one two three one two three one two three one two three one two three one two three 
\end{flushleft}

\begin{center}
one two three one two three one two three one two three one two three one two three%
\marginnote{a a a a a a a a a a} 
one two three one two three one two three one two three one two three one two three 
\end{center}


\end{document}

sectsty is doing somethig odd, can't be bothered to debug that so just re-assert the normalisation of font and alignment that marginpar/marginnote do anyway but that got broken somewhere. This is ragged left on one side and raggedright in the other, as is normal for marginnote.

enter image description here

\documentclass[twoside]{article}
\RequirePackage{sectsty}
\allsectionsfont{\centering\sc} % <-- this is probably wrong!

\usepackage[fulladjust]{marginnote}

\makeatletter
\renewcommand\marginfont{\normalfont}
\renewcommand\raggedleftmarginnote{\@parboxrestore\@marginparreset\raggedleft}
\renewcommand\raggedrightmarginnote{\@parboxrestore\@marginparreset\raggedright}
\makeatother

\begin{document}


\section*{This is a section header\marginnote{I really really want this 
margin note to be raggedright, and not centred like it is here.}}

\clearpage

\section*{This is a section header\marginnote{I really really want this 
margin note to be raggedright, and not centred like it is here.}}

\end{document}
Related Question