7

I'd like the margins in the example environment in the code below to be slightly indented. What is the easiest way of achieving this? It's supposed to apply to all example environments.

In the example below, just the heading is indented, but I'd like the entire environment to be (slightly) indented from both sides.

\documentclass{amsart}

\newtheoremstyle{ugh}
{3pt}% hSpace above
{3pt}% hSpace below
{}% hBody font
{1cm}% hIndent amount
{\bfseries}% hTheorem head font
{:}% hPunctuation after theorem head
{.5em}% hSpace after theorem head
{}% hTheorem head spec (can be left empty, meaning ‘normal’)

\theoremstyle{ugh}
\newtheorem{example}{Example}
\usepackage{lipsum}


\begin{document}

\lipsum[1-2]

\begin{example}
% I want this automatically indented a bit at both sides for any example 
\lipsum[3-4] \qed
\end{example}

\lipsum[5-6]

\end{document}
3
  • I tried adjusting the margins inside the body argument of the \theoremstyle command using \newgeometry of the geometry package, which adjust the right margin, but not the left margin.
    – JPi
    Commented Mar 30, 2015 at 14:24
  • adjustwidth of changepages gets closer but doesn't indent the displayed equations.
    – JPi
    Commented Mar 30, 2015 at 14:42
  • may be you want to add this comment to the question
    – touhami
    Commented Apr 1, 2015 at 20:24

2 Answers 2

7
+100

I'd locally patch the \@thm command in the example environment. Of course you won't be able to state theorems correctly inside the environment, but I don't think you would.

\documentclass{amsart}

\usepackage{etoolbox}
\usepackage{lipsum}

\theoremstyle{definition}
\newtheorem{innerexample}{Example}

\makeatletter
\patchcmd{\endinnerexample}{\endtrivlist}{\endlist}{}{}
\newenvironment{example}
 {\patchcmd{\@thm}{\trivlist}{\list{}{\leftmargin=3em \rightmargin=3em}}{}{}%
  \innerexample\pushQED{\qed}}
 {\popQED\endinnerexample}
\makeatother

\begin{document}

\lipsum*[1]
\[
e^x=\sum_{k\ge0}\frac{x^k}{k!}
\]
\lipsum[2]

\begin{example}
\lipsum*[3]
\[
e^x=\sum_{k\ge0}\frac{x^k}{k!}
\]
\lipsum*[4]
\end{example}

\lipsum[5-6]

\end{document}

The idea is to patch \@thm to do \list instead of \trivlist, so we're able to use \leftmargin and \rightmargin. The patch happens inside the example environment, so it will disappear when the environment ends.

I also added the automatic QED at the end. Use \qedhere if the example ends with a list or a display, as usual.

enter image description here

2
  • This is great! how can I get the extra argument in the title of the Definition/Example to be taken and written in bold?
    – Kikolo
    Commented Jan 30, 2022 at 18:25
  • @Kikolo That's the default…
    – egreg
    Commented Jan 30, 2022 at 20:58
5

Here is a solution based on changemargin environment

Edit: This does not answer the question of displayed equations

\documentclass{amsart}

\newtheoremstyle{ugh}
{3pt}% hSpace above
{3pt}% hSpace below
{}% hBody font
{}% hIndent amount
{\bfseries}% hTheorem head font
{:}% hPunctuation after theorem head
{.5em}% hSpace after theorem head
{}% hTheorem head spec (can be left empty, meaning ‘normal’)

\theoremstyle{ugh}
\newtheorem{eexample}{Example}

\newenvironment{changemargin}{%
\begin{list}{}{%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{1cm}%    
\setlength{\rightmargin}{1cm}%  
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\parsep}{\parskip}%
}%
\item[]}{\end{list}}

\newenvironment{example}{%
\begin{changemargin}\vskip-\baselineskip
\begin{eexample}}{%
\end{eexample}\end{changemargin}}
\usepackage{lipsum}


\begin{document}

\lipsum[1-2]

\begin{example}
% I want this automatically indented a bit at both sides for any example 
\lipsum[3-4] \qed
\end{example}

\lipsum[5-6]

\end{document}

If

\documentclass{amsart}

replaced by

\documentclass[leqno]{article}
\usepackage{amsmath,amsthm}

it will be correct.

Edit: Complete solution with amsart This not the proper way but it does the job

\documentclass{amsart}

\newtheoremstyle{ugh}
{3pt}% hSpace above
{3pt}% hSpace below
{}% hBody font
{}% hIndent amount
{\bfseries}% hTheorem head font
{:}% hPunctuation after theorem head
{.5em}% hSpace after theorem head
{}% hTheorem head spec (can be left empty, meaning ‘normal’)

\theoremstyle{ugh}
\newtheorem{eexample}{Example}

\newenvironment{changemargin}{%
\begin{list}{}{%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{1cm}%    
\setlength{\rightmargin}{1cm}%  
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\parsep}{\parskip}%
}%
\item[]%
}{\end{list}}

\newenvironment{example}{%
\begin{changemargin}%
\eeq\vskip-\baselineskip%
\begin{eexample}}{%
\end{eexample}\end{changemargin}}
\usepackage{lipsum}

\makeatletter\def\eeq{%                                     this may be bad idea
\def\maketag@@@##1{\makebox[1.5cm][r]{\m@th\normalfont##1}}}
\makeatother

\begin{document}


\lipsum[1-2]

\begin{example}
% I want this automatically indented a bit at both sides for any example 
\lipsum[3-4]

\begin{equation}
    x+y
\end{equation}
\qed
\end{example}

\lipsum[5-6]

\end{document}
1
  • Well, I don't think it's good. You're welcome.
    – touhami
    Commented Apr 2, 2015 at 7:22

You must log in to answer this question.

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