1

This is follow up to earlier question I asked about using margin notes here

I found that when I use book style the margin note jumps from the left to the right, depending on if the page is odd or even, this is even though I made sure to added \reversemarginpar to make sure the note goes to the left side of the page.

Then I changed the book style and added oneside which fixed the issue, and now all margin note show on the left side of each page.

But the note itself now gets broken into two small lines for some reason.

Even if I use geometry to increase the left margin, it is still not working.

Examples below help show the problem. First example using default.

\documentclass[12pt]{book}
\usepackage{listings}
\usepackage{fancybox,fancyvrb,xcolor}
\usepackage{marginnote}

\definecolor{bg}{RGB}{255,255,226}
\lstdefinestyle{TEXT}{%
    basicstyle=\ttfamily\normalsize,
    breaklines=false,
    columns=fullflexible,
    keepspaces=true,
    backgroundcolor=\color{bg},
    rulecolor=\color{gray},
    language=,
    frame=single,
    frameround=tttt,
    aboveskip=12pt,belowskip=6pt
}

\lstnewenvironment{TEXTinline}{%
  \lstset{style=TEXT}}{}

\begin{document}
\reversemarginpar

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command 
  which can be very very very 
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command 
  which can be very very very 
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command 
  which can be very very very 
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command 
  which can be very very very 
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command 
  which can be very very very 
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command 
  which can be very very very 
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command 
  which can be very very very 
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command 
  which can be very very very 
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command 
  which can be very very very 
  long command
  used to process the file
\end{TEXTinline}

\end{document}

This gives

enter image description here

The above shows the problem. The margin shift from left to right depending on page. Now I did the same as above, but changed \documentclass[12pt]{book} to \documentclass[12pt,oneside]{book} and everything else the same. This is the result

enter image description here

Looking closely at one:

enter image description here

What is the correct way to make all margin note show on the left side of page in book style without this breakup issue?

It looks like margin note have some fixed width. I need to find out if I can change that.

TL 2023 on Linux

4
  • 1
    To see source of your problem, add \usepackage{showframe}} to document preamble and compare result when you use option onseside and when is not (difference is quite big). BTW, boxes are wider than \textwidth˙ . Is this intentional?
    – Zarko
    Nov 20, 2023 at 7:05
  • As possible remedy is to add \usepackage[marginpar=22mm]{geometry} to document preamble and than remove option 12pt from \marginnote{....}. With this you increase width of marginpar and not shift not to the right. by this changes you will get desired result.
    – Zarko
    Nov 20, 2023 at 7:22
  • @Zarko I tried what you suggested but it is not working. \usepackage[marginpar=22mm]{geometry} \begin{document} \reversemarginpar Some text above the listing \marginnote{command} \begin{TEXTinline} This is my long command which can be very very very long command used to process the file \end{TEXTinline} etc... And this is the output: !Mathematica graphics as you see, withput [12pt] on the margine note, it is now shifted above, I am using this per answer I linked to.
    – Nasser
    Nov 20, 2023 at 7:30
  • It working! See my answer below.
    – Zarko
    Nov 20, 2023 at 7:42

1 Answer 1

1

To long for the comment.

When you change \documentclass[12pt]{book} to \documentclass[12pt,oneside]{book} you change page layout a lot. To see this I suggest you in comment to add showframe package which show page layout.

For example, at default two side layout without using correction done by geometry package the page layout is:

enter image description here

and at oneside layout is

enter image description here

Considering my suggestion in the second comment, the MWE is:

\documentclass[12pt,oneside]{book}      % <--- one side layout
\usepackage[marginpar=22mm]{geometry}   % <--- added for increasing marginpar width
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%
\usepackage{lipsum}                              % for dummy text
%---------------------------------------------------------------%
\usepackage{listings}
\usepackage{fancybox,fancyvrb,xcolor}
\usepackage{marginnote}

\definecolor{bg}{RGB}{255,255,226}
\lstdefinestyle{TEXT}{%
    basicstyle=\ttfamily\normalsize,
    breaklines=false,
    columns=fullflexible,
    keepspaces=true,
    backgroundcolor=\color{bg},
    rulecolor=\color{gray},
    language=,
    frame=single,
    frameround=tttt,
    aboveskip=12pt,belowskip=6pt
}

\lstnewenvironment{TEXTinline}{%
  \lstset{style=TEXT}}{}

\begin{document}
%\reversemarginpar   % <--- removed, since this is oneside document

\marginnote{command} % removed shift
\begin{TEXTinline}
  This is my long command
  which can be very very very
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command
  which can be very very very
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command
  which can be very very very
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command
  which can be very very very
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command
  which can be very very very
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command
  which can be very very very
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command
  which can be very very very
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command
  which can be very very very
  long command
  used to process the file
\end{TEXTinline}

\marginnote{command}[12pt]
\begin{TEXTinline}
  This is my long command
  which can be very very very
  long command
  used to process the file
\end{TEXTinline}

\end{document}

and obtained result is.

enter image description here

Is this what you after? BTW, in the answer I did not deal with the problem of the vertical position of the marginnote.

Addendum:
If your document will be only on web, that is probably better to usehtml document than pdf. Anyway, in the case that margin note should be always on the left side of text, you need to increase left side margin of document. For example to

\documentclass[12pt, oneside]{book}
\usepackage[hmargin={1.5in, 1in},

( I didn't bother with finding of appropriate size of the left margin) and use instruction \reversemarginpar in document body. Now result is:

enter image description here

enter image description here

4
  • Thanks. But I wanted the marginnote to be on the left side of the listing, Not on the right side. it is easier to read if it on the left side of the listings. Your example shows them all on the right. but will try your code with \reversemarginpar and see how it works.
    – Nasser
    Nov 20, 2023 at 8:05
  • On binding side? Than you need to increase page margins (by this reduce text width!)
    – Zarko
    Nov 20, 2023 at 8:07
  • Yes. But this PDF is meant to be viewed online, not for printing. OK, will try your suggestion of increasing page margin more and see. But from my example, I see lots of white space on the left side as is. So I do not understand why text will break.
    – Nasser
    Nov 20, 2023 at 8:09
  • See addendum to my answer. Will appear ASAP.
    – Zarko
    Nov 20, 2023 at 8:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .