3

I have a book where a custom command calls the \marginpar command routinely. The trouble is that sometimes it is called fairly low on a page, and then the marginal paragraph dips into and even below the footnotes. Given the length of the document and the other code involved with the custom command, hard-coding each \marginpar call so that it is in the correct place on the page manually is simply not feasible. I have searched for any way to force the note higher on the page, to no avail. I know there is the marginnote package, but since its provided \marginnote command does not even float, it seems even less equipped to handle this scenario. Here is my MWE:

\documentclass{book} \newcounter{factctr} \newcommand{\fact}[1]{\stepcounter{factctr}\marginpar{{\centering FACT \arabic{factctr} } \textit{#1}}} \begin{document} \chapter{First Chapter} Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Nunc congue nisi vitae suscipit tellus mauris a. Convallis tellus id interdum velit laoreet. Tempor commodo ullamcorper a lacus vestibulum. Massa massa ultricies mi quis hendrerit. Velit scelerisque in dictum non consectetur a erat nam at. Consequat semper viverra nam libero justo laoreet sit amet cursus. Ut ornare lectus sit amet est. Porta nibh venenatis cras sed felis eget velit aliquet. Imperdiet dui accumsan sit amet nulla facilisi morbi. Enim blandit volutpat maecenas volutpat blandit aliquam. Ac tortor dignissim convallis aenean et tortor at. Consequat interdum varius sit amet. Aliquet eget sit amet tellus. Nascetur ridiculus mus mauris vitae ultricies leo integer. Sit amet porttitor eget dolor morbi non arcu risus quis. Gravida arcu ac tortor dignissim convallis aenean et tortor. Faucibus ornare suspendisse sed nisi lacus sed. In iaculis nunc sed augue lacus viverra vitae congue eu. Amet cursus sit amet dictum sit. Adipiscing vitae proin sagittis nisl. Tincidunt ornare massa eget egestas. Pretium lectus quam id leo in vitae turpis massa. Elementum eu facilisis sed odio. Diam in arcu cursus euismod quis viverra nibh cras pulvinar. Vehicula ipsum a arcu cursus vitae congue. Tellus id interdum velit laoreet id. Id diam vel quam elementum. Viverra tellus in hac habitasse platea dictumst vestibulum rhoncus. Ut etiam sit amet nisl purus in mollis nunc sed. Aliquam sem fringilla ut morbi tincidunt. Tellus orci ac auctor augue. Etiam non quam lacus suspendisse faucibus. Odio euismod lacinia at quis risus. Est pellentesque elit ullamcorper dignissim cras tincidunt lobortis. Duis ultricies lacus sed turpis tincidunt. Habitasse platea dictumst vestibulum rhoncus. Massa sapien faucibus et molestie ac feugiat sed lectus vestibulum. Integer vitae justo eget magna fermentum iaculis. Enim diam vulputate ut pharetra sit amet aliquam. Tristique nulla aliquet enim tortor at. Tellus at urna condimentum mattis. Pretium quam vulputate dignissim suspendisse in. Accumsan in nisl nisi scelerisque eu ultrices vitae auctor eu. Eget velit aliquet sagittis id consectetur purus. Egestas quis ipsum suspendisse\fact{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.} ultrices gravida dictum fusce ut. Commodo nulla facilisi nullam vehicula ipsum a arcu cursus vitae. Eu sem integer vitae justo eget magna fermentum iaculis. Nec ullamcorper sit amet risus nullam eget felis. Ut faucibus pulvinar elementum integer enim. Arcu dui vivamus arcu felis bibendum ut tristique et. Dolor morbi non arcu risus. Placerat\fact{Tristique risus nec feugiat in fermentum.} in egestas erat imperdiet sed euismod nisi. Mollis aliquam ut porttitor leo a. Non consectetur a erat nam at lectus urna duis convallis. Rhoncus est pellentesque elit ullamcorper dignissim. A cras semper auctor neque vitae tempus quam. Etiam dignissim diam quis enim lobortis scelerisque fermentum dui. Magna eget est lorem ipsum. Feugiat pretium nibh ipsum consequat. Eget gravida cum sociis natoque penatibus et magnis. Tincidunt tortor aliquam nulla facilisi cras. Turpis egestas sed tempus urna et pharetra. Aliquam id diam maecenas ultricies mi eget mauris pharetra et. Aenean\fact{Lectus vestibulum mattis ullamcorper velit sed ullamcorper morbi tincidunt.} sed adipiscing diam donec adipiscing tristique. Suspendisse faucibus interdum posuere lorem ipsum dolor. Enim ut sem viverra aliquet eget sit amet tellus. Venenatis urna cursus eget nunc scelerisque viverra mauris in. Consectetur adipiscing elit duis tristique. Condimentum mattis pellentesque id nibh tortor id. Ut placerat orci nulla pellentesque dignissim enim sit. \end{document} 

The goal here would be for the bottom of the "FACT 1" note to align with the bottom of the text. If there were footnotes (which there will be on every page of my actual document, but I did not view them as strictly necessary for the MWE), then it would need to be fully above the footnotes.

EDIT

The "FACT 2" and "FACT 3" notes would remain untouched ideally, since they are nowhere near the bottom.

4
  • 1
    While the focus of this answer, tex.stackexchange.com/questions/101553/…, is on left/right marginpars, it does also provide ability to shift them up and down. However, the shift is not automatic, but specified. Commented Mar 24, 2021 at 9:16
  • There is also the marginfix package that provides \marginheightadjustment=<length>. You could use this to generally adjust the height of the marginpar area, but it would be the same on every page then and not really take into account the height of the footnotes block (which you may want to achieve, if I read this question in the context of your previous one). Commented Mar 24, 2021 at 10:42
  • So I suppose, ultimately, the question is, is there a way to determine the position of the lower edge of the margin note and compare it with the position of the top of the footnote block, or better, the footnote rule? Commented Mar 24, 2021 at 16:23
  • I wonder if my only option is to add an argument to the \fact command that would default to 0pt, that utilizes @StevenB.Segletes suggestion. Then I could manually raise those marginpars that extend too low at the time of calling \fact... Commented Mar 24, 2021 at 17:17

1 Answer 1

1

Using the information from this answer and this answer, I modified my custom command as follows:

\newcommand{\fact}[2][0]{\stepcounter{factctr}\marginpar{\vspace{\dimexpr(-6pt-#1\baselineskip)}{\centering FACT \arabic{factctr} } \textit{#2}}} 

Then when I call \fact, I can add [4], for example, before the text argument, to raise the note 4 lines. Using this method, I have to look at how many lines after the main text the margin note extends and add that to the call.

The -6pt seems to be necessary to offset a vertical shift caused by the \vspace call, and while it is a close approximation, it seems that the actual value needed varies from page to page, which leads me to believe there is a command I should be using instead.

Another problem is that if there is another \fact call too soon before, they overlap, which means I have to add the optional argument to that call as well. I do not love this solution; it feels really hacky to me, but it gets the job done. If anyone has a solution where this behavior is built into the command and does not have to be specified at the time of calling, I would definitely appreciate it.

EDIT

The problem is not with the -6pt, but rather with the \baselineskip, which is of course only the maximum distance between lines. The \raggedbottom command, suggested by Steven will make this work more precisely, but, as might be expected, that gets rid of that nice uniform look to pages that, for me, is one of the principle reasons for using LaTeX, in the first place.

1
  • The page to page variation is likely due to vertical glue between the page elements. If you employ \raggedbottom, the problem may go away and provide standard shifts that don't vary page to page. Commented Mar 24, 2021 at 22:27

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.