[Tex/LaTex] Syntax similar to \centering for right and left

graphicshorizontal alignment

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.

Best Answer

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}
Related Question