change margin in newenvironment
1,379
Solution 1
Nesting in an adjustwidth
environment, from changepage
leads to a solution. Another solution consists in using ntheorem
to define a \theoremindent
. If you want an endofenvironment symbol, it can place it automatically:
\documentclass[12pt]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{amsmath, amssymb}
\usepackage{enumitem}
\usepackage{titlesec, changepage, lipsum}
\usepackage[thmmarks, amsmath]{ntheorem}
\theoremstyle{nonumberplain}
\theoremindent = 2.05em
\theoremheaderfont{\itshape}
\theorembodyfont{\normalfont}
\theoremseparator{\upshape\ :\ }
\theoremsymbol{\ensuremath{\diamondsuit}}
\newtheorem{varans}{Ans.}
\titleformat*{\section}{\normalsize}
\titlelabel{\bfseries \thetitle.\quad }
\newenvironment{ans}[1][Ans]
{\begin{adjustwidth}{2.05em}{} \hangafter =1\par
{ \itshape #1\ }:\ }{\end{adjustwidth}\medskip}
\title{Title}
\author{SL}
\begin{document}
\maketitle
\section{Prove that a finite subgroup ....}
\begin{ans} Let $F$ be a field and $G $ ... \lipsum[11]
\end{ans}
\lipsum[1]
\section{Prove that a finite subgroup ....}
\begin{varans} Let $F$ be a field and $G $ ... Blah blah blah.
\end{varans}
\lipsum[2]
\end{document}
Solution 2
You could simply do it with an enumeration:
\documentclass[12pt]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{amsmath,amsthm,amssymb}
\usepackage{enumitem}
\newenvironment{ans}[1][Ans]
{
\\ { \it #1\ }:\
}
\begin{document}
\title{Title}
\author{SL}
\maketitle
\begin{enumerate}
\item Prove that a finite subgroup ....
\begin{ans}
Let $F$ be a field and $G$ ...
\end{ans}
\end{enumerate}
\end{document}
Update: To have bold enumeration labels use package enumitem
and \setlist[enumerate]{label=\textbf{\arabic*})}
.
Related videos on Youtube
Author by
Santosh Linkha
Updated on May 15, 2020Comments

Santosh Linkha over 3 years
I have a new environment defined as
\documentclass[12pt]{article} \usepackage[margin=0.5in]{geometry} \usepackage{amsmath,amsthm,amssymb} \usepackage{enumitem} \usepackage{titlesec} \titleformat*{\section}{\normalsize} \titlelabel{\bfseries \thetitle.\quad } \newenvironment{ans}[1][Ans] { { \it #1\ }:\ } \begin{document} \title{Title} \author{SL} \maketitle \section{Prove that a finite subgroup ....} \begin{ans} Let $F$ be a field and $G ... \end{ans} \end{document}
It produces answer that does not align with the question as follows.
I would like to align the answer to the question. How do it do it?

TeXnician over 6 yearsWhy do you use sections for that? Would it be okay for you to use enumeration?

Santosh Linkha over 6 years@TeXnician yes I used enumeration in my previous assignment. I thought it was a hassle since I would have inner enumeration inside enumeration


Santosh Linkha over 6 yearsthanks for teaching something new. I didn't know you could begin new environment while defining new environment.

Bernard over 6 yearsI believe the fully correct syntax would be to use the lower level pair
\adjustwidth … \endadjustwidth
, but here the highest level works. Note the alignment will be problematic if the section numbers have more than one digit (unless you put the section numbers in the margin, with the advanced interface oftitlesec
).