Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I produce whitespace before each line of an environment. If I have the following command in the preamble

\newenvironment{myenv}
{\vspace{3mm}\hspace{0.5cm}\noindent\ignorespaces\small\texttt}
{\par\noindent\ignorespacesafterend\vspace{0.5mm}}

and in the text:

\begin{myenv}
hello \\
world
\end{myenv}

this produces whitespaces only for the first line.

share|improve this question
1  
Welcome to TeX.sx! A tip: If you indent lines by 4 spaces, as I've done it just now, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). –  Speravir Oct 27 '12 at 23:35
3  
Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. It is considered a lot better to put in some code that will compile, as it makes it a lot easier for us to copy it into our text editor and work with it, and see exactly what it is you are trying to do. –  Canageek Oct 27 '12 at 23:38
    
@Speravir and Canageek, thanks for the tips. –  narengi Oct 27 '12 at 23:46
add comment

2 Answers

up vote 4 down vote accepted

Perhaps you might be interested in using a combination of \obeylines (so you don't have to manually break the line) and \doublespacing (provided by setspace):

enter image description here

\documentclass{article}
\usepackage{lipsum,setspace}% http://ctan.org/pkg/{lipsum,setspace}
\newenvironment{myenv}
{\par\hrulefill\doublespacing\obeylines}
{\hrulefill\par\ignorespacesafterend}
\begin{document}
\lipsum[6]
\begin{myenv}
hello
world
\end{myenv}
\lipsum[6]
\end{document}

The \hrulefill is only to show the start/end of the environment myenv and most likely not needed in your application.

Although the proposed solution does not show the typewriter font, you can issue \ttfamily to achieve this (not \texttt).

share|improve this answer
add comment

Depending on the application a minor problem of Werner's solution is that if a line is longer than the texwith the continuation is not indented. Here is an alternative solution (and comparison with Werner's solution).

\documentclass{article}
\usepackage{lipsum}

\newenvironment{myenv}
  {\begin{list}{}{
    \setlength{\topsep}{3mm}
    \setlength{\leftmargin}{0.5cm}
    \small\ttfamily}
    \item[]\hrulefill\\}
  {\hrulefill\end{list}}

\newenvironment{myenvW}
  {\par\hrulefill\obeylines\small\ttfamily}
  {\hrulefill\par\ignorespacesafterend}

\begin{document}

\lipsum[6]
\begin{myenv}
  test\\
  \lipsum[6]
\end{myenv}
\lipsum[6]
\begin{myenvW}
  test
  \lipsum[6]
\end{myenvW}
\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.