3

Based on the answer of Markus Scharrer, I am using the custom lstnewenvironment to get code and Section with my environment. Since I use an environment in an environment (I know it may not be the best approach, but I have to do it like this) I am not able to set the indentation of my list..

Here's my MWE:

 \documentclass[a4paper,11pt]{article}
 \usepackage{listings}
 \usepackage{enumitem}

 \lstnewenvironment{method}[2]
     {\section{#1}\label{sec:#1}\def\MethodDescription{#2}}
     {\MethodDescription}


 \newenvironment{returnvalues}
     {Return value:
     \begin{itemize}[labelindent=\parindent, leftmargin=*, labelsep=0.5cm,itemsep=0.8pt]}
      {\end{itemize}}

  \newcommand{\returnvalue}[2] %Name, Description
     {\item #1: #2}

which I am using like this:

  \begin{document}
  \begin{method}{SaveDocument}{Description of the Method \\
  \begin{returnvalues}
  \returnvalue{True}{Saved successfully.}
  \returnvalue{False}{otherwise}
  \end{returnvalues}}
  Method Boolean SaveDocument()
  \end{method}
  \end{document}

Any idea why my list is not indented like I customized? I could change leftmargin to anything with no influence..

  • This reminds me of a bug in listings that fails to set \if@nobreak to false. – egreg Jul 2 '13 at 21:01
  • and how can I fix it? – Kathiieee Jul 3 '13 at 6:52
  • @egreg: I don't think it's related to your hint. I think the calculation of the width fails. I tried the following \fbox{\vbox{\MethodDescription}} and it looks really odd. – Marco Daniel Jul 3 '13 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.