6

I am trying to define a command like \introduce{...} that among others will print its content into the margin.

I though "simple", just do \newcommand{\introduce}[1]{\marginpar{#1}#1}.

My reasoning to put #1 after the \marginpar{#1} is to start the maringpar in the line of the first word, as otherwise it looks weird with longer things that only have their last word flow over to the next line.

I however noticed that when the first words of a paragraph are highlighted this way, the marginpar aligns with the previous line.

Is there an easy way to fix this?

MWE

\documentclass[a4paper,11pt]{scrartcl}
\usepackage[utf8]{inputenc}
\newcommand{\introduce}[1]{\marginpar{#1}\emph{#1}} % too high
% \newcommand{\introduce}[1]{\emph{#1}\marginpar{#1}} % too low

\begin{document}

Bacon ipsum dolour sit amet porchetta beef turkey, bacon turducken boudin hamburger venison ball tip. Brisket pork loin bresaola short loin ground round leberkas pastrami tongue jerky cow turducken beef ribs. Pork ribeye landjaeger prosciutto pig venison tenderloin. Swine beef ribs kielbasa, porchetta tenderloin salami venison pork belly tail.

\introduce{More Bacon} ipsum dolour sit amet porchetta beef turkey, bacon turducken boudin hamburger venison ball tip. Brisket pork loin bresaola short loin ground round leberkas pastrami tongue jerky cow turducken beef ribs. Pork ribeye landjaeger prosciutto pig venison tenderloin. Swine beef ribs kielbasa, porchetta tenderloin salami venison pork belly tail.

Ipsum dolour sit amet porchetta beef turkey, bacon turducken boudin hamburger \introduce{even more Bacon} venison ball tip. Brisket pork loin bresaola short loin ground round leberkas pastrami tongue jerky cow turducken beef ribs. Pork ribeye landjaeger prosciutto pig venison tenderloin. Swine beef ribs kielbasa, porchetta tenderloin salami venison pork belly tail.

\end{document}

too high:

too high

too low:

too low

  • see my 2nd picture... it starts below the even aligning with more Bacon, but i'd like it to generally align with the first line of the highlighted words – Jörn Hees Oct 12 '17 at 13:26
  • 1
    off topic: the margin notes would look much nicer set ragged right. – barbara beeton Oct 12 '17 at 18:18
  • yupp, just didn't want to complicate the MWE – Jörn Hees Oct 12 '17 at 19:55
8

Add \leavevmode so the paragraph will be started anyhow.

\documentclass[a4paper,11pt]{scrartcl}
\usepackage[utf8]{inputenc}

\newcommand{\introduce}[1]{%
  \leavevmode % if at the start of a paragraph 
  \marginpar{#1}% the note
  \emph{#1}% the text
}

\begin{document}

Bacon ipsum dolour sit amet porchetta beef turkey, bacon turducken 
boudin hamburger venison ball tip. Brisket pork loin bresaola short 
loin ground round leberkas pastrami tongue jerky cow turducken beef 
ribs. Pork ribeye landjaeger prosciutto pig venison tenderloin. 
Swine beef ribs kielbasa, porchetta tenderloin salami venison pork 
belly tail.

\introduce{More Bacon} ipsum dolour sit amet porchetta beef turkey, 
bacon turducken boudin hamburger venison ball tip. Brisket pork loin 
bresaola short loin ground round leberkas pastrami tongue jerky cow 
turducken beef ribs. Pork ribeye landjaeger prosciutto pig venison 
tenderloin. Swine beef ribs kielbasa, porchetta tenderloin salami 
venison pork belly tail.

Ipsum dolour sit amet porchetta beef turkey, bacon turducken boudin 
hamburger \introduce{even more Bacon} venison ball tip. Brisket pork 
loin bresaola short loin ground round leberkas pastrami tongue jerky 
cow turducken beef ribs. Pork ribeye landjaeger prosciutto pig venison 
tenderloin. Swine beef ribs kielbasa, porchetta tenderloin salami 
venison pork belly tail.

\end{document}

enter image description here

  • thanks for the quick answers, but which of them to accept, both work... any downside of this compared to david's answer? – Jörn Hees Oct 12 '17 at 13:34
  • @JörnHees my analysis was not persuasive it seems:( – David Carlisle Oct 12 '17 at 14:37
  • I tried using your answer to add color to the margin text by \marginpar{\color{red}#1} with the xcolor package, and the margintext is then placed too low. Do you know what happens here and how to fix it? – Simon Dec 7 '18 at 17:20
  • @Simon The same: \leavevmode before \color – egreg Dec 7 '18 at 18:10
8
\documentclass[a4paper,11pt]{scrartcl}
\usepackage[utf8]{inputenc}

\newcommand{\introduce}[1]{\mbox{}\marginpar{#1}\emph{#1}}

\begin{document}

Bacon ipsum dolour sit amet porchetta beef turkey, bacon turducken boudin hamburger venison ball tip. Brisket pork loin bresaola short loin ground round leberkas pastrami tongue jerky cow turducken beef ribs. Pork ribeye landjaeger prosciutto pig venison tenderloin. Swine beef ribs kielbasa, porchetta tenderloin salami venison pork belly tail.

\introduce{More Bacon} ipsum dolour sit amet porchetta beef turkey, bacon turducken boudin hamburger venison ball tip. Brisket pork loin bresaola short loin ground round leberkas pastrami tongue jerky cow turducken beef ribs. Pork ribeye landjaeger prosciutto pig venison tenderloin. Swine beef ribs kielbasa, porchetta tenderloin salami venison pork belly tail.

Ipsum dolour sit amet porchetta beef turkey, bacon turducken boudin hamburger \introduce{even more Bacon} venison ball tip. Brisket pork loin bresaola short loin ground round leberkas pastrami tongue jerky cow turducken beef ribs. Pork ribeye landjaeger prosciutto pig venison tenderloin. Swine beef ribs kielbasa, porchetta tenderloin salami venison pork belly tail.

\end{document}

enter image description here

  • thanks for the quick answers, but which of them to accept, both work... any downside of this compared to egreg's answer? – Jörn Hees Oct 12 '17 at 13:34
  • 1
    mbox is a documented latex command but just works here because internally it uses \leavevmode which is the command egreg used. But whenever there is a choice between giving a tick to egreg and not doing so, not doing so is always the right choice,:-) – David Carlisle Oct 12 '17 at 13:36
  • oh-oh, no matter what i do now, i'm drawn into some battle here it seems :D good move ;) I'll however go with the answer that i think is less implicit, hope that won't cause a grudge. – Jörn Hees Oct 12 '17 at 14:30
  • This does not work for double-page layouts. With mbox, when the paragraph starts on a new line, the margin note will be placed on the wrong side of the page. Use the leavevmode solution. – Michael Schmid Jun 5 '18 at 21:45
  • @MichaelSchmid I don't see what you describe can possibly happen, are you sure you didn't use \hbox (which is \mbox without a \leavevmode – David Carlisle Jun 5 '18 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.