1

Given the quite long MWE:

\documentclass{memoir}
\usepackage[dvipsnames,table]{xcolor}
%\usepackage[showframe]{geometry}
\usepackage{mathtools}
\usepackage{needspace}
\usepackage{multido}
\usepackage{multicol}
\usepackage[thmmarks, amsmath]{ntheorem}
\usepackage{thmtools}
\usepackage{listings}

\nonzeroparskip             % Create space between paragraphs
\setlength{\parindent}{0pt} % Remove paragraph indentation
\setlength\columnsep{0pt}   % for multicol: still too much space in between

% From here:
% https://tex.stackexchange.com/questions/24101/theorem-decorations-that-stay-with-theorem-environment
\newcommand{\theoremhang}{% top theorem decoration
  \begingroup%
    \setlength{\unitlength}{.005\linewidth}% \linewidth/200
    \begin{picture}(0,0)(1.5,0)%
      \linethickness{0.45pt} \color{Black}%
      \put(-3,2){\line(1,0){206}}% Top line
      \multido{\iA=2+-1,\iB=50+-10}{5}{% Top hangs
        \color{black!\iB}%
        \put(-3,\iA){\line(0,-1){1}}% Top left hang
        \put(203,\iA){\line(0,-1){1}}% Top right hang
      }%
    \end{picture}%
  \endgroup%
}%

\newcommand{\theoremhung}{% bottom theorem decoration
  \begingroup%
    \setlength{\unitlength}{.005\linewidth}% \linewidth/200
    \begin{picture}(0,0)(1.5,0)%
      \linethickness{0.45pt} \color{Black}%
      \put(-3,0){\line(1,0){206}}% Bottom line
      \multido{\iA=0+1,\iB=50+-10}{5}{% Bottom hangs
        \color{black!\iB}%
        \put(-3,\iA){\line(0,1){1}}% Bottom left hang
        \put(203,\iA){\line(0,1){1}}% Bottom right hang
      }%
    \end{picture}%
  \endgroup%
}%

\newcommand{\theoremspace}{\needspace{2\baselineskip}}
\newcommand{\theoremspuce}{\nopagebreak\noindent}

\theoremstyle{plain}
\theoremsymbol{}%
\theoremprework{\theoremspace\theoremhang\vspace*{-1.3ex}}%
\theorempostwork{\theoremspuce\theoremhung}%
\theoremheaderfont{\upshape\bfseries}
\theoremseparator{.}
\theorembodyfont{\upshape}
\newtheorem{theorem}{Theorem}




\lstnewenvironment{code}[1][]%
{%
\noindent%
\minipage{\linewidth}%
\theoremspace%
\theoremhang%
\lstset{#1}}%
{\theoremhung\endminipage}

\begin{document}

Code Env:

\begin{code}
Test. Test. Test. Test. Test. Test.
\end{code}

Theorem Env:

\begin{theorem}
Test. Test. Test. Test. Test. Test.
\end{theorem}

Multicol Code Env:

\begin{multicols}{2}
\begin{itemize}
\item[]
\begin{code}
left
\end{code}
\item[]
\begin{code}
right
\end{code}
\end{itemize}
\end{multicols}

\end{document}

I get:

rendered output

Where I have two problems:

  1. The hang/hung bars do not have the same distance to text (In particular the space from end of theorem+listings to the hung below is too large. But there are also other problems: for example "Theorem Env:" to hung above)
  2. The multicol environment is not left aligned (may be caused by itemize which is needed to have the listings side-by-side)

I tried a lot with vspace hackery, but for at least at one of the places a problem persisted ;(

And is it possible to have the multicols/itemize in a self-defined environment to have everything more compact?

best regards, Markus

  • 2
    i believe that the multicol environment is left aligned, but the indentation of the code environment is a consequence of the fact that it's within an itemize environment. even though the \item label is absent. space is left for it at the beginning of the line.. – barbara beeton Sep 18 '17 at 0:48
  • Thank you, yes I think so too. How can I avoid the itemize to indent? Most problems are in the vertical spacing. (For example, Theorem to hung is too close). Btw. the itemize is necessary so that the code blocks are side-by-side. – markus23 Sep 18 '17 at 9:57
  • the only straightforward way i can think of to avoid the item indent is to get out of itemize. one of the list-enhancement packages, i've forgotten which, has a "resule" facility that allows one to continue numbering in an enumerate environment, but you wouldn't even need that with itemize since there's nothing you need to keep track of. just exit from itemize and go back in after the code block. – barbara beeton Sep 18 '17 at 12:29
  • Do you mean that I just put \begin{itemize}\item[]\end{itemize} within the two code envs? Or is there a way to define column breaks in multicol without any itemize? – markus23 Sep 18 '17 at 12:49
  • 1
    there is a command \columnbreak that you can use to break after the code on the left. maybe even \par would work. – barbara beeton Sep 18 '17 at 12:55
0

A partial solution is to have vspace within

\theorempostwork{\vspace{-1em}\theoremspuce\theoremhung}

Initially I tried to add the vspace to theoremspuce, where it did not work.

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.