How to fix figure position in LaTeX?

Figures and tables are floating objects in LaTeX. By Default LaTeX tries to put them in the best position around the page. But sometimes we want to position a figure as we want. In that case, we have to use some options.

In this tutorial, I will show you all the techniques to fix a figure position as we want.

Default placement options

LaTeX provides some options to control the figure potion around the page. So you can use those default options to set your figure position. Here are the following options.

  • [h]: “Here” – Right where you put the code.
  • [t]: “Top” – At the top of the page.
  • [b]: “Bottom” – At the bottom of the page.
  • !: A little “override” to LaTeX’s internal rules.

So, in order to fix a figure or table position, you can use the [h] option.

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum} 

\begin{document}
\section*{Section 1:}
\lipsum[1][1-5]
\begin{figure}[h]
    \centering
    \includegraphics[width=0.4\textwidth]{example-image}
    \caption{Fix the figure position with \texttt{[h]} option}
\end{figure}
\section*{Section 2:}
\lipsum[1][1-4]
\begin{table}[h]
    \centering
    \begin{tabular}{|c|c|c|}
       \hline
       1  &  2 & 3\\
       \hline
       4  &  5 & 6\\
       \hline
    \end{tabular}
    \caption{Fix the table position \texttt{[h]} option}
\end{table}

\end{document}

Output:

Fix figure and table position with h option.

Fix the figure position with [!h] option

You can also use the [!h] option if the [h] option doesn’t work. The [!h] option is more insistent than any other option.

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum} 

\begin{document}
\section*{Section 1:}
\lipsum[1][1-5]
\begin{figure}[!h]
    \centering
    \includegraphics[width=0.4\textwidth]{example-image}
    \caption{Fix the figure position with \texttt{[!h]} option}
\end{figure}
\section*{Section 2:}
\lipsum[1][1-4]
\begin{table}[!h]
    \centering
    \begin{tabular}{|c|c|c|}
       \hline
       1  &  2 & 3\\
       \hline
       4  &  5 & 6\\
       \hline
    \end{tabular}
    \caption{Fix the table position \texttt{[!h]} option}
\end{table}

\end{document}

Output:
Fix figure and table position with !h option.

Fix the figure and table position with [H] option

You can also use the [H] option to fix the figure and table position. But in this case, you have to load the float package.

\documentclass{article}
\usepackage{graphicx}
\usepackage{float}
\usepackage{lipsum} 

\begin{document}
\section*{Section 1:}
\lipsum[1][1-5]
\begin{figure}[H]
    \centering
    \includegraphics[width=0.4\textwidth]{example-image}
    \caption{Fix the figure position with \texttt{[H]} option}
\end{figure}
\section*{Section 2:}
\lipsum[1][1-4]
\begin{table}[H]
    \centering
    \begin{tabular}{|c|c|c|}
       \hline
       1  &  2 & 3\\
       \hline
       4  &  5 & 6\\
       \hline
    \end{tabular}
    \caption{Fix the table position \texttt{[H]} option}
\end{table}

\end{document}

Output:

Fix figure and table position with !h option.

Leave a Reply

Your email address will not be published. Required fields are marked *