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.

This is a follow-up question to my last question:

Defining a new LaTeX environment for numbered two-column proofs

Basically, I'm trying to define the following environment:

\newcounter{proofc}
\DeclareRobustCommand\stepproofc{\refstepcounter{proofc}(\arabic{proofc})}
\newenvironment{twoproof}{%
  \setcounter{proofc}{0}
  \begin{tabular}{@{\stepproofc \hspace{4pt}}>{$}c<{$}|>{$}l<{$}}
}{
  \end{tabular}
}

and I used \refstepcounter specifically so that I could refer to some entries inside other entries, like this:

\begin{twoproof}
\label{step1} Prop A & Justification \\
\label{step2} Prop B & Justification \\
Prop C & Because \ref{step1} and \ref{step2}
\end{twoproof}

Sadly, if you include the array package, this doesn't come out the way I'd hoped, because the \ref macros don't turn into the right number. I'm like 99% sure that this is because the \label macro is catching the wrong number (if you put a theorem environment before a twoproof environment, the \ref macros transform into the number of the theorem).

If I don't include the array package, this works the way it should. But then I can't use the >{$} and <{$} column modifiers to put my columns into math mode (I've tried using @-espressions instead and that gives an error). So how do I

  1. get label to work inside tabular, even with the array package included (preferable), or
  2. Typeset my columns in math mode without using >{$} and <{$}, which come from the array package.

Any help will be greatly appreciated!

Edit: Unfortunately, if you try to wrap the whole environment in \begin{displaymath} and \end{displaymath}, and change tabular to array (and get rid of the column modifiers), you get this error:

! Package amsmath Error: Multiple \label's: label 'step1' will be lost.

See the amsmath package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.30     \label
               {step2} Prop B & Justification \\
?

So it seems like displaymath doesn't play nicely with labels either.

Edit 2: As requested, here is a complete example illustrating the problem:

\documentclass[oneside]{article}
\usepackage{amsmath,amsthm}                                                                      
\usepackage{array}                                                                       

\newcounter{proofc}                                                                      
\DeclareRobustCommand\stepproofc{\refstepcounter{proofc}(\arabic{proofc})}               
\newenvironment{twoproof}{%                                                              
  \setcounter{proofc}{0}                                                                 
  \begin{tabular}{@{\stepproofc \hspace{4pt}}>{$}c<{$}|>{$}l<{$}}                        
}{                                                                                       
  \end{tabular}                                                                          
}                                                                                        

\theoremstyle{definition}                                                                
\newtheorem{thm}{Theorem}[section]                                                       

\begin{document}                                                                         

\begin{thm} This theorem exists to highlight the problem. \\                             
If you remove it or take the proof out of the theorem, the ref numbers simply disappear in the proof below

\begin{center}                                                                           
\begin{twoproof}                                                                         
\label{step1} E \vdash \alpha &  \pi_1 \\                                                
\label{step2} E \vdash \beta & \pi_2 \\
E \vdash \gamma & \ref{step1} \mbox{ and } \ref{step2}                                   
\end{twoproof}
\end{center}

\end{thm}                                                                                

\end{document}

Note that if you replace lines 7-12 with:

\newenvironment{twoproof}{%                                                              
  \setcounter{proofc}{0}
  \begin{displaymath}                                                   
  \begin{array}{@{\mbox{\stepproofc \hspace{4pt}}}c|l}                        
}{                                                                                       
  \end{array}
  \end{displaymath}                                                                         
}

You get the error described above.

Thanks again for your help!

share|improve this question
add comment

1 Answer 1

use the inline mode:

\documentclass[oneside]{article}
\usepackage{amsmath,amsthm,array}                                                                          
\newcounter{proofc}                                                                      
    \DeclareRobustCommand\stepproofc{\refstepcounter{proofc}(\arabic{proofc})}               

    \newenvironment{twoproof}
      {\setcounter{proofc}{0} \begin{center}$                                             
        \array{ >{\global\stepproofc\label{step\theproofc} \hspace{4pt}}c | l }}
      { \endarray $ \end{center}}

 \theoremstyle{definition}                                                                
 \newtheorem{thm}{Theorem}[section]                                                       
\begin{document}                                                                

\begin{thm} This theorem exists to highlight the problem. \\                             
If you remove it or take the proof out of the theorem, the ref numbers simply disappear in the proof below


\begin{twoproof}                                                                         
 E \vdash \alpha & \pi_1   \\                                                
 E \vdash \beta  & \pi_2 \\
 E \vdash \gamma & \ref{step1} \mbox{ and } \ref{step2}                                   
\end{twoproof}

 \end{thm}                                                                                

\end{document}
share|improve this answer
1  
give a complete example which I can run, then i can say more whats going wrong –  Herbert Dec 19 '10 at 18:00
    
So, this question is now quite old, but in the interest of providing closure I will leave this comment. This doesn't quite do what I want, because I'd like to automatically number every step, without needing the \Label macro (what's the point of automatic numbering if I have to put something in anyway). That may seem silly, but it just doesn't quite do what I want. I've tried modifying the provided solution, but haven't been able to separate the labeling and numbering mechanisms without running into the issue described in the question. That's what I'm going to keep trying to do, though. –  maths Dec 22 '10 at 5:10
    
That makes it easier, see my edited code –  Herbert Dec 22 '10 at 6:44
    
@maths: What? You want the labelling done automatically? Then what's the point in \label and \ref? Herbert gave you a solution, but in this case \ref{step<n>} is just a very fancy and unnecessarily complicated way to type the number <n>. –  Hendrik Vogt Dec 22 '10 at 7:35
    
@Hendrik: you have a curious understanding of "complecated". However, it is anyway wrong to define labels with the same name, which happens when there is another proof environment. –  Herbert Dec 22 '10 at 7:57
show 2 more comments

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.