1

I have a problem in LaTex, I want to place a figure in center of my text and below the figure, I want to add an information. I use this code to get the figure :

\newcommand\FanoPlane[1][1cm]{%
\begin{tikzpicture}[
 mydot/.style={
   draw,
   circle,
   fill=black,
   inner sep=3pt}
   ]
\draw
(0,0) coordinate (A) --
(#1,0) coordinate (B) --
($ (A)!.5!(B) ! {sin(60)*2} ! 90:(B) $) coordinate (C) -- cycle;
\coordinate (O) at
(barycentric cs:A=1,B=1,C=1);
\draw (O) circle [radius=#1*1.717/6];
\draw (C) -- ($ (A)!.5!(B) $) coordinate (LC); 
\draw (A) -- ($ (B)!.5!(C) $) coordinate (LA); 
\draw (B) -- ($ (C)!.5!(A) $) coordinate (LB); 
\foreach \Nodo in {A,B,C,O,LC,LA,LB}
 \node[mydot] at (\Nodo) {};    
\end{tikzpicture}%
\put(15,0){Figure 1. Fano Hypergraph }
 }

\quad\FanoPlane[5cm]
  • Do you really want to explicitly write the figure number? Why not use a \caption/\captionof? – Torbjørn T. Nov 10 '17 at 13:01
1

As a commenter has pointed out, it's strange that you are manually entering the caption. More common practice is to do something like this:

\newcommand\FanoPlane[1][1cm]{%
\begin{tikzpicture}[
 mydot/.style={
   draw,
   circle,
   fill=black,
   inner sep=3pt}
   ]
\draw
(0,0) coordinate (A) --
(#1,0) coordinate (B) --
($ (A)!.5!(B) ! {sin(60)*2} ! 90:(B) $) coordinate (C) -- cycle;
\coordinate (O) at
(barycentric cs:A=1,B=1,C=1);
\draw (O) circle [radius=#1*1.717/6];
\draw (C) -- ($ (A)!.5!(B) $) coordinate (LC); 
\draw (A) -- ($ (B)!.5!(C) $) coordinate (LA); 
\draw (B) -- ($ (C)!.5!(A) $) coordinate (LB); 
\foreach \Nodo in {A,B,C,O,LC,LA,LB}
 \node[mydot] at (\Nodo) {};    
\end{tikzpicture}%
 }
\begin{figure}
\centering
\quad\FanoPlane[5cm]
\caption{Fano Hypergraph}\label{fig:figurelabel}
\end{figure}

Which will place the tikz picture in a figure and center the figure contents.

PS: If you want for the picture to be placed RIGHT THERE in the text with no floating there are two options: Option 1: Use the t, b, h and H with ! switches to force the Latex to place the figure at top, bottom, here and RIGHT HERE.

\begin{figure}[h!]
figure code
\end{figure}

Will try to place the figure here. H will tend to ignore all the rules to place it there. TBH I'm not 100% on the exact algorithm that Latex uses to accomplish this.

If the above doesn't work, and you REALLY want to place something RIGHT THERE then you don't really want the floating bit so you shouldn't use the float environment. Instead use center like so:

\begin{center}
figure code
\captionof{figure}{Caption text}
\end{center}

This will force Latex to basically treat the image as text, which will mean things might not be pretty. But it will place it RIGHT THERE where you want it.

  • This code can produce picture as I want but the picture will appear in the top of my text. I want to put this picture below my text. – J. Klins Nov 10 '17 at 13:22
  • @J.Klins Yes, a figure is a floating environment, but see tex.stackexchange.com/questions/8625/…. (By the way, you can remove the \quad if you have \centering – Torbjørn T. Nov 10 '17 at 13:24
  • I added two ways to FORCE the figure to be placed right there in the text. The later one is preferable if it's critical that Latex doesn't move it at any cost at the price of maybe causing blank space on page if the image can't fit and is moved to the next one. – 4th Dimension Nov 13 '17 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.