6

I'm working on a memoir class document which happens to use interparagraph spacing rather than indented first lines, yet I'm trying to create an environment that showcases sample text - I'm calling it hangingsample - where:

  • the text is indented (like in a quote or quotation environment),
  • the text is set in typewriter font (I use \texttt for this),
  • the text is set \raggedright,
  • each paragraph uses hanging indentation (like in APA referencing), and
  • the interparagraph spacing is zero.

To illustrate:

sample effect

The only way I have managed to create this effect thus far is to do everything manually, combining the figure, minipage, and hangparas environment, the \raggedright command, and enveloping each separate paragraph in \texttt{x} and following up each paragraph with \vspace{-\parskip}:

Preceding text ...

\begin{figure}[h]
\hspace*{5mm}\begin{minipage}[h]{125mm}
\begin{hangparas}{5mm}{1}\RaggedRight
\texttt{Technic is ... LEGO.}\vspace{-\parskip}

\texttt{Technic sets are ... electric motors.}\vspace{-\parskip}

\texttt{The style of ... technic bricks.}\vspace{-\parskip}

\texttt{Lego Technic. ... wiki/Lego\_Technic}
\end{hangparas}
\end{minipage}
\end{figure}

Following text...

surely this cannot be the most economical way of doing it... I'm looking for a simple new (or renewed) environment that does all of these things.

So far, I have created the following environment:

\newenvironment{hangingsample}{%
\everypar{\hangafter=1 \setlength{\hangindent}{5mm}}\ttfamily\raggedright}
{\par%
}

Which achieves most points except the full indentation of the paragraphs.

Anyone any idea what I could do to solve this?

Most kind regards,

Cees

0

2 Answers 2

5

Define your own environment:

\documentclass{memoir}
\usepackage{lipsum}

\newenvironment{ttquote}
 {\list{}{%
    \ttfamily\raggedright
    \setlength{\itemindent}{-1em}%
    \setlength{\listparindent}{\itemindent}%
    \setlength{\rightmargin}{\leftmargin}%
    \setlength{\parsep}{0pt plus 1pt}%
  }%
  \item[]}
 {\endlist}

\nonzeroparskip
\setlength{\parindent}{0pt}

\begin{document}

\lipsum[2-3]

\begin{ttquote}
\lipsum[2]

\lipsum[3]
\end{ttquote}

\end{document}

enter image description here

2

Hope this helps. It's an adaptation of Herbert's answer to Within a single paragraph, hang a wrapped line, but do not hang new lines. Being based in a minipage, this environment won't break between pages.

\documentclass{article}
\usepackage{lipsum}
\usepackage{environ}

\NewEnviron{ttpar}{%
\begin{minipage}{.9\linewidth}
\everypar{\setlength\hangindent{1em}\ttfamily}
\BODY\end{minipage}}

\begin{document}

\lipsum[1]

\begin{ttpar}
\lipsum[1]

\lipsum[2]
\end{ttpar}

\lipsum[3]
\end{document}

enter image description here

2
  • I have a feeling @egreg's solution will work even better for me, but I will give both a try. Thanks!
    – Krottsy
    Commented Sep 29, 2016 at 4:44
  • @Krottsy No doubt! Any egreg's solution will work better than mine. He knows what he's doing. ;-)
    – Ignasi
    Commented Sep 29, 2016 at 7:47

You must log in to answer this question.

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