4

I have two bits of "code" that work perfectly when isolated. The first piece builds a table of marginpar, the second provides certain customizations for the marginpar environment. When I copy both in one document it produces the table of Marginpar but doesnt apply the customizations correctly.

This is the customization (it is not created by myself. Unfortunatelly, I dont remember the source):

\setlength{\marginparwidth}{1.2in} % Veränderung Marginpar
\let\oldmarginpar\marginpar
\renewcommand\marginpar[1]{\-\oldmarginpar[\raggedleft\footnotesize #1]%
{\raggedright\footnotesize #1}}

The ToM code results from a previous question (List marginpars in the/a TOC) and is provided by henrique:

\documentclass{article}
\usepackage{tocloft,blindtext}
\usepackage[english]{babel}
% First we create new list of marginpars with the help of tocloft package:
\newcommand{\listmarginparname}{List of Margin Pars}
\newlistof{marginpar}{lom}{\listmarginparname}
% Then we define a command that increments a counter and writes it in the created list
\newcommand{\mpar}[1]{%
\refstepcounter{marginpar}
\addcontentsline{lom}{marginpar}{#1}}
% Now we have to make \marginpar command to include the counting macro
\newcommand*\origmpar{}
\let\origmpar\marginpar
\renewcommand*\marginpar[1]{\origmpar{#1}\mpar{#1}}
\begin{document}
\listofmarginpar
\section{Two marginpars}
\blindtext \marginpar{First Marginpar Test}
\blindtext \marginpar{Second Marginpar Test}
\section{One marginpar}
\blindtext \marginpar{Third marginpar Test}
\end{document}

My question: Does anyone know how to get this kind of Table of Marginpar without compromising the other customizations?

Philip
  • 3,415

1 Answers1

4

This should be what you want:

\documentclass{article}
\usepackage{tocloft,blindtext}
\usepackage[english]{babel}
% First we create new list of marginpars with the help of tocloft package:
\newcommand{\listmarginparname}{List of Margin Pars}
\newlistof{marginpar}{lom}{\listmarginparname}
% Then we define a command that increments a counter and writes it in the created list
\newcommand{\mpar}[1]{%
\refstepcounter{marginpar}
\addcontentsline{lom}{marginpar}{#1}}
% Now we have to make \marginpar command to include the counting macro
% ADDED BY LOCKSTEP: And some other modifications
\setlength{\marginparwidth}{1.2in} % Veränderung Marginpar
\newcommand*{\origmpar}{}
\let\origmpar\marginpar
\renewcommand*{\marginpar}[1]{%
  \-\origmpar[\raggedleft\footnotesize #1]{\raggedright\footnotesize #1}%
  \mpar{#1}%
}
\begin{document}
\listofmarginpar
\section{Two marginpars}
\blindtext \marginpar{First Marginpar Test}
\blindtext \marginpar{Second Marginpar Test}
\section{One marginpar}
\blindtext \marginpar{Third marginpar Test}
\end{document}
lockstep
  • 250,273
  • Thank you. That works perfectly well. But still there is a little problem (for me a big one): People as me think breaking problems in smaller parts makes them easier to solve. So again, I left one part out that seemed to be a simple adjustment. It turned out otherwise. I thought I could just add \newcommand{\strang}[1]{\marginpar{\textcolor{magenta}{\small{#1}}}} and get a magenta colored marginpar. This turned out to be wrong. Do you know how to adjust this last bit? – Philip Mar 03 '12 at 19:34
  • Well, I do get a magenta \marginpar using your \strang command (though also a magenta LoM entry). Please edit your question so one can reproduce your (new) problem. If the new problem isn't really related to the one solved here, better ask a new question. – lockstep Mar 03 '12 at 19:41