1

The sidenotes package is supposedly using the \marginnote command, but I'm getting a justified text rather than a left / right ragged one. I'm a little confused.

\documentclass{book}
\usepackage{lipsum}
\usepackage{sidenotes}
\usepackage{marginnote}
\usepackage{graphics}

\begin{document} \begin{figure} \centering \sidecaption{\lipsum[66]} \includegraphics{example-image-a} \label{fig:my_labela} \end{figure} \marginnote{\footnotesize\lipsum[66]}[-4.5cm] \newpage \begin{figure} \centering \sidecaption{\lipsum[66]} \includegraphics{example-image-b} \label{fig:my_labelb} \end{figure} \marginnote{\footnotesize\lipsum[66]}[-4.5cm]

\end{document}

right page left page

Atcold
  • 1,727

1 Answers1

2

Add \DeclareCaptionStyle{sidecaption}{font=footnotesize, justification=raggedright}

a

The manual is not very explicit on how to set the caption styles:

Please refer to the caption manual for details on styles.

The package caption defines

 \DeclareCaptionFormat{name}{code} % name is the name of the caption format

\DeclareCaptionLabelFormat{name}{code}

\DeclareCaptionLabelSeparator{name}{code}

and others. Also the command \DeclareCaptionStyle .

\documentclass{book}
\usepackage{lipsum}
\usepackage{sidenotes}
\usepackage{marginnote}
\usepackage{graphics}

\DeclareCaptionStyle{sidecaption}{font=footnotesize, justification=raggedright}% added <<<<<<<<<<<<<<<<<<<<

\begin{document} \begin{figure} \centering \sidecaption{\lipsum[66]} \includegraphics{example-image-a} \label{fig:my_label1} \end{figure} \marginnote{\footnotesize\lipsum[66]}[-4.5cm]

\end{document}

UPDATE After follow-up suggestion: option twoside for book

Page 1

d

Page 2

e

This is the complete updated code.

Note: To detect odd or even page it is needed to have\RequirePackage[strict]{changepage} (which in this case is done by sidenotes).

\documentclass[twoside]{book}
\usepackage{lipsum}
\usepackage{sidenotes}% loads \RequirePackage[strict]{changepage}
\usepackage{marginnote}
\usepackage{graphics}

\usepackage[outer=7cm, inner=2cm, marginparwidth=5cm,marginparsep=5mm,showframe]{geometry}% show & large margins <<<

%%******************************************************************** \DeclareCaptionStyle{sidecaption}{font=footnotesize, justification=twoside}% added <<<
\DeclareCaptionJustification{twoside}{% added <<<<<<<<<<<<< \checkoddpage \ifoddpage \raggedright \else \raggedleft \fi } %%********************************************************************

\begin{document} \begin{figure} \centering \sidecaption{\lipsum[66]} \includegraphics{example-image-a} \label{fig:my_label} \end{figure} \marginnote{\footnotesize\lipsum[66]}[-4cm]

\lipsum[1]

\clearpage

\begin{figure}
    \centering
    \sidecaption{\lipsum[66]}
    \includegraphics{example-image-b}
    \label{fig:my_label}
\end{figure}
\marginnote{\footnotesize\lipsum[66]}[-4cm]
\lipsum[2]  

\end{document}

Simon Dispa
  • 39,141
  • How did you find out? I did read the source, but couldn't understand that. More precisely, where is \DeclareCaptionStyle defined? Also, it should be raggedright for right notes but raggedleft for left notes. \marginnote[<left>]{<right>}[<voffset>] has a left / right option for this reason. – Atcold Feb 21 '22 at 18:40
  • I see… The caption package is defining that. Digging further :D – Atcold Feb 21 '22 at 18:51
  • Fixed it! Found the solution here https://tex.stackexchange.com/a/499926/33287! Please, add \DeclareCaptionJustification{raggedauto}{\checkoddpage \ifoddpage \raggedright \else \raggedleft \fi} to your solution and replace raggedright with raggedauto. – Atcold Feb 21 '22 at 19:03
  • @Atcold I will do it later. You might need to expand your question for two sides. – Simon Dispa Feb 21 '22 at 19:19
  • Thanks a lot! And, I guess you've used the Lua debugger to show those boundaries? – Atcold Feb 21 '22 at 19:58
  • @Atcold Used showframe option in geometry. See last code. Please remember to update your question to include odd and even pages. Thank you for your feedback! – Simon Dispa Feb 21 '22 at 20:00
  • The default for marginnote is ragged (left or right). My question was asking why sidenotes was going for a justified alignment. You did answer my question and provided a fix for sidenotes incorrect behaviour. Anyhow, I'll make it more explicit. Thanks again for your help! And thanks for the showframe tip!! – Atcold Feb 22 '22 at 14:53