# Too much vertical space before \part when using \marginpar

When I use a \marginpar{...} before \part{...} on a new page, I get a big space on the top of that page. Below is a screenshot, where the left one was typeset with marginpar, the right one without:

Code:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{lipsum}
%\usepackage{marginnote}
\begin{document}

% too much space before part:
\marginpar{Lorem\\Ipsum}
\part{Lorem Ipsum Dolor}
\lipsum[5]
\pagebreak

% without marginpar
\part{Lorem Ipsum Dolor}
\lipsum[5]
\pagebreak

% marginpar after part (not possible for me):
% everythink ok, no vertical spacing
\part{Lorem Ipsum Dolor}
\marginpar{Lorem\\Ipsum}
\lipsum[5]

\end{document}


I have the same problems with the marginnote-package.

If I put the \marginpar after the \part-command, everything works fine – but this is not possible for me. (I \input/\include the parts and the marginpars show the filename and some information for that file.)

Is it possible to remove all the space above a \part?

I need this for lecture notes. I have one main file lecture.tex which inputs every lecture from a separate .tex-file (2013-05-08.tex, 2013-05-10.tex etc). Before every \input, I want to display the date ( = the filename) and the number of the lecture ( = a counter) using \marginpar. Everything works as expected, but when the external file begins with a \part (a new chapter in the lecture), I get this supplementary space. Not every lecture begins with a new chapter. I wanted to keep my question as general as possible, that's because I haven't written this before.

-

For aligning the marginpar to "Part I", do like this:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{lipsum}

\let\origpartname\partname
\newcommand{\partmargin}[2]{%
% #1 = part title
% #2 = margin par
\expandafter\def\expandafter\partname\expandafter{\partname
\marginpar{#2}}%
\part{#1}
\let\partname\origpartname
}

\begin{document}

\partmargin{Lorem Ipsum Dolor}{Lorem\\Ipsum}
\lipsum[5]

\end{document}


Thanks to David Carlisle for having spotted a weakness.

A simple solution for your more complex problem can be as follows. I use filecontents to provide two mock lecture files. So long as your files begin with plain text and not lists such as enumerate, this should work.

\begin{filecontents}{2013-05-08.tex}
\part{Start}

\section{Something}
This is the first lecture
\end{filecontents}

\begin{filecontents}{2013-05-09.tex}
\section{What's here?}

This is the second lecture.
\end{filecontents}

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{lipsum}

\newcounter{lecturecount}
\newcommand{\lectureinput}[1]{%
\stepcounter{lecturecount}%
\everypar={\marginpar{#1\\Lecture \thelecturecount}\everypar={}}%
\input{#1}\par
}

\begin{document}

\lectureinput{2013-05-08}
\lectureinput{2013-05-09}

\end{document}


-
I think you want this to avoid putting the heading in a group (note the indentation) \newcommand{\partmargin}[2]{% % #1 = part title % #2 = margin par \let\oldpartname\parname \expandafter\def\expandafter\partname\expandafter{\partname \marginpar{#2}}% \part{#1}% \let\partname\oldparname } – David Carlisle May 8 '13 at 22:35
Although this works perfectly, it is not suitable for my setup: I input many external files and not every one is starting with a \part, but each one gets a \marginpar. – ralfix May 10 '13 at 12:40
@ralfix You should make it clear in your question. It's impossible to answer questions you don't make. – egreg May 10 '13 at 12:43
You are absolutely right. I wanted to keep my question as general as possible. I'm sorry for your effort, but I learned a lot, and would like to thank you for that. – ralfix May 10 '13 at 16:08
Thank you, your edit is what I was looking for. However, if the external file begins with a \paragraph, the marginpars are not shown? – ralfix May 13 '13 at 18:55