The following is a summary of counter usage and manipulations available in LaTex.
The following commands have a counter associated with it:
- part
- chapter
- section
- subsection
- subsubsection
- paragraph
- subparagraph
- page
- equation
- figure
- table
- footnote
- mpfootnote
- enumi
- enumii
- enumiii
- enumiv
You have several possibilities to manipulate counters in LaTex:
\addtocounter {counter} {value}increments the specified counter by the value.\newcounter {newcounter} [oldcounter]defines a new counter. Option ‘oldcounter’ is to link ‘newcounter’ to ‘oldcounter’.\setcounter {counter} {value}sets the counter to have the specified value.\usecounter{counter}used as the second argument of the list environment to number list items (see list command).\value {counter}produces the value of the counter and is useful for doing arithmetic with counters.\renewcommand {cmd} [args] [opt] {def}general command to define/redefine new commands.
Counter values can be printed in different formats such as:
\alphor\Alph {counter}for letters (a…z or A…Z) .\arabic {counter}for arabic numbers (1…9).\fnsymbol {counter}printing various symbols: asterisk, dagger, double dagger, section mark, paragraph mark, double vertical lines, double asterisk, double daggers, double double daggers. The value of counters must be between 1 and 9.\romanor\Roman {counter}for roman numerals (I,II,III,IV,V,…,X,etc.)
September 21st, 2007 at 9:56 pm
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.
September 22nd, 2007 at 12:36 pm
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} \newcounter{taskcounter} \begin{document} \newcommand{\createTask}[1]{ \stepcounter{taskcounter} \bf{TASK \arabic{taskcounter} #1} } \section{My three tasks} \createTask{Your first task} \newline \createTask{Your second task} \newline \createTask{Your third task} \end{document}October 2nd, 2007 at 7:54 pm
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?
October 15th, 2007 at 10:33 am
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
November 6th, 2007 at 4:12 am
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
September 25th, 2012 at 9:55 am
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.
September 25th, 2012 at 10:37 am
Thanks for your comment!
For code,
[sourcecode language="latex"]…
[/sourcecode]should work.
Cheers, Tom.
November 7th, 2007 at 12:51 pm
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
November 7th, 2007 at 2:48 pm
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).
November 21st, 2007 at 10:17 pm
Hi,
plz help me!!
How can i link footnote counter to pabe counter?
Thanks.
November 22nd, 2007 at 4:41 pm
Hi,
You can use the Latex variable “\thepage” to get the current page as a number.
Look at this post for how to customise header/footer:
http://texblog.wordpress.com/2007/11/07/headerfooter-in-latex-with-fancyhdr/
Hope this solves your problem. If not, let me know.
November 23rd, 2007 at 12:48 pm
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.
November 27th, 2007 at 11:22 pm
You can try to use \newcommand:
\newcommand{\name}[3]{ %arguments: newcounter, oldcounter, value \addtocounter{#1}{#3} \setcounter{#2}{0} }I am not sure whether this will work, you have to try it yourself.
Good luck:).
December 11th, 2007 at 5:19 am
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.
January 29th, 2008 at 4:22 am
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)
January 29th, 2008 at 5:50 pm
Hi Alex,
You can actually customise your caption completely.
To answer your question, you need the package “caption2″:
\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.
This should solve your problem.
Cheers,
Tom
March 4th, 2008 at 10:21 am
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!).
March 17th, 2008 at 10:18 pm
Hi Florian,
What you did works perfectly, just that you forgot the dollar signs ($), even though you had them in the text. Here is the corrected code:
\newcounter{cte} \newcommand{\newcte}[1]{ \refstepcounter{cte} \label{cte:#1} $C_{\thecte}$ } \newcommand{\usecte}[1]{ $C_{\ref{cte:#1}}$ }And now you can print what you wanted:

\newcte{bla}->\ref{cte:bla}-> 1March 24th, 2008 at 5:20 pm
Hi,
I’m using “book” as the document class. And I want to link chapters to parts, so whenever I create a new part, the chapter counter is reset to 0. The easiest way to do this would be to just add following code in the preamble:
\newcounter{chapter}[part]Right? But LaTeX always complains that the counter “chapter” has already been defined.
How do I do this efficiently, without having LaTeX complain? Please help. Thanks in advance.
March 26th, 2008 at 10:05 pm
Hi Troy!
The counter is indeed already defined. What you have to do is reset it to zero.
The following line after each “part-command” will do the trick:
\setcounter{chapter}{0}Cheers,
Tom
March 27th, 2012 at 2:43 am
Thanks a lot. I was searching for this info for long time.
March 27th, 2012 at 3:11 am
You are welcome! Best, Tom.
March 27th, 2008 at 11:04 am
Hi Tom,
Thanks for your tip. I tried that, and at the first look, it’s the solution I was looking for. But only at the first look. See, I use PDFTeX. And setting the “chapter” counter to zero whenever I call “part” does the trick visually. This solution would work fine as a print. But my goal is PDF.
The problem is, let’s say I have two parts in my book, with various chapters in each part. Now, in the table of contents in the PDF, if I click on the second chapter of part II, the link doesn’t take me to the second chapter of part II. Instead, it takes me to the second chapter of part I. So internally, setting the “chapter” counter to zero every time part is called up messes with PDFTeX’s linking system.
Is there any way to avoid that? There has to be an elegant solution to this problem without having to program new \chapter or \part, because I want to be able to use my .tex files in other projects as well without having to change anything.
Thanks again. Cheers,
Troy
April 9th, 2010 at 12:41 pm
Hi Troy,
my answer comes probably a bit too late to help you but in case anybody else faces the same problem: Include the following command in your preamble:
\renewcommand*{\theHchapter}{\thepart.\thechapter}Cheers,
PLS
March 27th, 2008 at 8:56 pm
Hi Troy,
I see your point. The books I have seen usually have consecutive chapter numbering even over different parts. I couldn’t find a solution to your problem, sorry!
Cheers,
Tom.
March 27th, 2008 at 10:55 pm
Hi,
thank you for your answer. unfortunately, what does not work is that I cannot use this code inside an environment \begin{align} with a label, because then there is a conflict on the labels…
i have found a trick by using the package smartref, but if anybody has a better solution, I am interested!
April 13th, 2008 at 1:53 pm
hello
I want for my math formula number, first have equation number then have chapter number, e.g.(34-2)
34 is equation number and 2 is chapter number
how can I do this?please guide me
April 14th, 2008 at 8:18 am
@venus
In Latex, you can always access the counter of a specific environment using \theenvironment, e.g. the equation-environment counter is accessed through
\theequation.Your problem can be solved by redefining the equation counter as follows:
\renewcommand\theequation{\arabic{equation}-\thechapter}Cheers,
Tom
April 16th, 2008 at 10:41 pm
Hi all,
I have the appropriate “example” environment, and its respective ExampleCounter.
I want to be able to continue an “example”, as in:
Example a: xyz
Example b: xyz
Example c: xyz
Example b (continued): xyz
Example d: xyz
My question is:
How do you:
(1) set ExampleCounter = value of ExampleCounter of the (say the) second example (ie. Example b:)
(2) Use the counter to create the example: “Example b (continued):” (i.e. \begin{example}[continued] xyz \end{example}
(3) set ExampleCounter = value it had before step (1) —so that I can continue with the correct example labels…
Thanks in advance,
Erick
April 17th, 2008 at 7:31 pm
Hi Erick,
I couldn’t find a nice answer to your questions (1) and (3).
Concerning question 2, a possible way to do it is the following:
\newcounter{examplecounter} \newenvironment{example}[1]{ \addtocounter{examplecounter}{1} Example \theexamplecounter#1:}{\\}and then
\begin{example}{} xyz \end{example} \begin{example}{ (continued)} xyz \end{example}The disadvantage is, you always have to have the optional argument brackets when using the environment.
For (1) & (3), you can simply add and subtract from your counter:
\begin{example}{}xyz\end{example} \begin{example}{}xyz\end{example} \begin{example}{}xyz\end{example} \addtocounter{examplecounter}{-2} \begin{example}{ (continued)}xyz\end{example} \addtocounter{examplecounter}{1} \begin{example}{}xyz\end{example}This is obviously not dynamic, but I couldn’t think of a better solution for now, sorry.
Cheers,
Tom
April 19th, 2008 at 5:49 am
hello thnks for your worth help
April 19th, 2008 at 6:44 am
First of all I wanted to thank Tom for his response. I also wanted to post a possible solution to my questions 1 and 3 that is somewhat more dynamic (although definitively not elegant).
%First we need to save counter before the example that we wish to %continue later (say save its value in the newcounter 'ex') \newcounter{ex} \setcounter{ex}{\value{examplecounter}} %When where we want to continue the example we can load the %saved counter (we need to save the current counter value in the %newcounter temp ---so that we can restore it later) \newcounter{temp} \setcounter{temp}{\value{examplecounter}} \setcounter{examplecounter}{\value{ex}} %We continue the example (as Tom showed) \begin{example}{ (continued)}xyz\end{example} %Finally we restore the counter value \setcounter{examplecounter}{\value{temp}}Erick
April 21st, 2008 at 3:04 pm
hi all
I’m looking to define a new sort of section to my document where i store all my figures. It should be something like when you do \appendices your chapter titles change from Chapter 1,2,3 to Appendix A,B,C
I want this new section at the very end (after appendices, bibliography, etc), and when i type \figures for instance, chapter titles should change to Figures Chapter 1,2,3
What do you think is the best solution for this? And do the figurecounters automatically change too? (so they look like Figure 1.12, 2.34, etc)
May 23rd, 2008 at 6:58 am
I need to print a document in batches of pages. I’d LIKE to do this by creating separate documents for each batch of pages (the batches have different layouts and are printed on different paper so it makes some sense to separate them).
In order to do this, I need to set the starting page of each document. I haven’t had much luck modifying \thepage… it seems to be defined as a macro command somewhere deep in the bowels of TeX.
Any/all help and suggestions are welcome,
thanks.
May 23rd, 2008 at 7:11 am
Sorry… my bad… I found the (very simple) answer moments after posting:
\setcounter{page}{9}Thanks anyway,
June 10th, 2008 at 12:09 pm
i have a question. how can i start footnote number, from 1 in each page, as u know its continuous for each chapter
June 11th, 2008 at 6:21 am
hello
please help me who knows it, as you familiar with latex footnotes numbers
starts from 1 at the beginning of each chapter, but I want for each page
footnotes number starts from 1, how do it?
thank you
June 22nd, 2008 at 6:40 am
hi
how can I clear the page number of the first page of each chapter, and second page of chapter start from 2 and continue?
thanx
July 7th, 2008 at 1:45 pm
I am writing a book where I would like to number the examples, and have them appear in a “listofexamples”. I would like the counter to be chpater name dash example number, also, I would like to be able to reference an example via \label \ref. How can I achieve this.
Thanks
July 13th, 2008 at 12:50 am
Hi Victor,
Thanks for your very interesting question. As this might be interesting to others, I decided to write a new post on that topic.
http://texblog.wordpress.com/2008/07/13/define-your-own-list-of/
I hope this is more or less what you were looking for. If you have any further question, don’t hesitate to contact me.
Best regards,
Tom
July 19th, 2008 at 1:55 pm
Great, I used:
\newcommand{\listexamples}{List of Examples} \newlistof{examples}{exp}{\listofexamples} \newcommand{\example}[1]{% \refstepcounter{examples} \vspace*{0.2in}\par\noindent\sqrblt\textbf{Example \theexamples. #1} \addcontentsline{exp}{examples} {\protect\numberline{\theexamples}#1}\par}however…
1. If I set example numbers to include chapter, than in the table of contents the example number overlaps with the text (i.e. the numwidth is not properly set).
2. Also, I would like to have an extra space in between the examples from various chapter.
Thanks
September 4th, 2008 at 3:29 am
Hi! thanks for the great blog! I have a question. I have document with Chapters 1, 2, 3, and sub sections 1.1 1.2…. 2.1, 2.2 … so on.. How do I set a counter for a figure X that belongs to Chapter Y and subsection Z, so that its number will appear as Figure Y.Z.X ?
September 4th, 2008 at 3:32 am
… and basically same question for tables…
September 11th, 2008 at 11:50 am
Hi!
What you would need to do is the following.
Define a new counter:
\newcouter{myfigure}and tell Latex how you want your figure counter to look like:
\renewcommand{\thefigure}{\addtocounter{myfigure}{1}\thesection.\themyfigure}%If you want Latex to reset the counter everytime you start a new chapter you need to add this piece of code:
\makeatletter \@addtoreset{myfigure}{chapter} \makeatotherHope this is what you were looking for,
Tom
September 11th, 2008 at 11:26 pm
Thanks a lot!
September 20th, 2008 at 12:20 pm
Tom,
Your last tip can solve Troy C.’ s problem :
To change chapter number each time changing part, add in your preamble
\makeatletter \@addtoreset{chapter}{part} \makeatotherOctober 3rd, 2008 at 8:51 am
Hi,
I am writing a book that contains a certain number of tables and figures.
I would like to include the total number of figures and the total number of tables in the front page.
I was wondering if there is way to do so automatically.
Thanks in advance.
October 5th, 2008 at 7:06 pm
Hi,
Thanks for your question, which was rather tricky to answer
. The problem is, that you first have to run through the document in order to know the number of figures.
I propose you write a macro with the code given below, so you don’t mess up your tex-file:
1. Open a new text-file and call numberfigure.sty.
2. Copy-paste the code below into the file and save it.
3. Add the
numberfigurepackage to your Latex-document.4. Use
\pageref{NumberFigures}to print the number of figures.I have to admit, the solution is not very nice and I would be happy if someone who is familiar with macros would post a better solution.
Here is the macro code for numberfigure.sty:
\newcounter{myfigure} \setcounter{myfigure}{0} \newcommand{\mycaption}[1]{ \stepcounter{myfigure} \caption{#1}} \def\numberfigures@putlabel{\addtocounter{myfigure}{0}% \immediate\write\@auxout{\string \newlabel{NumberFigures}{{}{\themyfigure}}}% \addtocounter{myfigure}{1}} \AtEndDocument{% \clearpage\numberfigures@putlabel}% \endinputCheers,
Tom
October 10th, 2008 at 8:41 am
It worked!!! Not only for the tables and figures, but also for a user-defined floating environment as well. Thanks a lot for your prompt help.
October 15th, 2008 at 9:26 pm
[...] I recently posted a comment on how to count the number of figures within your document. View [...]
February 6th, 2009 at 11:18 pm
Hi,
I’m a little stuck with list numbering. I’m creating a list of assumptions in a paper. However, I would like the assumption counter to reset ONLY when the chapter number changes. In other words, I’d like the text to read:
Chapter 1, Section 1
~
Assumption 1.1
Assumption 1.2
~
Chapter 1, Section 2
~
Assumption 1.3
Assumption 1.4
~
Chapter 2, Section 1
~
Assumption 2.1
~
Currently though, the assumption counter resets every time I call the assumption environment. Here’s my code for the environment:
\newcounter{assump} \newenvironment{assumption} {\begin{list}{Assumption \arabic{chapter}.\arabic{assump}:} {\usecounter{assump}}} {\end{list}}I’ve tried adding “[chapter]” to the end of the counter definition, but it still doesn’t ensure that the counter is reset only when the chapter changes. Any ideas? Thanks!
February 8th, 2009 at 1:44 am
Ah, nevermind, I figured out a way around it. I added a new counter using
\newcounter{assumpt}[chapter]which keeps the total of the assumptions in a chapter. Then I changed the last two lines of the above code to:
{\usecounter{assump}}\addtocounter{assump}{\value{assumpt}}} {\end{list}\setcounter{assumpt}{\value{assump}}}Thanks though!
March 16th, 2009 at 5:29 pm
Hi again,
I have finished the book I was writing (Programming in MATLAB). The book is written in greek. Now, I am trying to generate a multilingual index (greek + english) using makeindex package without success. Can you give me any suggestion on which package do I have to use?
Thanks in advance.
February 28th, 2010 at 10:52 pm
[...] applied some logic! It’s very useful to know that LaTeX has a counter for everything. This particular post was very helpful in working out which ones to alter, and how. Share and [...]
May 1st, 2010 at 10:04 pm
Hi, I hope your help.
I need to numbering the front pages of a document in Latex by I,II,III,IV,…
Thanks for your help
May 2nd, 2010 at 1:45 pm
Hello!
Use
\pagenumbering{Roman}and
\pagenumbering{arabic}Tom.
May 3rd, 2010 at 11:24 am
thank you for help me.. but I dont need this numbering in the full document only in the first pages befor my chapters
can you help me again??..
May 3rd, 2010 at 9:48 pm
Then just use the command several times whenever you want to change the style. In the beginning you start with:
\pagenumbering{Roman}and when you need arabic, do:
\pagenumbering{arabic}to switch back.
Try it!
Cheers,
Tom
May 3rd, 2010 at 10:41 pm
Thank you very much for your interest ..
I look forward to help you later.
June 14th, 2010 at 3:11 pm
Hello,
I have a big problem, if I add the figure in my latex document, this figure be in the wrong place. My code is
\begin{figure} \centering \includegraphics[scale=0.2]{Ha.pdf} \caption{hyperplane} \label{labelname} \end{figure}Regards,
June 14th, 2010 at 7:02 pm
Tom,
I’ve made my own environment for Examples. I followed your advice above (see post : Application about adding sections and chapters to numbering).
Although the numbering is working, referencing examples does NOT work (that is, whenever I reference an example, it always says “1″).
I want to examples to be like
Example 1.3
Example \thechapter.\theexample
and I want to reference them in the same manner: e.g. Please see Example 2.27.
Thanks for help. Code follows.
\newcounter{example}[chapter] \newcounter{myexample}[chapter] \renewcommand{\theexample}{\addtocounter{myexample}{1}\thechapter.\themyexample} \makeatletter \@addtoreset{myexample}{chapter} \makeatother \newenvironment{example}[1][] { \ifx&#1&% \par\medskip\noindent\textbf{Example~\theexample.} \rmfamily \else \par\medskip\noindent\textbf{Example~\theexample ~{\normalfont (#1)}.} \rmfamily \fi } {\blank\hfill$\LHD$\vspace{1ex}\medskip}June 19th, 2010 at 10:30 am
Hi Paul,
It seems what you are looking for is this.
Cheers,
Tom
June 28th, 2010 at 12:23 pm
[...] and some credits: I wouldn’t come up with a solution if I haven’t read this post, and this website. Huge thanks to the authors for their tips! 60.388072 5.331851 [...]
September 23rd, 2010 at 1:34 am
Thank you for this great help.
October 25th, 2010 at 10:02 am
This a really great writeup by the author looking forward to come back more very soon.
December 14th, 2010 at 8:13 pm
Hello for all,
I want to ask you blease.
How can I add the first pages (i-ii-iii- ….etc) to Contents in latex
thanks for help me
November 8th, 2011 at 3:44 pm
Hi Tom,
thanks for the great tips. I am having an issue with custom section numberings and I was hoping you can help me with that.
In a standard document (not book, etc), I wanted to number sections as “S.1″, “S.2″, etc. and Appendices as “S.A”, “S.B”, etc.
Do you know how this can be done?
Thanks!
November 9th, 2011 at 3:34 am
Hi there,
You can use this:
\renewcommand*{\thesection}{S.\arabic{section}} ... \begin{appendix} \renewcommand*{\thesection}{S.\Alph{section}} ... \end{appendix}In case you are using
\tableofcontents, you may also need to change the space between the number an the heading:\usepackage{tocloft} \setlength{\cftsecnumwidth}{2.3em}Best, Tom.
November 10th, 2011 at 10:05 am
Hi tom,
I am new to latex, we are creating a pdf which consists of tables. when the table row contains more information its is getting overlapped with the pdf footer. here we are using longtable for table creation.
Please suggest a solution for not to overlap with the footer.
Thanks,
Prasad.
November 10th, 2011 at 10:30 am
Hi Prasad,
A
longtableautomatically “breaks” tables that are too long and reach into the margin. You can find some sample code here that may help you setting up yourlongtableproperly. Best, Tom.November 10th, 2011 at 12:05 pm
Hello Tom,
Whats happening in my case is i have a row data which will not fit into a single page. In this case its over lapped with footer and it is not continuing to next page.
Thanks in Advance,
Prasad.
November 16th, 2011 at 8:56 am
Hi Prasad,
I see what your problem is. However, I don’t know how to solve it, sorry. I tried various things without success. Maybe somebody else can help…
Cheers, Tom.
November 23rd, 2011 at 10:44 am
Hello,
I have a problem in finding wether a pdf file is already opened by the user or not.
Can any one help me?
Prasad.
November 24th, 2011 at 3:46 am
Hi Prasad,
I’m not sure what you are trying to do. Is your goal to check if a file to be included in a Tex-document is readable? This page shows how to check if a file that you want to include exists.
Best, Tom.
November 25th, 2011 at 3:46 pm
Dear Tom,
From the blog, it seems that you are the guy who can help me..:) I need to number my figures in following 1,2a,2b,3,4….. way. As I understood, I have to use
\newcouter, this kind of stuff. But I could not figure out how to do it properly. Here is my code :\begin{figure}[h!] \centering \includegraphics[clip=true,width=8cm]{vac_tim_5.eps} \caption{Time dependence of the number of defects.} \label{fig2} \end{figure} \begin{figure}[h!] \centering \includegraphics[clip=true,width=8cm]{vac_tim_6.eps} \caption{Time dependence of the number of defects. The curves are averages of twenty irradiations.} \label{fig3} \end{figure}I would like to put the label as 2a and 2b then again 3, 4….
please help.
regards
Ullah
November 28th, 2011 at 3:52 am
Hello!
I suppose the two figures (a) and (b) belong together and should be displayed together? Please have a look at the
subfigpackage, which is a much cleaner way to generate sub-figures and automatically numbers the figures the way you want.Here is a post I wrote some time ago about
subfigincluding sample code. You may also want to have a look at the package documentation.Let me know if you have any more questions.
Best, Tom.
November 29th, 2011 at 6:20 pm
Hello,
Thanks a lot for you reply. These documents will help me for sure. But, I need to make two different figures with two different captions and labels, (a) and (b) don’t belong together. Some complete different figures in different places of the article like 1,2,3,4,5.. except I want to make it like 1,2a,2b,3,4,5… one figure after another figure, with there own caption. By doing normal way I can make figures and Latex number them automatically Fig1, Fig2, Fig3…. But I want to have Fig1, Fig2(a), Fig2(b), Fig3….
I guess, this time I made it clear..:)
thanks in advance..
cheers
Ullah
November 30th, 2011 at 6:03 am
Hey Ullah,
I put together some code that will modify
\thefigurethe way you need it. Put it into your preamble.\let\thefigureold\thefigure \newcounter{mysubfig} \newcounter{const} \newcommand{\modfig}{ \setcounter{mysubfig}{1} \setcounter{const}{\thefigure} \addtocounter{const}{1} \renewcommand{\thefigure}{\theconst\alph{mysubfig}\addtocounter{mysubfig}{1}}} \newcommand{\resfig}{ \setcounter{figure}{\theconst} \let\thefigure\thefigureold}The only thing you have to do now is to call
\modfigto start the subfigure numbering and\resfigto stop it and continue normal figure numbering.Best, Tom.
November 30th, 2011 at 10:18 am
Hi,
Thanks a lot. I feel there is some bug in the code or may be I am too novice to understand.:( When I call \modfig and \resfig in the first figure it gives 1a number. But when I call at the beginning of my second figure and close at the end of third figure, it gives 2b and 2d. where I was expecting 2a and 2b. But I found another blog, and I fixed it now..in the following way..
In to preamble:
\usepackage{subfigure} \newcounter{subfigure1}Then at the beginning of the 2nd figure
\renewcommand{\thefigure}{\arabic{figure}\alph{subfigure1}} \setcounter{subfigure1}{1} \begin{figure}[htb] ......then beginning of the third figure
\addtocounter{figure}{-1} \addtocounter{subfigure1}{1} \begin{figure}[h!] ......and at the end to continue normal figure numbering.
\renewcommand{\thefigure}{\arabic{figure}}this gives me 1,2a,2b,3,4,5 …..
regards
Ullah
November 30th, 2011 at 10:48 am
That looks good and makes sense in case you use it once only.
By the way, you don’t need to load the
subfigurepackage, it’s not needed here.Best, Tom.
December 8th, 2011 at 4:45 am
Hi Tom,
I have seen ur solutions in this blog.They are helpful to me a lot.I have some problem regarding the alignment of numbers in listoffigures.The number and title are overlapping.I couldnot figure it out.Could you help me to solve this issue.
December 12th, 2011 at 1:57 pm
Hi usha,
Please have a look at the tocloft package and the comments on this post (e.g. here).
Best, Tom.
February 8th, 2012 at 6:37 am
(Moved here by Tom.)
Is there a simple way to have counters (e.g., equations) in a document pick up where the previous document left off? Obviously, I can always manually set the counter at the beginning of the new doc, but discovery of the xr package got me to thinking that perhaps there’s a similarly automated way to do this.
Thanks!
AJ
February 8th, 2012 at 6:42 am
Hey Alec,
I moved your comment to this more suitable post. So here is my response. I tried quite a few things and I could not find a simple way to use counters across multiple documents. You could give the
zrefpackage a try (documentation).In some cases,
includemay do the job. You can compile a list of individual tex-files once, generating all the counters, page-numbers and labels correctly. They will be stored in meta-files (e.g. *.aux). Next, you compile only a subset (one or more) usingincludeonly:\documentclass[11pt]{article} \includeonly{file2} \begin{document} \include{file1} \include{file2} \include{file3} \end{document}Best, Tom.
February 8th, 2012 at 4:22 pm
Thanks so much! I’ll give it a try.
best,
Alec
February 8th, 2012 at 4:41 pm
Sure, good luck
. Tom.
March 21st, 2012 at 4:23 am
Hi,
I was curious to know that is there any possibility that I manage to have two different kind of numbering for figures. For example I have a picture of a table and I want to have a separate numbering for figures of tabels!
Sincerely,
March 21st, 2012 at 5:12 am
Hey,
Have a look at the
trivfloatpackage. Also, here is a code example in the comments of this previous post on defining your own list of….Let me know if you have any problems.
Best, Tom.
April 4th, 2012 at 4:12 pm
Hey,
Thank you for usefull information.
I see that you are pro in latex docs, so I would like to know if there is a possibility to show the equation counter on a different side of a document, because it is on the right side of a page by default.
I am looking forward to hearing from you.
April 5th, 2012 at 5:50 am
Hey!
You can use the documentclass option
leqnofor equation numbering on the left side. Here is an example:\documentclass[12pt, leqno]{article} \begin{document} \begin{eqnarray} f_1(x) & = & a_1+b_1x+c_1x^2\\ f_2(x) & = & a_2+b_2x+c_2x^2 \end{eqnarray} \end{document}Best, Tom.
April 5th, 2012 at 10:23 am
Works. Thank you very much.
April 5th, 2012 at 1:59 pm
You are welcome. Tom.
April 12th, 2012 at 10:50 am
Is there a way to count the number of entries in a bib file? I am writing my CV and wished to have something like:
Oral Presentations (3):
Reference1
Reference2
Reference3
Poster presentations (4)
Reference 4
Reference5
Reference6
Reference7
What I want is to print the numbers inside the parentheses (oral presentations are in oral.bib and poster presentations are in poster.bib)
Thanks
April 12th, 2012 at 4:54 pm
Hi Filipe,
Here is a minimal working example. It’s certainly not the most efficient way to do it, but it works. You’ll have to run “bibtex poster” and “bibtex oral”. Best, Tom.
\documentclass[11pt]{article} \usepackage{multibib, totcount} \newtotcounter{oralcount} \newtotcounter{postercount} \newcites{poster,oral}{% Poster Presentations (\protect\total{postercount}),% Oral Presentations (\protect\total{oralcount})} \def\oldciteoral{} \let\oldciteoral=\citeoral \def\citeoral{\stepcounter{oralcount}\oldciteoral} \def\oldciteposter{} \let\oldciteposter=\citeposter \def\citeposter{\stepcounter{postercount}\oldciteposter} \begin{document} First poster reference: \citeposter{posterref2012} Second poster reference: \citeposter{posterref2011} First oral reference: \citeoral{oralref2012} \bibliographystyleposter{plain} \bibliographyposter{poster} \bibliographystyleoral{plain} \bibliographyoral{oral} \end{document}April 16th, 2012 at 9:55 am
What if I use \nocite? I only get 0′s… I wish to count the entries in the bib file. is that possible?
April 17th, 2012 at 3:48 pm
Hi Filipe,
The command
nociteis tricky. Try the biblatex package which offers great flexibility. Furhtermore, you may find these answers to a somewhat related question useful.Best, Tom.
April 17th, 2012 at 4:07 pm
Actually I did change every \cite… to \nocite… and it works perfectly. The only thing I which it could do additionally would be instead of having to add every reference by by hand using the \nociteoral{ref1}\nociteoral{ref2}\nociteposter{ref3}… i could just \nociteoral{*}\nociteposter{*} but sadly it won’t work…
April 18th, 2012 at 10:39 am
Thanks for the follow-up. Indeed, according to the documentation, the star as a placeholder for all references in a bib-file was not implemented. Best,Tom.
December 7th, 2012 at 7:14 am
Great blog!! This may not have a solution (possibly, due to it’s narrow application base):
I am writing up mathematical models in LaTeX [i.e. a lot of equations] and then coding up models in Java/C++/C algorithm for implementation. To keep track of which part of code belongs to which equation, I comment the code with the related equation number [company policy!!]… this works when document is growing from the bottom. However, I now have to go back and add sections here and there in document, which screws up numbering and my code comments. The only solution I can see to dynamically link my equation numbers to my code is the following:
1) Label each equation (100s of ‘em) inside LaTeX and in relevant code
2) Utilize *.aux file + script to extract labels and equation number
3) Run code through another script to append new eqn number to label
But is there some better way to extract equation numbering without labeling everything in LaTeX? From what I can tell, only if I label equations do they appear in *.aux file.
Or for short-term solution, is there a way to keep old equations numbers and just increment LaTeX counter for every additional equation — to avoid overwriting old equation numbering?
Any ideas? Thanks in advance!!
December 8th, 2012 at 7:48 am
Hi Mads,
Thanks for your interesting question. I don’t know the exact policy of your company on identifiers. In case you can use any identifier format (e.g. no consecutive numbering, etc.), I suggest using the equation label, since it remains the same when the document is changed. Using the showlabels package, you can print the label into the margins for example.
Since you have so many equations, you might also find the catchfilebetweentags package useful. It lets you store chunks of code in a text file and load them. I’m not sure if this is useful, but with this package you might even be able to automatically fetch the code of the equation implementation and add it to the LaTeX document using listings.
In case you prefer using the actual equation numbers, say because you have a list of equations, what comes to my mind is use any of the tocloft commands to change the entries and extend it to write the equation numbers to a file that is easily parseable.
Hope you find my thoughts useful. I’m sure you’ll find a solution that suffices the requirements and is convenient.
Cheers, Tom.
December 10th, 2012 at 11:03 am
Is it necessary to be a code number or could it be a code name? If so, it would be rather easy just to set names… Can you do that? (That must be exhausting do, to name hundreds of equations…) I can’t think of any other way to do it besides that outer script you mentioned.
January 4th, 2013 at 11:28 am
Hi.
Is there a way to compute the actual (or physical) page count (current and possibly last)?
Or, otherwise phrased, is there a {globalpage} counter that is indifferent to anything the user does to the {page} counter?
To clarify the question suppose you reset counter{page} as you go (e.g., preface in roman+body in arabic, as found in many texts, or you use the \include{} command and skip some sections).
Suppose now that for typographical reasons you would like to understand whether the last page is a multiple of 4 or not (as to insert extra blank pages, for example). If the page counter is never reset, that’s easy. But if the page counter does get reset, this becomes a problem.
January 8th, 2013 at 11:17 am
Hi Oskar,
An interesting question. Yes, there is a way to determine the absolute number of pages using the zref package. Here is how:
\documentclass[11pt]{article} \usepackage[user, lastpage, abspage]{zref} \usepackage{blindtext} \pagestyle{plain} \begin{document} \pagenumbering {roman} \tableofcontents \clearpage \section{Test} \pagenumbering {arabic} Last page number: \zpageref{LastPage}; absolute page number: \zref[abspage]{LastPage}. \end{document}March 26th, 2013 at 2:37 am
In this blog, I found that I can change my page numbering from arabic to roman. But in my thesis, cover page must be without page number then few pages in roman page numbers and then rest of pages english numbers.
http://ashishrevar.com/2010/09/latex-redefine-numbering-in-figure-caption/
This page is only useful to change the number style but how to unset page numbers in cover page?
March 26th, 2013 at 3:21 am
Hi Disha,
Try the following to switch off page numbering for the first few pages.
\documentclass[11pt]{report} \usepackage{blindtext} \begin{document} \pagenumbering{gobble} \tableofcontents \clearpage \pagenumbering{arabic} \chapter{First} \Blindtext \end{document}April 18th, 2013 at 5:16 pm
I am using \begin{multline}…\end{multline} for some very long equations that span more than 60 lines. I would like to refer to specific lines in such equations. I have defined a counter, incremented it, and print a small number after each line. To avoid manual referencing of the lines I would like to refer to, I have attempted to use the \label command along with \refstepcounter. While this works fine outside the equation environment, it does not work within the multline. Any suggestions for this unusual application?
April 19th, 2013 at 2:15 am
Hi Casey!
Thanks for this question. In fact, you could just use align. See the example below.
\documentclass[11pt]{article} \usepackage{amsmath} \begin{document} \begin{align} y_1&=a_1x_1+b_1 \label{eqn:one} \\ y_2&=a_2x_2+b_2 \nonumber \\ % omit number y_3&=a_3x_3+b_3 \label{eqn:three} \end{align} See \ref{eqn:one} and \ref{eqn:three}. \end{document}April 19th, 2013 at 12:16 pm
Hi Tom,
Align will not do the job because the 60+ line expression is indeed one equation and thus needs to be numbered along with the other equations in the document consistently. What I need to do is to refer to individual lines within this one equation. Thus I needed embedded numbering that can be referenced. Sorry for not being more clear.
April 20th, 2013 at 7:15 am
Hi Casey,
Please provide a minimal working example and I’ll try to help you with the problem.
Tom.
April 22nd, 2013 at 2:40 pm
\documentclass{article} \usepackage{amsmath} %.....Tiny line numbering for long equations \newcounter{eqnline}[equation] \newcommand{\eln}{\stepcounter{eqnline}\hfill \hbox{\tiny{\theeqnline}}} \begin{document} Here is a minimal example: \begin{multline} a = b + \dots \eln \\ c + d \dots \eln \\ e + f \dots \eln \\ \dots+g + h \dots \end{multline} The real application has a single equation that spans more than 60 full lines, and I would like to be able to refer to the line numbers using a label construct within the equation, which I number using a defined counter as shown above. \end{document}April 24th, 2013 at 4:44 pm
Thanks for the code! The code below works (apart from hyperref, which I didn’t test). I took the idea from here. HTH, Tom.
\documentclass{article} \usepackage{amsmath,refcount,makerobust} \newcounter{eqnline} \newcounter{refeqc} \let\textlabel\label \newcommand{\eln}{% \begingroup \refstepcounter{eqnline}\mylabel{\theeqnline}\hfill \hbox{\tiny{\theeqnline}}% \endgroup} \newcommand{\mylabel}[1]{\textlabel{lnl:#1}} \newcommand{\eqqref}[1]{% \setcounterref{refeqc}{#1}% Line $(\arabic{refeqc})$} \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}April 24th, 2013 at 6:09 pm
Thanks Tom! This solution will work.