2

My self defined environment having a symbol at the beginning and at the end works fine for text without enumeration. When including enumerate the symbols are not there where desired. Is it possible to have the first symbol directly in front of "1." i. e. in the same line and the ending symbol in the same line as the last line of the enumeration? With \ignorespacesafterend and \unskip I did not succeed.

\documentclass{article}
\usepackage{amssymb}
\newenvironment{myenv}{$\blacktriangleright$}{\hfill$\blacktriangleleft$}

\begin{document}
There is a text.

\begin{myenv}
And an example
\end{myenv}

Here is another text.

\begin{myenv}
\begin{enumerate}
\item A
\item B
\end{enumerate}
\end{myenv}

\end{document}

enter image description here

2

Instead of nesting an enumerate environment inside a myenv environment, you could define a new list environment with enumitem, where the black triangles would be placed automatically at the beginning and at the end.

\documentclass{article}
\usepackage{amssymb}
\newenvironment{myenv}{$\blacktriangleright$}{\hfill$\blacktriangleleft$}
\usepackage{enumitem}
\newlist{myenumerate}{enumerate}{1}
\newcommand*{\placebtr}{%
    \item[]
        \hspace*{-\labelsep}%
        \hspace*{-\labelwidth}%
        $\blacktriangleright$%
    \vspace*{-\baselineskip}%
    \vspace*{-\itemsep}%
    \vspace*{-\parsep}%
}
\setlist[myenumerate]{
    label=\arabic*.,
    first=\placebtr,
    after=\hfill$\blacktriangleleft$
}
\setlength{\parindent}{0pt}

\begin{document}
There is a text.

\begin{myenv}
And an example
\end{myenv}

Here is another text.

\begin{myenumerate}
\item A
\item B
\end{myenumerate}

\end{document}
3
  • With your code I get "Package enumitem Error: first undefined." Besides this: In your screenshot the triangle in front of the enumeration is indented less than the one before "An example" – ubuntuuser Nov 14 '20 at 17:12
  • 1
    @ubuntuuser I guess the error you get from enumitem means that you have an old version of the package, if you update it everything should work fine. For the indentation, thank you for pointing it out, I had made a mistake with the lengths used. I edited my answer and both triangles are aligned correctly. – Vincent Nov 14 '20 at 17:39
  • 1
    @ubuntuuser I think I could clarify how triangles align on the left. In myenumerate, the triangle aligns directly on the left margin, but in myenv, the triangle is just placed at the start of the environment. For the triangle of myenv to align directly on the left margin as well when myenv is used at the start of a paragraph, I set \parindent to 0 in my answer. If you use a non-zero \parindent, be aware that the triangle of myenv will be indented by an amount of \parindent if it is at a start of a paragraph (unless you modify myenv or add \noindent or something like that). – Vincent Nov 14 '20 at 17:53

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.