Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
You need to provide a small example document that demonstrates the effect you describe (which is not the expected behaviour) –  David Carlisle May 11 at 20:36

1 Answer 1

up vote 4 down vote accepted

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}
share|improve this answer
    
This is really helpful, but unfortunately my incompetence breaks it. Perhaps in light of my edit, you have a better idea... –  Henry Gomersall May 11 at 21:08
    
@HenryGomersall see update –  David Carlisle May 11 at 21:43
    
It works perfectly - thanks! –  Henry Gomersall May 11 at 22:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.