0

I have created a flow chart in Latex by 'tikz' package. Besides, there are many figures in my paper, and I used 'graphicx' package to auto-number these figures.

However, if I want to auto-number the flow chart together with other inserted figures, could anyone please help me how to achieve that?

I put my code of flow chart here:

\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=white]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=white]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=white]
\tikzstyle{arrow} = [thick,->,>=stealth]



\begin{tikzpicture}[node distance=2cm]

\node (in1) [io] {unit cell};
\node (pro1) [process, below of=in1] {vc-relax (pw.x)};

\draw[arrow](in1)--(pro1);
\end{tikzpicture}

And my code for auto-number figure:

\usepackage{graphicx}


\begin{figure}
    \centering
    \includegraphics{a.jpeg}
    \caption{Caption}
\end{figure}

Thanks!!

Ryan Gao
  • 1
  • 1
  • 3
    Place the tikzpicture inside of a figure environment. – leandriis May 12 '20 at 19:54
  • 1
    The graphicx package has nothing to do with the figure environment and caption numeration. Demonstration: \documentclass{article} \begin{document} \begin{figure} \hfil whatever \caption{caption of whatever} \end{figure} \end{document} – Fran May 12 '20 at 20:05
  • @leandriis Thanks! It works!!! – Ryan Gao May 12 '20 at 20:24
  • @Fran that is the answer (and this is a common misconception so I think it is worth an answer not just close as "solved in comments") do you want to post it as an answer? oh or leandris :-) – David Carlisle May 12 '20 at 20:33

1 Answers1

2

The graphicx package allow the insertion of external images (in png, jpg or pdf format using pdflatex, or eps format using latex) with the \includegraphics command, but this has nothing to do with the figure environment, that can be used without any package, and without any image:

\documentclass{article}
\begin{document}
\begin{figure}
     \hfil  (whatever) 
\end{figure}
\end{document}

That is, the figure environment is not an image, as the table environment in not really a table. Both are floats, unbreakable containers that can move from the actual position to fit well on top or bottom of the present page, or move to the next page if this is not possible, according to some options and complex rules. For a full understanding of floating mechanisms, see How to influence the position of float environments like figure and table in LaTeX?.

The numeration of the float is due to the optional \caption{...} command, that will increase the float counter and print "Figure x" or "Table y" plus the argument (the {...} part), that is, \figurename plus \thefigure, or \tablename plus \thetable, according to the type of float where it is placed, without regarding the float content:

\documentclass{article}
\begin{document}
\begin{figure}
      \hfil  (whatever) 
      \caption{caption of whatever}
\end{figure}
\end{document}

In both floats types, the content of the float is up to you. It can be almost anything except another float (a nested float is a contradiction in its own terms, and of course, will produce a fatal error), so the content can be an image in a table environment, or a table tabular environment in a figure environment, or absolutely nothing, or some text with or without a caption, or a minipage, ... or a tikz draw, that answer the question in verbose mode, but not better than the @leandriis comment:

mwe

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=white]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=white]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=white]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{figure}\centering 
\begin{tikzpicture}[node distance=2cm]
\node (in1) [io] {unit cell};
\node (pro1) [process, below of=in1] {vc-relax (pw.x)};
\draw[arrow](in1)--(pro1);
\end{tikzpicture}
\caption{A tikz figure}
\end{figure}
\end{document}
Fran
  • 80,769
  • Thank you so much for the detailed answer. I try to vote it, but my reputation is low so it didn't show! Anyway, thanks! – Ryan Gao May 13 '20 at 21:25