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’m using LaTeX to typeset some homework, and since we’re assigned problems scattered throughout our textbook I have to enter the problem number for each problem I typeset. I’d like these problems to look like this:

Problem 4.15. Prove that for every prime p, …

As far as I can tell, all of the straightforward ways to do this with amsthm will produce labels like

Problem (4.15).

or

4.15. Problem.

neither of which is quite what I want. Most of the samples I’ve found online are complicated by the fact that they support automatic numbering, but that’s not necessary (or even really useful) for me. I did come up with this:

\newenvironment{myproblem}[1][]
    {\vspace{1em} \noindent \textbf{Problem #1.}}
    {\vspace{1em}}

It produces the output I want, give or take an imperceptible amount of spacing, but this feels like a kludge. Is there a way to get what I want using amsthm or ntheorem or something like that?

share|improve this question
1  
So you don't want automatic numbering? If so, may I ask you why? What do "4" and "15" represent in your example? –  Gonzalo Medina Sep 19 '11 at 0:17
    
@GonzaloMedina As I said, we’re assigned a smattering of problems from a textbook (e.g. “problem 12 from chapter 4 and problem 5 from chapter 5”), and in order to include the problem number in my answers I need to use wildly non-sequential values (4.12 and 5.5 in this example). –  bdesham Sep 19 '11 at 3:14
add comment

3 Answers

up vote 9 down vote accepted

You can use the thmtools package as a front-end for amsthm to define your own theorem style. You can suppress the automatic numbering using the numbered=no option, and use the additional note field to manually introduce the numbering. Notice however that this approach has two drawbacks: 1) You loose the possibility of cross-referencing your problems. 2) Manual numbering is error-prone.

Here's a simple example:

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}

\declaretheoremstyle[
notefont=\bfseries, notebraces={}{},
bodyfont=\normalfont,
postheadspace=0.5em,
numbered=no,
]{mystyle}
\declaretheorem[style=mystyle]{problem}

\begin{document}

\begin{problem}[4.15]
Prove that for every prime $p$,
\end{problem}

\begin{problem}[3.12]
Prove that every integer
\end{problem}

\end{document}

enter image description here

As I already mentioned, the previous solution annihilates cross-referencing. Here's another approach that allows you to cross-reference your problems. I am assuming that the two-fold counter for the problems has its firs component (the "4" in your example) associated to an already defined counter (the one of a sectional unit, as it is customary), and that only the second component (the "15" in your example) will be manually introduced (again a possible source of errors).

In the following example I used amsthm to define a new theorem-like structure of definition style; this new structure will be numbered subordinately within sections. Then I wrapped this definition using a new environment with a mandatory argument that will be used to set the proper value to the second component of the counter.

\documentclass{article}
\usepackage{amsthm}

\theoremstyle{definition}
\newtheorem{prob}{Problem}[section]

\newenvironment{problem}[1]
  {\setcounter{prob}{\numexpr#1-1\relax}\begin{prob}}
  {\end{prob}}

\begin{document}

\section{Test}
\begin{problem}{15}\label{test1}
Prove that for every prime $p$,
\end{problem}
\section{Test}
\begin{problem}{8}\label{test2}
Prove that for every ring $R$,
\end{problem}
We see in Problems~\ref{test1} and~\ref{test2}

\end{document}

enter image description here

share|improve this answer
    
I don’t need the ability to cross-reference so this will work fine. Thanks! –  bdesham Sep 19 '11 at 3:15
add comment

Here's a simpler solution that also copes with cross references.

\documentclass[a4paper]{article}
\usepackage{amsthm}

\makeatletter
\newtheorem*{probleminn}{Problem \@currentlabel}
\newenvironment{problem}[1]
  {\def\@currentlabel{#1}\probleminn}{\endprobleminn}
\makeatother

\begin{document}
\begin{problem}{4.14} 
Prove that $2$ is prime.
\end{problem}

\begin{problem}{4.15}\label{bigproblem}
Prove that $2+2=4$.
\end{problem}

\begin{problem}{5.5}\label{easyone}
Prove that every even integer greater than $2$ is the sum of two primes.
\end{problem}

I can solve \ref{easyone}, but I'm stuck with \ref{bigproblem}.
\end{document}

Defining \@currentlabel is what's needed for assigning the correct value to the \label.

share|improve this answer
add comment

How about this:

    \documentclass{book}
    \usepackage{thmtools}
    \declaretheorem[numberwithin={}]{theorem}

    \begin{document}
    \begin{theorem}
        something
    \end{theorem}
     \begin{theorem}
        something
    \end{theorem}
   \end{document}

enter image description here

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.