1. Affan

Do you know of a way of defining newcounter such that I can have a separate macro that prints out my own heading? eg.
I want to use \creatTask{Develop a new Algorithm},
to expand into \textbf{TASK 1 — Develop a new Algorithm}.

Thank you.

2. tom

Hi!

Try the code below, I think it solves your problem. I am using a newcommand “\createTask” which you call each time you want to create a new task. You can modify the new command to your needs, e.g. add the dash, etc.

\documentclass{article}
\begin{document}
}
\newline
\newline
\end{document}
• Thank you Tom!

3. Felipe

I have a counter-related question. I’m writing the outline of a document and want the section headings to be called simply “Chapter 1”, “Chapter 2”, etc. However, I need to move things around (i.e. move entire sections up or down) which messes the numbering, and then I have to go a manually change all of the headings. Any suggestions on how can I reference the chapter number without having to use actual numbers?

4. tom

Hi Felipe,

You can use labels to reference many things including all headings. Just place the label command (\label{label:name}) below the heading and use \ref{label:name} to access the number.

Cheers,
Tom

• Quasi

Fantastic idea! Many thanks!!

5. David

Hi, first of all, great blog. Anyway, do you know if there is any command that gets the max value of a counter in a list? Thing is, I need to typeset a list where the label is normally:

P 1 – This and that and that.
P 2 – This and also another thing.

However, if there is only one \item in the list, it should be typeset as:

Paragraph – I’m alone in this list!!

Therefore, when defining the \newenvironment, I will probably need to use, as a condition value for \ifthenelse, some command like \maxvalue{counter}, as in:

\ifthenelse{\maxvalue{counter}=1}{Paragraph - }{P \arabic{counter} -}

The question is, of course, is there such a command (maxvalue)? Is it something LaTeX can do?

Thank you very much, I can send you the sources if you want.
David

• 2noob2banoob

Don’t know if you still need it, but…

I think the easiest way is to manually label the last item, then in your environment definition check the counter value associated with that label. Not sure though because I’m not that much of an expert, but there is a package called lastpage which counts pages in a similar way. You do have to run latex twice to get the counter right.

Also, it may become problematic if you want several of those environments in your document, but maybe you can fix that by making the label name a variable which is passed as an argument to the environment. Then if you use a different label for each occurence of the environment you should be ok. Not exactly trivial though…

An example of the code in the document body: (don’t know how to do code layout on this blog, sorry about that)

\begin{myenv}{lbl1}
\item blabla
\item blabla
\item \label{lbl1} blabla
\end{myenv}

\begin{myenv}{lbl2}
\item \label{lbl2} blabla
\end{myenv}

I hope this works for you. I don’t have any experience with creating my own environment so I can’t test it unfortunately.

For code,
[sourcecode language=”latex”]

[/sourcecode]
should work.

Cheers, Tom.

6. Hi David,

If I understood your problem correctly, I do not think you can do it the way you propose, as Latex runs through your code sequentially and therefore cannot know the final value of a counter beforehand. Hence there is nothing like \maxvalue{counter}.
You would probably need to do it manually…

Tom

7. David

Thank you for your help, I was afraid of that, exactly. I guess I will need to figure out another automatic way of doing that (mixing latex/scripts probably).

8. Ehsan

Hi,
plz help me!!
How can i link footnote counter to pabe counter?

Thanks.

9. Ehsan

Hi,
Thanks,
In the above lesson (maybe!) you write
————————————————————————–
\newcounter {newcounter} [oldcounter] defines a new counter. Option ‘oldcounter’ is to link ‘newcounter’ to ‘oldcounter’.
————————————————————————-
i want create such link (beetwen newcounter and oldcounter).
It means that when the oldcounter is increased the newcounter is set to zero!!

Thanks a lot.

10. tom

You can try to use \newcommand:

\newcommand{\name}[3]{
%arguments: newcounter, oldcounter, value
\setcounter{#2}{0}
}

I am not sure whether this will work, you have to try it yourself.
Good luck:).

11. David

Hi again! I almost managed to do what I wanted, using \label and \ref to store a given value in the aux file. Here is what I did:

%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{listnum}

\makeatletter
\newcommand\firstitem{\@item[ImAlone-]}
\makeatother

\newenvironment{myenumerate}{
\refstepcounter{listnum}
\begin{enumerate}
\ifthenelse{\equal{\ref{enum:\arabic{listnum}}}{1}}
{
\let\item\firstitem
\refstepcounter{enumi}
}{
\refstepcounter{enumi}
}
}{
\label{enum:\arabic{listnum}}
\end{enumerate}
}
%%%%%%%%%%%%%%%%%%%%%

This is: for each myenumerate env in the text, there will be a correspondent enum:(number) label, and at the end of the processing, those counters will hold, as value, the total number of items in the environment, plus 1.

With 3 myenumerate ‘s, each with 1,4 and 1 numberof \item ‘s, respectively, I get a clean compilation, but:

2.

2.
3.
4.
5.

2.

So, I’m very close, but since I’m a total newbie in LaTeX, there is something simple I can’t realize. Could you help me? Maybe try it?

Thanks a lot.

12. Alex

How to change numbering of figures in a standard Latex article style from Figure 1: to Figure 1.
(i.e., colon to dot after numbers)

13. tom

Hi Alex,

You can actually customise your caption completely.

\usepackage{caption2}

Then you renew the “caption label delimiter” through:

\renewcommand{\captionlabeldelim}{.}

If you want to have the colon back for whatever reason, just use the command again inside your document with a colon instead of a dot.

Cheers,
Tom

14. Florian

Hi,
I am writing a document with many constants that I want to write $C_i$ with $i=1,2,…$, and such that I can make a reference to a specific constant later. So I tried to define a counter \cte, a command \newcte{label} that prints $C_\thecte$ and labels it with some label, and then another function \usecte{label} that would print the corresponding constant.

I tried:

\newcounter{cte}
\newcommand{\newcte}[1]{
\refstepcounter{cte} \label{cte:#1} C_{\thecte}
}
\newcommand{\usecte}[1]{
C_{\ref{cte:#1}}
}

But I don’t understand why this does not work. Moreover, I have an annoying problem: when I want to use this syntax in an align environment with a label, I get a multiple labels error…

Thanks in advance if anyone knows how to make this work (the way I tried or any other way!).

15. tom

Hi Florian,


\begin{document}
\begin{multline}\label{eqn:dummy}
a = b + \dots \eln \\
c + d \dots \eln \\
e + f \dots \eln \\
\dots+g + h \dots
\end{multline}

Referencing the equation: \ref{eqn:dummy}

Referencing lines: \eqqref{lnl:2}
\end{document}
• Casey

Thanks Tom! This solution will work.

74. Paul

Hi Tom,
Using documentclass{book} I have \setcounter{secnumdepth}{3} before \mainmatter. For one of the chapters this setting is one too deep, so I want to change it for that chapter only. I’ve tried resetting within the chapter, but to no avail. Do you have a solution to this.

Thanks a lot, in anticipation,
PaulT.

75. Paul

Hi Tom,
I left my previous post when frustrated after spending some time googling but failing to find a solution. However, I got the google question right today and now have the solution, which is simple.
Cheers,
PaulT.

• Thanks for getting back to me. Would you mind to post the solution that worked for you? Thanks, Tom.

76. Paul

Hi Tom,
The solution was to use the asterisk answer—i.e. include an asterisk in the section heading: e.g. \subsubsection*{Arguments}. This prevents the section heading being listed in the table of contents (toc).
Cheers,
PaulT.

• Paul, thanks for posting the solution, appreciate it! Best, Tom

77. Federica

Hello 🙂
I am writing my Master’s Thesis and I have a big big problem: I have to put 87 figures, two for page, so I am using the \subfloat command.
When I compile I get the error Counter too large. How can I solve it? My figures are labeled as A, B, C…..what’s the right way to continue labelling them AA, BB, CC… and so on?
Fede

78. Hello,
I want to use additional counters for page number in appendices, so that the main numbering (bottom) goes from beginning to the end of the document, and header (if the page is in appendix) must contain something like “Appendix 1. Page X of XXX” where XXX is the number of pages in appendix. Can I do it with custom counters? Thanks.

• tom

Hi there,

Thanks for your question. The lastpage package does what you are looking for. I wrote a short post about it some time ago.

HTH,
Tom

79. nils

Hello,
How do i stop counter? I need to stop counting pages at the appendices i have following;

\setcounter{page}{1}
\fancyfoot[C]{Page \thepage \ of XXX}
\pagenumbering{arabic} %use arabic page numbering in the mainmatter
\input{sections/cp1-introduction.tex}
\input{sections/cp2-problem_formulation_and__description.tex}
\input{sections/cp3-methodology___Theory.tex}
\input{sections/cp4-analysis.tex}
\input{sections/cp8-discussion.tex}
\input{sections/cp9-conclusion.tex}

%% I NEED TO STOP COUNTING PAGES FROM HERE%%

\label{bib:mybiblio}
\appendix
\input{sections/appAname.tex}
\input{sections/appBname.tex}
\input{sections/appCname.tex}
\end{document}

Best Wishes and thanks in advance

• Hi Nils,

I assume you use the lastpage package as described in this post. The easiest solution would be to place a label on the last page (before the appendices) and then use \pageref to print that page number.

Best, Tom

\documentclass{report}
\usepackage[toc,page]{appendix}
\usepackage{blindtext, fancyhdr}
\pagestyle{fancy}
\fancyfoot[C]{{\thepage} of \pageref{LastContentPage}}
\begin{document}
\tableofcontents
\blinddocument
\label{LastContentPage}
\appendix
\chapter{Appendix}
\blinddocument
\end{appendices}
\end{document}
80. Joe

Hello Tom,

Thank you for the awesome blog.
I am new to Latex environment. I looked at your response (11/9/2011) related to custom
toc. Is there a special package that I need to download from CTAN ? Currently in list of tables I have VIII.1, VIII.2 etc that needs to changed to A2.1, A2.2 etc.
2. How do i setup margins 1 ½” on the LEFT and 1” on the OTHER THREE SIDES for the entire document ?
Thank you.

• Hi Joe,

1. To change the way a counter value is printed, you won’t need a package.

\renewcommand*{\thechapter}{A\arabic{chapter}.\arabic{section}}

2. Use the geometry package to set the margins globally.

\usepackage[top=1in,bottom=1in,right=1in,left=1.5in]{geometry}

HTH,
Tom