Graphics, Figures & TablesNumbering of customised environment in Appendix

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
paolob
Posts: 3
Joined: Fri Feb 06, 2015 9:09 am

Numbering of customised environment in Appendix

Post by paolob »

Hello,

I am new to the community, so maybe it has escaped me, but I did not find an answer to this problem.

I have defined a new environment, with its proper counter

Code: Select all

\newenvironment{spec}[2]{
\textbf{Specification~\ref{#2}}: #1
\label{#2}
\begin{small}
\begin{tabbing}
}
{
\end{tabbing}
\end{small}
}
\newcounter{spec}
and everything works nicely, However, when I use it in the appendix,

Code: Select all

\newcounter{appendix}
%\renewcommand\thespec{\Alph{appendix}\arabic{spec}}
\setcounter{spec}{0} 
%\renewcommand{\thespec}{A.\arabic{spec}} 
\appendix
%\makeatletter
%\def\@seccntformat#1{Appendix\ \csname the#1\endcsname\quad}
%\makeatother
\input{appendix}
I get references and captions in the form Specification Appendix A.x. Of course the A.x bit is what I want, but not the Appendix bit.

I have tried to adapt the solutions proposed for figure and table, by using \thespec, but that does not do anything.

Any suggestions?

thanks
paolo

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Numbering of customised environment in Appendix

Post by Johannes_B »

Hi and welcome,

can you tell us what you want to do? Do you just want to have automatically numbered chunks of material?

Right now, you are setting the counter after defining the environment, i think this should give the first error if you would use the counter in your newly defined environment.

Instead of your label/ref mechanism (which is wrong here), you should use \refstepcounter.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
paolob
Posts: 3
Joined: Fri Feb 06, 2015 9:09 am

Re: Numbering of customised environment in Appendix

Post by paolob »

Dear Johannes, thank you for your reply and apologies for not replying sooner, but I did not see the reply on my previous checks to the page. Shame on me! :-(

What I want to achieve is to get a collection of definitions and equations gathered under the Specification heading and references of the form Specification x when I refer to specifications in the main text and Specification A.y when I refer to specifications in the Appendix.

My definition works correctly for those in the text (actually the \refstepcounter causes some compilation error), but for those in the Appendix I get that the heading is Specification Appendix A.y. and also the reference in text reads Specification Appendix A.y.

By the way, I am compiling under the Elsevier article style

\documentclass[3p,12pt]{elsarticle}

so that might also count.

thanks
paolo
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Numbering of customised environment in Appendix

Post by Johannes_B »

Something like this?

Code: Select all

\documentclass[3p,12pt]{elsarticle}
\usepackage{blindtext}
\usepackage{capt-of}
\usepackage{hyperref}
\newcounter{spec}
\renewcommand*{\theHspec}{\thespec}
\newcommand{\specautorefname}{Specification}
\newenvironment{spec}{\par\refstepcounter{spec} Specification\space\thespec:\par}{}
\begin{document}
\section{main}
\blindtext

\begin{spec}
	\label{spec:main}
\end{spec}
In \autoref{spec:appendix}, not  \autoref{spec:main}, you can see \blindtext
\clearpage
\appendix
\setcounter{spec}{0}
\renewcommand{\thespec}{\Alph{section}.\arabic{spec}}
\section{appendix}
\begin{spec}
	\label{spec:appendix}
\end{spec}
In \autoref{spec:appendix} you can see \blindtext
\end{document}
\appendix
\setcounter{spec}{0}
\renewcommand{\thespec}{\Alph{section}.\arabic{spec}}
\section{appendix}
\begin{spec}
	\label{spec:appendix}
\end{spec}
In \autoref{spec:appendix}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
paolob
Posts: 3
Joined: Fri Feb 06, 2015 9:09 am

Re: Numbering of customised environment in Appendix

Post by paolob »

It worked!

Thank you very much. I would have never imagined of anything such that.

The only problem is that now I have a conflict between the hyperref package required by this and the xr-hyperref one that the elsevier style seems to prefer.
However this just gives me a few warnings, so I think I can live with that.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Numbering of customised environment in Appendix

Post by Johannes_B »

You do not need hyperref, but if you are using it in your document, and most users do, you need to take care of some stuff.

A 20 second google search told me, that hyperref must be loaded after xr-hyper. i don't get any warnings.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply