Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to have an environment for strategies. So far I used the package ntheorem to define such an environment.

I use it like this:

\begin{strategy}[bla]
    bla bla
\end{strategy}

And get:

 <surrounding text>

 Strategy 1 (Bla):
    bla bla

<surrounding text>

Which is what I want except that I would like to group the numbering of the strategies with by me specified prefixes, like LD.1,..LD.5 and I.1,..I.3 and so on:

<surrounding text>

Strategy A.1 (bla):
   bla bla
   more bla bla

<surrounding text>

So, the word Strategy my prefix and a short description an a non-indented line, then the strategy text indented. Also I would like a little space above and below the strategy.

Is it possible to use ntheorem in such a way:

\begin{strategy}[prefix][bla]
    bla bla
\end{strategy}

Or has anybody another idea. I do not need to use ntheorem. It was just the first idea I had.

I use ntheorem for other environements, so they should work together.

share|improve this question
    
It's a bit too vague; how do you decide to change A into B? Are strategies A and B mixed, that is, can there be A.1, A.2, B.1, A.3, B.2? –  egreg Sep 25 '12 at 8:50
    
I edited the question. –  Jana Sep 25 '12 at 9:01
add comment

3 Answers 3

up vote 8 down vote accepted

Here's a way; you specify

\begin{strategy}{<label>}[<optional description>]
Text
\end{strategy}

The <label> can be empty. The various strategies will be numbered sequentially by label. If you want to reset a number, then issue

\resetstrategy{<label>}

Example:

\documentclass{article}
\usepackage{xparse}

\makeatletter
\NewDocumentEnvironment{strategy}{ m o }
 {\@ifundefined{@strategy#1}
   {\newtheorem{@strategy#1}{Strategy}%
    \global\@namedef{the@strategy#1}{#1.\arabic{@strategy#1}}%
   }%
   {}%
  \IfNoValueTF{#2}{\begin{@strategy#1}}{\begin{@strategy#1}[#2]}%
 }
 {\end{@strategy#1}}
\newtheorem{@strategy}{Strategy}
\newcommand{\resetstrategy}[1]{%
 \@ifundefined{@strategy#1}
  {\typeout{You have no `Strategy #1'}}
  {\setcounter{@strategy#1}{0}}%
}
\makeatother

\begin{document}

\begin{strategy}{}
A
\end{strategy}

\begin{strategy}{}[Good]
B
\end{strategy}

\begin{strategy}{A}
C
\end{strategy}

\begin{strategy}{A}[Bad]
D
\end{strategy}

\begin{strategy}{X}[So and so]
E
\end{strategy}

\resetstrategy{A}

\begin{strategy}{A}
F
\end{strategy}
\end{document}

enter image description here

share|improve this answer
    
This is exactly what I want. Unfortunately I also use ntheorem for other environments and it seems to not work together. It just takes the style I last defined, even though I put the code where the old definition was. And there is no label and the name is written as normal text. Can I use this and ntheorem? –  Jana Sep 25 '12 at 9:56
    
@Jana Just add \theoremstyle{plain} (or the style you wish) before the two \newtheorem commands in the code. –  egreg Sep 25 '12 at 10:24
add comment

Like this?

Code

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{lipsum}

\newcounter{mystrategy}[section]
\setcounter{mystrategy}{0}
\renewcommand{\themystrategy}{\Alph{section}.\arabic{mystrategy}}

\newenvironment{strategy}[1]{\refstepcounter{mystrategy}\textbf{Strategy \themystrategy\ (#1)}\itshape\selectfont}{\par}

\begin{document}

\section{One}
\lipsum[1]
\begin{strategy}{Bla}
\lipsum[2]
\end{strategy}
\lipsum[3]

\subsection{one}
\lipsum[1]
\begin{strategy}{Bla}
\lipsum[2]
\end{strategy}
\lipsum[3]

\section{Two}
\lipsum[1]
\begin{strategy}{Bla}
\lipsum[2]
\end{strategy}
\lipsum[3]

\subsection{one}

\lipsum[1]
\begin{strategy}{Bla}
\lipsum[2]
\end{strategy}
\lipsum[3]

\end{document}

Output

enter image description here


Edit 1: For freely choosable labels:

Code

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{lipsum}

\newenvironment{strategy}[2]{\textbf{Strategy #1 (#2)}\itshape\selectfont}{\par}

\begin{document}

\section{One}
\lipsum[1]
\begin{strategy}{Q.5}{Bla}
\lipsum[2]
\end{strategy}
\lipsum[3]

\subsection{one}
\lipsum[1]
\begin{strategy}{X.101}{Bla}
\lipsum[2]
\end{strategy}
\lipsum[3]

\section{Two}
\lipsum[1]
\begin{strategy}{H.42}{Bla}
\lipsum[2]
\end{strategy}
\lipsum[3]

\subsection{one}

\lipsum[1]
\begin{strategy}{S.19}{Bla}
\lipsum[2]
\end{strategy}
\lipsum[3]

\end{document}

Edit 2: With indentation (thanks to Werner) and spaces:

Code

\documentclass{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{lipsum}

\newenvironment{strategy}[2]{\vspace{5mm}\noindent\textbf{Strategy #1 (#2)}\\\phantom{}\hfill\begin{minipage}{\dimexpr\textwidth-5mm} \itshape\selectfont}{\end{minipage}\par\vspace{5mm}}

\begin{document}

\section{One}
\lipsum[1]
\begin{strategy}{Q.5}{Bla}
\lipsum[2]
\end{strategy}
\lipsum[3]

\subsection{one}
\lipsum[1]
\begin{strategy}{X.101}{Bla}
\lipsum[2]
\end{strategy}
\lipsum[3]

\section{Two}
\lipsum[1]
\begin{strategy}{H.42}{Bla}
\lipsum[2]
\end{strategy}
\lipsum[3]

\subsection{one}

\lipsum[1]
\begin{strategy}{S.19}{Bla}
\lipsum[2]
\end{strategy}
\lipsum[3]

\end{document}

Result

enter image description here

share|improve this answer
    
This is close, but I actually would like to specify the prefix myself and not corresponding to the section. –  Jana Sep 25 '12 at 9:02
    
@Jana: Now you can specify them freely. –  Tom Bombadil Sep 25 '12 at 9:14
    
This is good. But now I have the caption (Strategy Q.5 (Bla)) indented and the text not. I would like the caption to not be indented, but the rest, linebreak after the caption and a space above and below teh strategy. –  Jana Sep 25 '12 at 9:37
    
@Jana: Done. But next time it would be nice to describe exactly and completely all requirements in your initial question. –  Tom Bombadil Sep 25 '12 at 9:52
add comment

If you use the hyperref and ntheorem. You can try something like this:

\newtheorem{strategy}{\normalfont{\textbf{Strategy}}}
\numberwithin{strategy}{chapter}
\newcommand{\strategyautorefname}{Strategy}

\begin{document}
...
\chapter{chapter something}
\begin{strategy}\label{str:first}
bla bla
\end{strategy}
In \autoref{str:first} you can see...

The first command defines the strategy environment. The second command defines the counter that precedes the strategy, in this case the Chapter number. The last command allows you to cite your environments and get automatically the string Strategy appended before the number. This will produce something like this when you reference it:

  1. Chapter something.

Strategy 2.1. bla bla

In Strategy 2.1 you can see...

Where 2 is the chapter number and 1 is the counter of the strategy within the second chapter.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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