I'd like to use \marginnotes{text here} to create vertical margin notes, since for me the margin is so narrow that the margin line is broken up a lot, making it difficult to read.

I've tried the solution here: Margin note/annotation with vertical text direction in APA7 manuscript but for me that just results in one or two syllables being there, albeit vertical, and the rest being gone or off-screen.


% Options for packages loaded elsewhere
\documentclass[a4paper, 12pt, oneside]{article}
\usepackage[a4paper, portrait, margin=0.9in,headheight=14.5pt]{geometry}

\titlespacing*\section{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}


\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex



   % START BODY %   
abc text
\marginnote{expand on this?}    
%   \clearpage


Thanks :)


1 Answer 1


If I understand, what you want, you could (alternative to John's answer) iterate to find a good width for longer text, that has to be broken into several lines, e.g. (I've removed everything unrelated to the problem):

\documentclass[a4paper, 12pt, oneside]{article}
\usepackage[a4paper, portrait, margin=0.9in,headheight=14.5pt]{geometry}
  \setlength{\minboxwidth}{2\baselineskip}% minimum width of the text
  \setlength{\maxboxwidth}{\textheight}% maximum width of the text
  \@tempcnta=10 % max. iterations
  % Now we iterate to get a good boxwidth not extending 
  \@whilenum \@tempcnta > \z@\do {%
    \settoheight{\@tempdima}{\parbox{\maxboxwidth}{\notefont #1}}%
    \settodepth{\@tempdimb}{\parbox{\maxboxwidth}{\notefont #1}}%
    \ifdim \dimexpr\@tempdima + \@tempdimb\relax <\marginparwidth
      % total height of box is less than \marginparwidth -> can reduce width
      \maxboxwidth=\dimexpr (\maxboxwidth+\minboxwidth)/2\relax
      \ifdim \dimexpr\@tempdima + \@tempdimb\relax >\marginparwidth
        % total height of box is greater than \marginparwidth -> advance width
        \ifdim \maxboxwidth=\oldmaxboxwidth
          % Cannot extend height -> stop and use (to small) width
          \@tempcnta \z@
          % try to increase width
        % Don't think, that this would ever happen, but if, it would be perfect
        \@tempcnta \z@
  \reversemarginpar% Use left margin of oneside document
  \marginpar{\hfill\rotatebox[origin=c]{90}{\parbox{\oldmaxboxwidth}{\notefont #1}}}%

abc text
\mymarginnote{expand on this?}

\mymarginnote{What about a longer text? Will the automatism to detect a proper
width work?}


enter image description here

In difference to John's answer the note is not forced to fit the height of the paragraph beside, but just tries to use the full width of the margin column.

You can change origin=c to origin=l or origin=r to get another vertical alignment of the notes. You can change \minboxwidth to define another width of text, that should not be broken into several lines.

Note: If the maximal number of iterations is too low, the final \parbox can be wider as needed, but not wide enough only if the box has to be wider than \textheight.

  • That's exactly what I wanted and needed. Thank you so much! Jul 19, 2023 at 22:15
  • I have another question, is it possible to center mymarginnote vertically to the paragraph that it's part of? Otherwise I'm not always sure which paragraph my note refers to. Thanks :) Jul 21, 2023 at 13:19
  • @ReaderGuy42 IMHO not with a simple command. You would need an environment solution similar to John's answer. With a command you could only change the origin (see the note about this in my answer) to change the alignment. You even could add an optional argument for the origin to \mymarginnote. And with an environment you still would have to specify, what should happen, if the paragraph is very short but the note very long, which seems to be your problem with John's answer, because otherwise you simply could use his solution.
    – cabohah
    Jul 21, 2023 at 15:52
  • OK, yeah, I understand that problem. I could use John's solution but since I write in a different program and then compile to LaTeX it would be a hassle to have to include all those delimiters. I just thought I'd ask if there was a simple fix. Thanks anyways :) Jul 21, 2023 at 18:16

You must log in to answer this question.

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