0

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.

wrong alignment

I would like to align the answer to the question. How do it do it?

  • Why do you use sections for that? Would it be okay for you to use enumeration? – TeXnician May 14 '17 at 14:12
  • @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 May 14 '17 at 14:13
2

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 end-of-environment 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} 

enter image description here

| improve this answer | |
  • thanks for teaching something new. I didn't know you could begin new environment while defining new environment. – Santosh Linkha May 14 '17 at 15:11
  • I 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 of titlesec). – Bernard May 14 '17 at 15:27
1

You could simply do it with an enumeration:

right alignment

\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*})}.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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