0

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.

My MWE:

% Options for packages loaded elsewhere
%\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
    \DeclareUnicodeCharacter{02BE}{}
\documentclass[a4paper, 12pt, oneside]{article}
\usepackage[a4paper, portrait, margin=0.9in,headheight=14.5pt]{geometry}

\usepackage{caption}
\usepackage{titling}
\usepackage[onehalfspacing]{setspace}
\usepackage{titlesec}
\titlespacing*\section{0pt}{12pt plus 4pt minus 2pt}{0pt plus 2pt minus 2pt}

\usepackage[normalem]{ulem}
\usepackage{marginnote}







\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi





% START DOCUMENT %

\begin{document}




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

\end{document}

Thanks :)

0

1 Answer 1

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}
\usepackage[onehalfspacing]{setspace}
\usepackage{graphicx}
\usepackage{blindtext}
\newlength{\minboxwidth}
\newlength{\maxboxwidth}
\newlength{\oldmaxboxwidth}
\newcommand*{\notefont}{\linespread{1}\footnotesize\raggedright}
\makeatletter
\newcommand*{\mymarginnote}[1]{%
  \setlength{\minboxwidth}{2\baselineskip}% minimum width of the text
  \setlength{\maxboxwidth}{\textheight}% maximum width of the text
  \setlength{\oldmaxboxwidth}{\maxboxwidth}%
  \@tempcnta=10 % max. iterations
  % Now we iterate to get a good boxwidth not extending 
  \@whilenum \@tempcnta > \z@\do {%
    \advance\@tempcnta\m@ne
    \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
      \oldmaxboxwidth=\maxboxwidth
      \maxboxwidth=\dimexpr (\maxboxwidth+\minboxwidth)/2\relax
    \else
      \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@
        \else
          % try to increase width
          \minboxwidth=\maxboxwidth
          \maxboxwidth=\oldmaxboxwidth
        \fi
      \else
        % Don't think, that this would ever happen, but if, it would be perfect
        \@tempcnta \z@
        \oldmaxboxwidth=\maxboxwidth
      \fi
    \fi  
  }
  \reversemarginpar% Use left margin of oneside document
  \marginpar{\hfill\rotatebox[origin=c]{90}{\parbox{\oldmaxboxwidth}{\notefont #1}}}%
}
\makeatother

\begin{document}
    
abc text
\mymarginnote{expand on this?}
\blindtext

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

\end{document}

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.

4
  • 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 .