1

I am trying to make a new environment that takes an undefined number of items and creates a list in the margin. Essentially doing the same thing as this code does:

\marginpar{\fontsize{1.5cm}{1.5cm}\selectfont 
        \begin{itemize}
            \item item1
            \item item2
            \item item3
        \end{itemize}}

I have tried this

\newenvironment{marginlist}
{\marginpar{\fontsize{1.5cm}{1.5cm}\selectfont 
    \begin{itemize}}
{   \end{itemize}}}

but latex can't parse it because of the opening { of \marginpar.

1 Answer 1

1

You can define a box to store the body of the environment (which may also be better regarding the alignment), or you can use the \NewDocumentEnvironment macro:

\documentclass{article}

\newsavebox{\tempitemizebox}
\newenvironment{marginlist}{%
    \setbox\tempitemizebox=\vbox\bgroup%
    \fontsize{1.5cm}{1.5cm}\selectfont%
    \begin{itemize}
}{%
    \end{itemize}
    \egroup%
    \marginpar{\usebox{\tempitemizebox}}%
}

\begin{document}

\begin{marginlist}
    \item item1
    \item item2
    \item item3
\end{marginlist}

\end{document}

\documentclass{article}

\NewDocumentEnvironment{marginlist}{ b }{%
    \marginpar{\fontsize{1.5cm}{1.5cm}\selectfont%
    \begin{itemize}
    #1
    \end{itemize}
    }%
}{}

\begin{document}

\begin{marginlist}
    \item item1
    \item item2
    \item item3
\end{marginlist}

\end{document}

I am not sure whether you really want the font to be that large though ...

1
  • It works thank you very much! I am using a big font because I'm making flash cards.
    – thedoctor
    Jul 30, 2022 at 11:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .