4

I think this is more an issue of my not understand Tex's syntax than anything else. I want to format my paragraphs as shown below. There seems to be a way of combining the three commands I'm using into a single statement but I can't quite work it out. Grateful for any help anyone can offer...(though maybe I shouldn't be using {hangparas} in the first place; I don't know)

\documentclass{article}

\usepackage{lipsum} % http://ctan.org/pkg/lipsum
\usepackage[english]{babel}
\usepackage{hanging}

\begin{document}

\lipsum[1]

\begin{hangparas}{0.5cm}{1}
\setlength{\leftskip}{2cm}
\setlength{\rightskip}{2cm}

\lipsum[2]

\setlength{\rightskip}{0cm}
\setlength{\leftskip}{0cm}
\end{hangparas}

\lipsum[3]

\end{document}

James.

3 Answers 3

7

Use a list, it's easier. I left your original code for comparison.

Before the code, some explanations. In LaTeX almost all the specially formatted parts of text are obtained by means of a list: center, quote, quotation are all implemented as lists. This allows nesting lists in those special places, which hanging wouldn't allow, because lists use \parshape that overrides any value given to \hangindent.

All those special environments are “one item” lists. Any list must have an \item command at the start. The basic list environment doesn't define a label for the item, so we can just issue \item\relax and nothing would be printed, but LaTeX will be in the suitable state, respecting the given values to \leftmargin, \rightmargin and the other parameters. Why \item\relax and not \item only? Because \item looks for a possible optional argument; \item[] would be equivalent, but \item\relax is slightly more efficient.

Final note: it's better to use \list and \endlist rather than \begin{list} and \end{list}; in this way an error message about wrong closure (say you mistype \end{beion}) would refer to a not closed bejon environment rather than list.

\documentclass{article}

\usepackage{lipsum} % http://ctan.org/pkg/lipsum
\usepackage[english]{babel}
\usepackage{hanging} % remove this, it's just to show the output

\newenvironment{bejon}
  {\list{}{
     \itemindent=-.5cm
     \leftmargin=2.5cm
     \rightmargin=2cm
     \topsep=0pt
     \partopsep=0pt
   }\item\relax}
  {\endlist}

\begin{document}

\lipsum[2]

\begin{hangparas}{0.5cm}{1}
\setlength{\leftskip}{2cm}
\setlength{\rightskip}{2cm}
\lipsum[2]
\setlength{\rightskip}{0cm}
\setlength{\leftskip}{0cm}
\end{hangparas}

\lipsum[2]

\begin{bejon}
\lipsum[2]
\end{bejon}

\lipsum[3]

\end{document}

enter image description here

Possibly easier with enumitem:

\documentclass{article}

\usepackage{lipsum} % http://ctan.org/pkg/lipsum
\usepackage[english]{babel}
\usepackage{enumitem}

\newenvironment{bejon}
  {\itemize[
     label={},
     itemindent=-.5cm,
     leftmargin=2.5cm,
     rightmargin=2cm,
     nosep]
   \item\relax}
  {\enditemize}

\begin{document}

\lipsum[2]

\begin{bejon}
\lipsum[2]
\end{bejon}

\lipsum[3]

\end{document}

enter image description here

4
  • In enumitem style, use \newlist{bejon}{itemize}{1} \setlist[bejon]{label={}, itemindent=-.5cm, leftmargin=2.5cm, rightmargin=2cm, nosep, before={\item\relax}} instead of \newenvironment{bejon}... Jan 4, 2015 at 20:47
  • @karlkoeller I don't find it much easier, but it's a good suggestion.
    – egreg
    Jan 4, 2015 at 20:54
  • That looks perfect; thanks a bunch. A quick question if you have a second though: would you mind talking me through what's actually going on here? Within the environment, you're defining a "list"? And everything you list in it gets triggered when you begin the environment? The \relax then does what exactly? just switches it off when you close the environment? Jan 4, 2015 at 20:54
  • @JamesBejon I added some explanations.
    – egreg
    Jan 4, 2015 at 21:09
0

The above responses were really helpful--so thanks. But it turns out that what I thought I wanted wasn't what I wanted really after all. What I'm after is something which causes each new line within a block of text to begin at a fixed left margin but to wrap around in an indented fashion. Hopefully the example below makes this clear?

\documentclass{article}

\usepackage{lipsum} % http://ctan.org/pkg/lipsum
\usepackage{blindtext}
\usepackage[english]{babel}
\setlength{\parskip}{1em}

\newenvironment{bejon}
  {\list{}{
     \itemindent=-.5cm
     \leftmargin=2.5cm
     \rightmargin=2cm
     \topsep=0pt
     \partopsep=0pt
   }\item\relax}
  {\endlist}

\begin{document}

\begin{bejon}
Here's a line which I want to be wrapped onto the next line but be indented in the same way that poems often are.  This works fine.
\end{bejon}
\begin{bejon}
Here's the next line.  Its left positioning is nice, but I don't like the way it skips a line
\end{bejon}
\begin{bejon}
The gaps between lines are too big.
\end{bejon}

\blindtext

\begin{bejon}
Here's an alternative \\
I like the way the next starts without a gap, but I don't want it indented. \\
\end{bejon}



\end{document}
-1

Regarding the line gaps you mentioned, removing \setlength{\parskip}{1em} or just setting a new length before the section removes the gaps.

You must log in to answer this question.

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