Page Layoutntheorem hanging indentation

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
smr01cmh
Posts: 14
Joined: Thu May 13, 2010 1:23 am

ntheorem hanging indentation

Post by smr01cmh »

Hi all,
I am currently using the ntheorem package to create some theorems. I would like the text of the theorem to have a hanging indent (see attached picture).

I have tried using a newtheoremstyle, but haven't succeeded yet. A MWE is below- any help would be greatly appreciated.

Code: Select all

\documentclass[10pt,letter]{report}
\usepackage{ntheorem}

% hanging theorem
\makeatletter
\newtheoremstyle{hanging}%
{\item[\hskip\labelsep \theorem@headerfont ##1\ ##2\theorem@separator]\mbox{}\hangindent4cm\hangafter=0}%
{\item[\theorem@headerfont \hskip\labelsep\relax ##3]}
\makeatother

% make the theorem
\theoremstyle{hanging}
\newtheorem{subproblem}{Problem}

\begin{document}
\begin{subproblem}
Find the domain of the function
\[
    f(x)=\frac{2}{x-2}
\]
State your answer in interval notation.
\end{subproblem}

\end{document}
Attachments
Screenshot.png
Screenshot.png (11.97 KiB) Viewed 4965 times
Last edited by smr01cmh on Fri Feb 18, 2011 8:47 pm, edited 1 time in total.

Recommended reading 2024:

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

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

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

ntheorem hanging indentation

Post by frabjous »

In "22.1.1" what are the "22" and "1"? The chapter and section? That's what I'll assume.

Anyway, I can think of many different ways of accomplishing this. If I were going to stick with ntheorem commands, wouldn't using the margin style along with positive indentation (and empty label) be the same more or less as a hanging paragraph:

Code: Select all

\documentclass[10pt,letter]{report}
\usepackage{amsmath}
\usepackage{ntheorem}
\usepackage{lipsum}% for auto-generating paragraphs

\theoremstyle{margin}
\theoremindent3em
\theoremseparator{\negthickspace\negthinspace}
\theorembodyfont{}
\newtheorem{subproblem}{}[section]

\begin{document}
\chapter{This chapter}
\section{This section}

\lipsum[1]% paragraph above for comparison
\begin{subproblem}
Find the domain of the function (and we're making this long so we can see what happens with the next line)
\[
    f(x)=\frac{2}{x-2}
\]
State your answer in interval notation.
\end{subproblem}
\lipsum[3]% paragraph below for comparison
\end{document}

However, it isn't clear to me that you really ought to be doing this at all with a theorem environment, as opposed to something like an enumerate-like environment (tweaked with enumitem, etc.) or similar. I can think of some other ways to accomplish it too, using, e.g., a custom defined environment with the hanging package, or just a mbox and a parbox.

I guess my actual strategy would vary on details. E.g., how far does it hang? Does it depend on the width of the label? Or is it a constant amount for every instance? Do subsequent lines of text always line up with where the first one started after the label? Is the label right aligned or left aligned, and is its start flush with the usual start of text, etc.?

Sorry but I'm ethically bound not to help you with making it use the comic sans font. That's just wrong.
smr01cmh
Posts: 14
Joined: Thu May 13, 2010 1:23 am

Re: ntheorem hanging indentation

Post by smr01cmh »

Thank you *so* much for your reply. I completely agree with you about the comic sans font; it was the first thing I could think of to show what I wanted- it felt wrong, major apols.

I really like your approach, and thanks for providing so many different alternatives. To answer some of your questions...

> how far does it hang?
> Does it depend on the width of the label?

Yes, I suppose it does; I want the label to be in line with the main body of text (exactly as in your document)

> Do subsequent lines of text always line up with where the first one started after the label? Is the label right aligned or left aligned, and is its start flush with the usual start of text, etc.?

Left aligned.

The reason I am currently using a theorem for this is that there will be lots of these environments, and (so far) I find it easiest to tweak, label, and reference the enumeration when using theorems. I will certainly consider the other options you provided.

Again, thank you!
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

ntheorem hanging indentation

Post by frabjous »

Here's another way of doing it, just defining your own environment outright, making use of the hanging package, where the indentation is set to the width of the label plus a \quad space. I don't know if it's any better or not, but \label and \ref work just fine. It would probably be easy to achieve the same with an enumerate environment too.

Code: Select all

\documentclass{report}
\usepackage{hanging}
\usepackage{lipsum}

\newcounter{subproblem}[section]
\renewcommand{\thesubproblem}{\thesection.\arabic{subproblem}}
\newlength{\subproblabel}
\newenvironment{subproblem}{%
    \refstepcounter{subproblem}%
    \settowidth{\subproblabel}{\textbf{\thesubproblem}\quad}%
    \vspace{\abovedisplayskip}%
    \par\noindent\hangpara{\subproblabel}{1}%
    \textbf{\thesubproblem}\quad%
    \ignorespaces%
}%
{
    \par\vspace{\belowdisplayskip}\noindent\ignorespacesafterend
}

\begin{document}
\chapter{My Chapter}
\section{My Section}
\lipsum[1]
\begin{subproblem}\label{example}
Find the domain of the function (and we're making this long so we can see what happens with the next line)
\[
    f(x)=\frac{2}{x-2}
\]
State your answer in interval notation.
\end{subproblem}
That was subproblem~\ref{example}.
\end{document}
smr01cmh
Posts: 14
Joined: Thu May 13, 2010 1:23 am

ntheorem hanging indentation

Post by smr01cmh »

Gosh, that's brilliant, thanks very much!

I think I will use your hanging environment. The ideas you gave me prompted me to see if I could achieve it with ntheorem. I think that I have managed it (see the code below). I don't know which is more preferable though?

I really appreciate your help on this, thanks again.

Code: Select all

\documentclass[10pt,letter]{report}
\usepackage{amsmath}
\usepackage{ntheorem}
\usepackage{lipsum}% for auto-generating paragraphs
\usepackage[margin=3cm,showframe]{geometry}
\usepackage{chngpage}

\makeatletter
\newtheoremstyle{marginjustnumber}%
{\item[\theorem@headerfont \llap{##2}]}%
{\item[\theorem@headerfont \llap{##2} (##3)]}%
\makeatother

\newlength{\subproblabel}
% subproblem environment
\theoremstyle{marginjustnumber}
\theorembodyfont{}
\theoremseparator{}
\theoremprework{
\settowidth{\subproblabel}{\textbf{\thesubproblem} }%
\begin{adjustwidth}{\subproblabel}{}}
\theorempostwork{\end{adjustwidth}}
\newtheorem{subproblem}{}[section]

\begin{document}
\chapter{This chapter}
\section{This section}

\lipsum[1]% paragraph above for comparison
\begin{subproblem}
Find the domain of the function (and we're making this long so we can see what happens with the next line)
\[
    f(x)=\frac{2}{x-2}
\]
State your answer in interval notation.
\end{subproblem}
\lipsum[3]% paragraph below for comparison
\end{document}
Post Reply