1

I am using apa7 package in writing a manuscript (\documentclass[man]{apa7}). I am trying to add margin notes/annotation next to (some lines of) some paragraphs that summarize the gist of it, to show why I have written those paragraphs and why I've chosen to place it at that place in the manuscript. Searching for similar questions on TeX.SE (e.g., the first 50 search results) did not lead me to a solution.

(I know apa7 manuscript document type has limitations and is not meant to look too good/pleasing, though, at this stage of our writing, I need to use APA manuscript formatting before it is typeset for publication.)

Desired result

Ideally, I would like such margin annotations to appear on the left side of the text, with a vertical direction:

basic margin note

Additionally, having a vertical line next to the paragraph would be helpful:

margin note with a vertical line

It would be great if it is done by a macro (?) that would allow turning it on/off in the preamble for the whole document (like this solution for colored comments) for, e.g., when we want a clean PDF without manually removing all the notes.

Current solution and shortcoming

As far as my not-so-deep knowledge of TeX allowed me, as a dirty remedy, I tried using \marginpar{...} and \todo[noline]{...} (from todonotes package) to somehow allow me to write on the margins. However, I wasn't able to change the direction of the text. Furthermore, the text wraps terribly bad, and I could not put them on the left margin. Here is what I am getting:

sad, bad results

And here is a (not-so-brief) MWE to reproduce it:

\documentclass[man]{apa7}

\usepackage[american]{babel}

\usepackage{csquotes} \usepackage[style=apa,sortcites=true,sorting=nyt,backend=biber]{biblatex} \DeclareLanguageMapping{american}{american-apa} \addbibresource{bibliography.bib}

\usepackage{todonotes}

\title{Sample APA-Style Document Using the \textsf{apa7} Package with marginpar/todonotes}

\author{ManuHaq} \affiliation{A University Somewhere}

\leftheader{ManuHaq}

\abstract{This is an MWE for TeX.SE, that asks for margin notes in an APA7 manuscript.}

\keywords{APA style, demonstration, marginpar, todonotes}

\begin{document}

\maketitle

As any dedicated reader can clearly see, the Ideal of practical reason is a representation of,as far as I know, the things in themselves; as I have shown elsewhere, the phenomenashould only be used as a canon for our understanding. \marginpar[left]{A margin note that, unfortunately, doesn't wrap well :(} The paralogisms of practical reasonare what first give rise to the architectonic of practical reason. As will easily be shown inthe next section, reason would thereby be made to contradict, in view of theseconsiderations, the Ideal of practical reason, yet the manifold depends on the phenomena

Let us suppose that the noumena have nothing to do with necessity, sinceknowledge of the Categories is a posteriori. Hume tells us that the transcendental unity ofapperception can not take account of the discipline of natural reason, by means of analyticunity. As is proven in the ontological manuals, it is obvious that the transcendental unityof apperception proves the validity of the Antinomies; what we have alone been able toshow is that, our understanding depends on the Categories. It remains a mystery why theIdeal stands in need of reason. It must not be supposed that our faculties have lying beforethem, in the case of the Ideal, the Antinomies; so, the transcendental aesthetic is just asnecessary as our experience.

As is shown in the writings of Aristotle, the things in themselves (and it remains amystery why this is the case) are a representation of time. \todo[noline]{A todonote with no line. As you see, the text again doesn't wrap well :(} Our concepts have lying before them the paralogisms of natural reason, but our a posteriori concepts have lying before them the practical employment of our experience. Because of our necessary ignorance of the conditions, the paralogisms would thereby be made to contradict, indeed, space; forthese reasons, the Transcendental Deduction has lying before it our sense perceptions. (Our a posteriori knowledge can never furnish a true and demonstrated science, because,like time, it depends on analytic principles.) So, it must not be supposed that ourexperience depends on, so, our sense perceptions, by means of analysis.

\end{document}

One final wish

It would be great if the vertical margin note wrap if it exceeds the paragraph length, or just allow adding manual line breaks in it.

final wish

psyguy
  • 237

1 Answers1

2

This assumes that it doesn't matter where in the paragraph the note occurs, since it will expand to fill the space.

The odd page check is not totally reliable (if the entire paragraph is moved to the next page). See the ifoddpage package.

\documentclass{book}
\usepackage{marginfix}% not needed, just usefuld
\usepackage{varwidth}% for short notes
\usepackage{adjustbox}% for rotatebox
\usepackage{lipsum}% MWE only

\newif\ifshownoted \shownotedtrue% default \shownotedfalse

\newsavebox{\notedbox}

\makeatletter \def\udbox#1{% fragile, see lrbox \edef\reserved@a{% \endgroup \setbox#1\vbox{% \begingroup\aftergroup}% \def\noexpand@currenvir{@currenvir}% \def\noexpand@currenvline{\on@line}}% \reserved@a @endpefalse \color@setgroup \ignorespaces} \def\endudbox{\unskip\color@endgroup} \makeatother

\newenvironment{noted}[1]{% #1 = note to be placed alongside paragraph \par\strut\vspace{-\baselineskip}\hrule height0pt% fix spacing \def\passparameter{#1}% \begin{udbox}{\notedbox}\strut}% measure height {\strut\end{udbox}% \ifshownoted \sbox0{\begin{varwidth}{\dimexpr \ht\notedbox+\dp\notedbox}% measure width \passparameter \end{varwidth}}% \sbox2{\rlap{\usebox0}\raisebox{\dimexpr-\dp0-0.5\marginparsep}[0pt][0pt]{\rule{\wd0}{1pt}}}% add line below \ifodd\value{page}% \marginpar{\rotatebox{-90}{\usebox2}}% \else \marginpar{\hfill\rotatebox{90}{\usebox2}}% \fi \fi% ebd \ifshownoted \unvbox\notedbox }

\begin{document}

\lipsum[1]

\begin{noted}{This is a short note} \lipsum[1] \end{noted}

\begin{noted}{This is a longer note, Also a shorter paragraph.} \lipsum[2] \end{noted}

\newpage

\begin{noted}{This is a longer note, Also a shorter paragraph.} \lipsum[2] \end{noted}

\end{document}

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • Thanks a lot, this is great! It has an issue, though: The note on the first noted paragraph does not show if it is preceded by an ordinary paragraph (without a note); put differently, the note only renders if the paragraph starts the page or there is a noted paragraph before it. (Also, how is it possible to turn them on/off for the whole document, instead of taking paragraphs one by one out of the noted environment?) – psyguy Feb 07 '22 at 08:58
  • 1
    This should take care of it. – John Kormylo Feb 07 '22 at 14:58
  • Wonderful, thanks! Three other things, if I may add: How do you decrease the space between the comment lines when the text gets wrapped? And if I want to change the line color with an argument, how can this be done (like, if I want to color the line underneath some of the notes purple and some blue, and the rest black)? And finally, is it not possible to change the environment into a command (?), like \notefornextparagraph{Some notes next to the upcoming paragraph} such that instead of putting the paragraph inside the environment, it would attach the comment next to the upcoming paragraph? – psyguy Feb 08 '22 at 09:37
  • 1
    The idea was to measure the height of the paragraph, so you need to format the paragraph before formatting the note. – John Kormylo Feb 08 '22 at 14:52
  • I educated myself on defining environments and could add an optional parameter to the definition for color: \newenvironment{noted}[2][Periwinkle]{...}. However, I cannot use it to color the \rule command that draws the line; with \color{#1}\rule{...}{...} and \textcolor{#1}{\rule{...}{...}} I get Illegal parameter number in definition of \endnoted. and Package xcolor Error: Undefined color '##1', among other errors. Could you enlighten me? – psyguy Feb 09 '22 at 12:08
  • Environment arguments are only available in the first half. Note the use of \def\passparameter{#1} in order to pass #1 to the second half (implemented as \endnoted}. – John Kormylo Feb 09 '22 at 14:06
  • Hmmm. I'm afraid I cannot figure out how to fix it :( – psyguy Feb 09 '22 at 16:36