Using a single count for figures and tables in LaTeX - latex

I've been given a LaTeX document to edit with the following code for using a single count for figures and tables.
\makeatletter
\newcounter{unisequence}
\def\ucaption{
\ifx\#captype\#undefined
\#latex#error{\noexpand\ucaption outside float}\#ehd
\expandafter\#gobble
\else
\refstepcounter{unisequence}
\expandafter\#firstofone
\fi
{\#dblarg{\#caption\#captype}}
}
\def\thetable{\#arabic\c#unisequence}
\def\thefigure{\#arabic\c#unisequence}
\makeatother
This works well to give a single counter for captions of tables and figures but, I find that if I click on any of the caption numbers in the .pdf this code generates, I am always returned to the first figure or table in the document rather than the one I want, e.g. clicking on in Table [3] will take me to Table 1 instead.
Does anyone know how to fix this? Or can anyone advise an alternative?
I am a LaTeX newbie.
Thanks
Mr Morgan.

Based on https://stackoverflow.com/a/3866061/53974 and https://tex.stackexchange.com/a/127744/1340, we can just (1) make the table counter be the same as the figure counter, and (2) make the table float type be the same as the figure float type, to ensure that the ordering is consistent with the numbering, because:
LaTeX keeps all floats of the same type in order
Code:
\makeatletter
\let\c#table\c#figure % for (1)
\let\ftype#table\ftype#figure % for (2)
\makeatother
Compared to https://stackoverflow.com/a/3866061/53974, this keeps \thetable and \thefigure aloneā€”so the table and figure numbers are kept formatted as-is. This respects per-chapter/section numbering, and it works for me well together with hyperlinking, the subcaption, float and rotating packages, and probably more, on a 160-page document.

If it's of use to anyone, use:
\makeatletter
\renewcommand*{\thetable}{\arabic{table}}
\renewcommand*{\thefigure}{\arabic{figure}}
\let\c#table\c#figure
\makeatother
In the preamble of your document.

Off the top of my head, this is a problem of the snippet you have there not generating the correct reference. See here, for instance: http://en.wikibooks.org/wiki/LaTeX/Hyperlinks

Combining the code in the query with a previous answer worked wonderfully for me - thank you.
To get the figures and tables numbered consecutively within chapters with chapter numbers too, I replaced two lines in the answer snippet by
\renewcommand*{\thetable}{\arabic{chapter}.\arabic{table}}
\renewcommand*{\thefigure}{\arabic{chapter}.\arabic{figure}}

Related

Add a custom word to a cross reference in LaTex

Good morning!
I've been searching for a time but I can't reach a solution to my problem. I'm writing my master thesis, and I want to add custom words to my references, I mean, if I want to ref the only table in my document (\label{table:test} for example), I usually do \ref{table:test}, getting as a result just a clickable number 1.
However, I need to set a global option in order to, always I refer to a table, for example, I get {custom word} 1(1 for the first table). This custom word surely will be Table, but I can desire to use Figure(in English) or Imagen (in spanish), for ref figures.
Thanks you very much in advance!
The cleveref package will automatically add the correct words and adapt to the language of your document:
\documentclass[spanish]{article}
\usepackage{babel}
\usepackage{hyperref}
\usepackage[noabbrev,nameinlink]{cleveref}
\begin{document}
\begin{figure}
\caption{content...}
\label{key}
\end{figure}
\cref{key}
\end{document}

Last-page column equalization for latex IEEEtran class?

In the documentation for the IEEEtran LaTeX class, it's mentioned that the two columns on the last page need to be manually adjusted in order to be balanced (have the same length).
I see that \newpage will allow me to break the first column so the rest of the content is on the second column. This allows for paragraph-level equalization, and looks good, but I'm having trouble with line-level equalization, that is, breaking the column by lines instead of by paragraphs.
When I insert \newpage in the middle of a paragraph (instead of between paragraphs), LaTeX effectively splits the paragraph in two. The second part goes to the top of the second column (as desired) and the first part remains in the first column. There are two issues I've found with this, and I've only solved one of them.
The first issue is that the partial paragraph on the top of the second column is treated by LaTeX as a new paragraph, so it's indented. I fixed this by adding \noindent after \newpage so that it's not indented.
The second issue is that for the partial paragraph in the first column, the paragraph is justified (as expected), but the last line is ragged (no justification). Is there a way to force justification of this last line? LaTeX has environments and commands to disable justification, but I can't find anything to fully justify a paragraph, including the last line.
Two possibilities:
Ending a line with \linebreak will force the line to be justified, no matter how empty it is.
To do what you are trying to do you could replace \newpage \noindent with \linebreak \newpage \noindent.
Note this will create a blank line before the end of the page, which may or may not be a problem. In certain cases it could create an empty page between your pages.
Another option would be \pagebreak. It tells LaTeX to start a new page when you get to the end of the current line. You don't have control of the exact word where the page break occurs.
What about making the last page (column) shorter using
\enlargethispage{-50mm}
and maybe forcing LaTeX to split after the appropriate line? Of course the amount of shortening should be guessed by trial and error, and re-guessed after changing the text. (Just an idea, may be impossible to implement in your case.)
(Posting for the googlers landing here)
The quickest solution is
\usepackage{pbalance}
(Package documentation at https://ctan.org/pkg/pbalance?lang=de)
In case that does not work, one can try the special command \IEEEtriggeratref{10}, which adds a column break before reference 10. Replace 10 by the actual number of the reference. See the documentation of IEEEtran, section "XIV. Last Page Column Equalization" for more details).
You can adjust the following lengths to make LaTeX fill the last line of a paragraph. Put this in your preamble:
\newcommand{\filllastline}[1]{
\setlength\leftskip{0pt}
\setlength\rightskip{0pt}
\setlength\parfillskip{0pt}
#1}
Then in your document do this:
\filllastline{The text for your partial para in 1st col goes here...}
(For future LaTeX questions you should probable post to https://tex.stackexchange.com/)

Use fancyhdr in Lyx to position page number

I am trying to customise the position of the page number to make them all appear at the bottom centre in Lyx. I plan to use the fancyhdr package in the preamble section of the document, but I get the following error msg:
'LaTex Error: Command /footruleskip already defined'
I guess it has something to do with me forcing a footnote formatting which may already be defined by fancyhdr package, as i have the following in my preamble:
\setlength{\skip\footins}{0.8cm}
Any suggestion how I get around this problem and set the page number position together with the footnote setting? Many thanks.
This link should help: http://en.wikibooks.org/wiki/LaTeX/Page_Layout#Customising_with_fancyhdr. You can use the lhead, chead, rhead, lfoot, cfoot and rfoot commands to tell it what you what where (section names, page numbers, custom text, etc). I think you still need to specify them even if they are empty. For only a page number at the bottom center, that would be:
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\lhead{}
\chead{}
\rhead{}
\lfoot{}
\cfoot{\thepage}
\rfoot{}
Perhaps your error could be fixed by using \renewcommand instead of trying to define an already existing value.
I'm trying to do my thesis with LyX and small problems like this are killing me because of having to adhere to the strict format of my school. Anyhow, this page came up as I searched for over an hour for the answer to your question. I'm using the memoir layout (kind of, I've already had to edit it) because my school's latex .cls file is supposedly based on memoir.cls (which I couldn't get to work correctly with LyX despite hours of persistence). I ended up putting this code into my preamble and it displayed the page numbers in the bottom-center per my formatting requirements.
\makeevenfoot{headings}{}{\thepage}{}
\makeoddfoot{headings}{}{\thepage}{}
\makeevenhead{headings}{}{}{}
\makeoddhead{headings}{}{}{}
Hope this helps anyone else that finds this page. Now if I can just figure out how to tell LyX that I have no chapters and I want sections to be 1 instead of 0.1. I'll probably just use section* and call my sections "Section" #. Anyway, I hope this helps someone who is as close to punching themselves in the face for using LyX as I am.

Is there a way to get LaTeX to place figures and tables in the order they are referenced in the text?

I think this question is novel. Here is the problem I have. I have a relatively short piece of text associated with a lot of figures and a table. I want floats to appear on pages just for floats but in the order I specify. I have set all of the table and figure parameters to [hp] and placed them in the order I want them to appear in the source e.g.
Figure 1
Figure 2
Figure 3
Table 1
Figure 4
Figure 5
The problem I have is that no matter what I do the document typesets like this
Table 1
Figure 1
Figure 2
etc....
I have tried trashing the Aux files before typesetting. I am aware of the endfloats package but I still want latex to place the floats in between larger sections of txts in other parts of the document. Any help is greatly appreciated.
Thanks
I'll try to explain why the fix by #user476160 (placement modifier hp instead of just p) works. A figure is a float, i.e. an element that cannot be broken across a page. The figure environment accepts a parameter list with placement hints:
\begin{figure}[placement parameters]
% ...
\end{figure}
The placement specifier h stands for here and places the figure approximately at the same point as in the source text. The placement specifier p puts the figure in a special page that contains only floats:
\begin{figure}[hp]
% ...
\end{figure}
Wikibooks has an excellent article on figure placement if you want to fine-tune your figure and table placement.
I also recommend posting LaTeX-related questions in the TeX Stack Exchange Q&A.
Problem solved, the first figure in my list had the parameter [p] rather [hp]. This seemed to cause latex a lot of grief for some reason. Anyhow problem solved for now. The figures and txt all appear in the order I have specified.
It is quite easy. All you have to do is use this package.
\usepackage{float}
And you have to change the figure parameters to
\begin{figure}{H}
%..
\end{figure]}
Let me know if it works :)

Three columns frame in a big document and renaming stuff in latex

I'm just learning latex, so this may be trivial to some of you.
I went through a few tutorials but they all seem to cover the same things.
I'm writing a big report - calculation all the way (and it has to be neat, because it's part of the documentation). It consists of a frame around the page (15mm margins), and 3 columns inside it: in the left column (3cm wide) are references from where the equation came from (e.g. "ABS 3-2-7"), in the middle is the calculation and in the right is the accepted value (5cm wide). It is a standard way of doing things, so I don't have a choice over the layout.
Now, I don't understand, how would I go in creating such layout ? The frame with columns has to appear on every page. How to accomplish that ?
I've never seen such a document so I'm not sure how to ease the creation.
And second, how do I rename things that are in english language in document classes ? For example, "article" class, I have "References" and I need to have "Literatura".
Is there a way to rename it without touching .cls file?
For your first problem, look at the longtable package (available at ctan.org if you haven't already got it installed)
The problem with using tabular is it won't work as you want across pages.
As far as the second problem, it will depend on the environment and the document type, but typically you'll have to renew a command.
For example, add to the preamble \renewcommand\refname{Literatura} for the article class to do what you were asking for. If I recall correctly it is bibname for books.
Table design in LaTeX has not been made very easy. I would use tabbing rather than tabular and draw the lines manually to keep things simple. A downside is that you don't get any automatic sizing of the table cells, but since your format is fixed, I would consider it a good thing (i.e., if text overflows, you notice it and get to fix it yourself, and your table doesn't accidentally get stretched into the margins). If you use multiple tables like this in your document, try packaging the commands with \newenvironment.
\documentclass{article}
\usepackage[margin=15mm]{geometry}
\usepackage{amsmath}
\usepackage{calc}
\newlength{\tableheight}
\setlength{\tableheight}{20cm} % how high to draw the lines of the table
\newlength{\rulethickness}
\setlength{\rulethickness}{1pt} % how thick lines to draw
\newcommand{\verticalline}{\smash{\rule[-\tableheight]{\rulethickness}{\tableheight}}}
\newlength{\myindent}
\setlength{\myindent}{3mm} % how much to indent each column
\newlength{\leftcolumn}
\setlength{\leftcolumn}{3cm-\myindent}
\newlength{\midcolumn}
\setlength{\midcolumn}{\textwidth-3cm-5cm-\myindent-\rulethickness}
\newlength{\rightcolumn}
\setlength{\rightcolumn}{5cm-\myindent}
\begin{document}
\begin{tabbing}
% first set the tab stops
\hspace*{\myindent}\=\hspace{\leftcolumn}\=%
\hspace{\myindent}\=\hspace{\midcolumn}\=%
\hspace{\myindent}\=\hspace{\rightcolumn}\=\kill
% then draw the lines
\rule{\textwidth}{\rulethickness}\\[-\baselineskip]
\smash{\rule[-\tableheight]{\textwidth}{\rulethickness}}\\[-\baselineskip]
\verticalline\>\>\verticalline\>\>\verticalline\>\>\verticalline\\
% Now start the table: indent the first column with \>
\>ABS 3--2--7
% ... and each additional column with \>\>
\>\> $\iint_{-\infty,-\infty}^{\infty,\infty} e^{-x^2-y^2}\, dx\,dy$
\>\> 2.507
% End each line with \\, add e.g. [2pt] to get 2pt extra space if required
\\[2pt]
% here's another line:
\>ABS 3--2--8 \>\> $\displaystyle\sum_{k=0}^n k^2$ \>\> $\frac12 n(n+1)$ \\
% etc. Be careful not to overflow the table - there's no automatic check for that.
\end{tabbing}
\newpage % also remember to start a new page after the table
\end{document}
To change the fixed names, see this FAQ, or possibly this one if you are using babel.
In this case you probably want to use the tabular environment to generate the three columns (or as simon notes longtable if your report-thingy runs longer than one page). Something like:
\framebox{
\centering
\begin{tabular}{p{3cm}|p{\specialwidth}|p{5cm}}
Ref 1-0-0 & 1.2345 & 1.2346 \\
Ref 1-0-1 & 2.3456 & 2.3454 \\
...
\end{tabular}
}
You'll note that I've used paragraph formatted columns (the p{<length>} formatting specifiers), and stuck a frame around it with \framebox.
You can either compute \specialwidth by hand, or calculate it:
\newlength{\specialwidth}
\setlength{\specialwidth}{\textwidth}
\addtolength{\specialwidth}{-10cm} % extra room for the seperators...
I can't help you on the internationalization issue...

Resources