Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to create something similar to marginpar but without the hassle of floats (particularly because I'm going to have a lot of these).

First issue These notes always appear at the beginning of a paragraph, and I would like to be able to take into account whether the paragraph has been indented or not (such as whether it's followed a section command). I really only need to know this so I can position the note correctly in the right hand margin. I suppose there may be so tikz trick for this. If you know of one, I'd greatly appreciate your suggestions for finding the position of the right margin of the current line. I'd also be very interested in non-tikz answers too.

Second issue I want to be able to kill the extraneous whitespace after the environment. I know I can manually add % after the environment. But I'd like not to have to do this. I thought using etoolbox I could achieve this effect with the hook \AtEndEnvironment, but that's not working.

Here's a MWE

\documentclass{article}
\usepackage[driver=dvips,
            top=0.5in,bottom=0.5in,
            left=0.5in,right=3.25in,
            headsep=0.5\baselineskip, headheight=\baselineskip,
            footskip=1.5\baselineskip, 
           ]{geometry}
\pagestyle{empty}
\usepackage{xcolor}
\usepackage{etoolbox}
\usepackage{lipsum}
%%'
\newsavebox{\aemarginpar}
\newenvironment{mnote}
    {%
        \begin{lrbox}{\aemarginpar}\color{blue}%
        \begin{minipage}[t]{\dimexpr 3.25in - 2em - 0.5in\relax}%\raggedright%
    }{%
        \end{minipage}%
        \end{lrbox}%
        \rule{0pt}{0pt}%
        \hspace*{\linewidth}%
        \raisebox{0pt}[0pt][0pt]{%
            \makebox[0pt][l]{\hspace*{2em}\usebox{\aemarginpar}}%
        }%
        \hspace*{-\linewidth}%
    }
\AtEndEnvironment{mnote}{\ignorespaces}
\begin{document}

\section{Hello}

\begin{mnote}
    First margin note.  I want to kill white space at the end of the
    environment, but even with \verb=etoolbox=, I can't seem to get rid of
    the extra white space.
\end{mnote}
\lipsum[1-2]

\begin{mnote}
    My margin note is pushed too far to the left which is, of course,
    because the paragraph has been indented.
\end{mnote}
\lipsum[3-4]

\end{document}

And here's the result:

enter image description here

share|improve this question
1  
You can use the package marginnote. –  Marco Daniel May 11 '13 at 16:25

1 Answer 1

up vote 5 down vote accepted

enter image description here

Using \ignorespacesafterend to ignore spaces after \end. As requested this just adds the box as positioned, but of course it will go off the page if the paragraph is near the bottom of the page, which is why standard marginpars are designed to move.

\documentclass{article}
\usepackage[%driver=dvips,
            top=0.5in,bottom=0.5in,
            left=0.5in,right=3.25in,
            headsep=0.5\baselineskip, headheight=\baselineskip,
            footskip=1.5\baselineskip, 
           ]{geometry}
\pagestyle{empty}
\usepackage{xcolor}

\usepackage{lipsum}
%%'
\newsavebox{\aemarginpar}
\newenvironment{mnote}
    {%
        \begin{lrbox}{\aemarginpar}\color{blue}%
        \begin{minipage}[t]{\dimexpr 3.25in - 2em - 0.5in\relax}%\raggedright%
    }{%
        \end{minipage}%
        \end{lrbox}%
        \leavevmode\strut\vadjust{%
        \smash{\raise\dp\strutbox\hbox{%
                     \kern\dimexpr\textwidth+\marginparsep\relax
                     \usebox{\aemarginpar}}}}%
    \ignorespacesafterend}

\begin{document}

\section{Hello}

\begin{mnote}
    First margin note.  I want to kill white space at the end of the
    environment, but even with \verb=etoolbox=, I can't seem to get rid of
    the extra white space.
\end{mnote}
\lipsum[1-2]

\begin{mnote}
    My margin note is pushed too far to the left which is, of course,
    because the paragraph has been indented.
\end{mnote}
\lipsum[3-4]

\end{document}
share|improve this answer
    
Very nice. It works correctly even if embedded in the middle of a paragraph. I thought \textwidth was a rigid length. What is keeping track of the remaining length of the line? –  A.Ellett May 11 '13 at 16:50
    
It is the vadjust: the note is added to the space between the lines, the horizontal position of the vadjust is not recorded by TeX. –  David Carlisle May 11 '13 at 17:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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