Text FormattingIndentation inside a new Environment

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Willie
Posts: 42
Joined: Sat Aug 27, 2011 3:43 am

Indentation inside a new Environment

Post by Willie »

I want to use indentation in a new environment I created. However, I do want to enable page breaking inside the environment, so the the \minipage environment is not suitable choice for me.
How should I define the indentation?
I tried

Code: Select all

\addtolength{\textwidth}{-5cm}%
and also

Code: Select all

\addtolength{\parindent}{5cm}
but this seems to have no effect. What should I use?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Indentation inside a new Environment

Post by localghost »

Why don't you just show us what you did to define this new environment? Or is this top secret? At the moment nobody knows which structure this environment has or whereon it is based. So specific help will be very difficult if you don't give useful information.


Thorsten
Willie
Posts: 42
Joined: Sat Aug 27, 2011 3:43 am

Indentation inside a new Environment

Post by Willie »

Code: Select all

\documentclass[a4paper,10pt,english]{article}
\usepackage{babel}
\usepackage{blindtext}

\newenvironment{myEnv}{\addtolength{\parindent}{5cm}}{}

\begin{document}
	\blindtext
	
	\vspace{2ex}
	Here is the new environment, with left margin the same as regular text:
	\vspace{2ex}
	
	\begin{myEnv}
		\noindent\blindtext
	\end{myEnv}
	\vspace{2ex}
	
	\noindent Here is what I want to achieve with my new environment.
	The following text is all indented:
	
	\vspace{2ex}
	\begin{minipage}{\dimexpr\textwidth-\parindent}
		\blindtext
	\end{minipage}
\end{document}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Indentation inside a new Environment

Post by localghost »

You can try the below code to indent a complete paragraph without defining a new environment.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{blindtext}

\parindent0em

\begin{document}
  \hangindent2em
  \hangafter=0
  \blindtext

  \medskip
  \blindtext
\end{document}
If you want to indent longer passages of text with several paragraphs, you should think about an environment that is based on a list environment with customized settings.
Willie
Posts: 42
Joined: Sat Aug 27, 2011 3:43 am

Re: Indentation inside a new Environment

Post by Willie »

Thanks, but I do want the indentation inside the environment. The environment was not created solely for this purpose, but I want the presented text to be indented. Is there a simple command to achieve that in the environment definitions? And how do I base my environment on a list if I want to? (btw. and I don't want this environment to be a list, i.e. to specify items with \item, as it has nothing to do with \items)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Indentation inside a new Environment

Post by localghost »

Willie wrote:[…] The environment was not created solely for this purpose, but I want the presented text to be indented. […]
So please tell us for what purposes the environment is created. What is it for? What will it do? At the moment you only want indentation. For this single purpose you don't need a new environment. Just list all desired properties of your environment and we will see how we can implement them.
Willie
Posts: 42
Joined: Sat Aug 27, 2011 3:43 am

Indentation inside a new Environment

Post by Willie »

localghost wrote:
Willie wrote:[…] The environment was not created solely for this purpose, but I want the presented text to be indented. […]
So please tell us for what purposes the environment is created. What is it for? What will it do? At the moment you only want indentation. For this single purpose you don't need a new environment. Just list all desired properties of your environment and we will see how we can implement them.
The purpose is not relevant for the answer, however the purpose is: an enviroments for writing "examples". I want it to behave just like minipages with respect to indentation, as in my code above, with the only difference it could be page-broken.

By the way, I tried to use parbox, which should be by my understanding the same as minipage but page-breakable. But that dosn't yield indentation either.

Code: Select all

\newenvironment{myEnv}{\begin{parbox}{0.7\textwidth}}{\end{parbox}}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Indentation inside a new Environment

Post by Stefan Kottwitz »

You could change \leftskip in that environment, such as here, where you can see indentation across a page break:

Code: Select all

\documentclass[a4paper,10pt]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\parindent0em
\parskip\baselineskip
\begin{document}
\blindtext[3]
\par
\begingroup
\leftskip4em
\rightskip\leftskip
\blindtext[3]
\par
\endgroup
\blindtext
\end{document}
Source: Changing margins for just one paragraph.

Stefan
LaTeX.org admin
Willie
Posts: 42
Joined: Sat Aug 27, 2011 3:43 am

Indentation inside a new Environment

Post by Willie »

Stefan_K wrote:You could change \leftskip in that environment, such as here, where you can see indentation across a page break:

Code: Select all

\documentclass[a4paper,10pt]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\parindent0em
\parskip\baselineskip
\begin{document}
\blindtext[3]
\par
\begingroup
\leftskip4em
\rightskip\leftskip
\blindtext[3]
\par
\endgroup
\blindtext
\end{document}
Source: Changing margins for just one paragraph.

Stefan
This DOES seem to be what I want. However I can't get it to work when defined inside my new environment. for example:

Code: Select all

\newenvironment{myEnv}{\leftskip4em \rightskip\leftskip}{}
Also, is there a way to make it work with a \parbox?
For example, the following definition:

Code: Select all

\newenvironment{myEnv}{\begin{parbox}{0.5\linewidth}}{\end{parbox}}
results with a right indentation, and I am looking for a left one
Willie
Posts: 42
Joined: Sat Aug 27, 2011 3:43 am

Re: Indentation inside a new Environment

Post by Willie »

I have also posted this in tex.stackexchange, for further results and discussion of this.
http://tex.stackexchange.com/questions/ ... nvironment
Post Reply