185

For images, we can use \centering. Is there anything available to align the image to the right side or the left side of the page.

Olivier
  • 208

4 Answers4

125

For general text you can use \raggedright and \raggedleft to align the material to the left and right, respectively. To align images inside a figure easily you can use the adjustbox package which allows you to add alignment keys to \includegraphics.

\documentclass{article}
\usepackage[export]{adjustbox}

\begin{document}

\begin{figure}
    \includegraphics[width=.6\textwidth,center]{example-image}
    \caption{centered image}
\end{figure}

\begin{figure}
    \includegraphics[width=.6\textwidth,left]{example-image}
    \caption{left aligned image}
\end{figure}

\begin{figure}
    \includegraphics[width=.6\textwidth,right]{example-image}
    \caption{right aligned image}
\end{figure}

\end{document}

For new documents, especially if many adjustbox keys are used, I recommend to use the \adjustimage{<keys>}{<filename>} macro instead of \includegraphics. The export option is then not required anymore. There is also the possibility to do the whole figure using one \adjustimage use by using the keys caption, label and figure.

\documentclass{article}
\usepackage[export]{adjustbox}

\begin{document}

\begin{figure}
    \adjustimage{width=.6\textwidth,center}{example-image}
    \caption{centered image}
\end{figure}

% or even shorter
\noindent\adjustimage{width=.6\textwidth,center,caption={your caption},label={some label},figure}{example-image}

\end{document}
Martin Scharrer
  • 262,582
  • Can we apply this approach for tikzfigure inside figure? – alper Dec 12 '22 at 10:48
  • 1
    @alper: You can use \begin{adjustbox}{center}\begin{tikzfigure} ... \end{tikzfigure}\end{adjustbox} to center tikzfigures. center also accepts an optional width and you can of course add more arguments. See the adjustbox manual. – Martin Scharrer Feb 07 '23 at 07:53
28

Consider the following examples:

\documentclass[12pt]{article}
\usepackage{showframe}
\usepackage[demo]{graphicx}
\begin{document}

\begin{figure}
 \includegraphics{n}
 \caption{\texttt{none}}
\end{figure}

\begin{figure}
 \hfill\includegraphics{n}
 \caption{\texttt{hfill}}
\end{figure}

\begin{figure}
 \begin{flushright}% or better \raggedleft see comments below
  \includegraphics{n}
  \caption{\texttt{flushright}}
 \end{flushright}
\end{figure}

\begin{figure}
 \hfill\begin{minipage}{.5\textwidth}\centering
  \includegraphics{n}
  \caption{\texttt{minipage}}
 \end{minipage}
\end{figure}

\end{document}

You can choose now. I personally prefer the minipage approach.

enter image description here enter image description here

bloodworks
  • 10,178
  • I don't think you should use the flushright environment inside a figure for the same reason as you shouldn't use center. The vertical spacing might be wrong. – Martin Scharrer Jan 13 '13 at 12:23
  • I agree, particularly because it is not necessary since hfill is sufficient. I just wanted to show a few more possibilities. I added a comment... – bloodworks Jan 13 '13 at 12:28
9

If it isn't a floating images you can use \flushright or \flushleft. Also you may put \hfil from the right or left of image block.

Eddy_Em
  • 1,405
  • 7
    flushright and flushleft are intended as environments cf center the analogues of \centering are \raggedright and \raggedleft – David Carlisle Jan 13 '13 at 11:09
0

Worked for me:

\documentclass{article}
\usepackage[export]{adjustbox}

\begin{document}

\begin{figure} \includegraphics[width=.6\textwidth,left]{example-image} \caption{left aligned image} \end{figure}

\end{document}