0

I have two images that I would like to place at the top edges of the document. One image at top left and other image at top right. But I am not able to achieve it

enter image description here

This how it looks whereas I want both in the same line. The picture A at top left and picture B at top right of the page. The code for it as follows:

    \begin{figure}[t]
       \subfloat{\includegraphics[width=3cm,left]{Pictures/a.jpg}}\\
        \subfloat{\includegraphics[width=3cm,right]{Pictures/b.jpg}}\\
    \end{figure}

Is there a way to achieve this?

EngGu
  • 103
  • Looks like these links from the Related: section do what you need: https://tex.stackexchange.com/questions/343855/two-images-with-different-size-side-by-side-automatic-computation?rq=1, and https://tex.stackexchange.com/questions/515311/how-do-i-position-3-images-on-a-1-big-image-left-two-small-one-on-top-of-the-ot?rq=1 . – MS-SPO Oct 24 '22 at 08:09
  • They are NOT on the same line due to the use of \ (\newline). By "the top edges of the document", do you mean the text area or the paper? – John Kormylo Oct 24 '22 at 15:01

2 Answers2

2

Try this:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{graphicx,float,mwe}
\usepackage{showframe} % comment after testing
\begin{document}
    \begin{figure}[t]
        \includegraphics[width=3cm]{example-image-a}\hfill
        \includegraphics[width=3cm]{example-image-b}\\
    \end{figure}
\[ax^2+bx+c=0 \Rightarrow x=\dfrac{-b\pm\sqrt{b^2-4ac}}{2a}\]
\end{document}

Output:

enter image description here

2

You don't really need to make them float in this case, hence you don't need the figure environment. Just start your document from the images

\vspace*{-\topskip}%
\noindent%
\includegraphics[width=3cm,valign=t]{example-image-a}%
\hfill%
\includegraphics[width=3cm,valign=t]{example-image-b}

Additionally, the first line removes \topskip latex adds as the first thing on a page whilst \noindent cancels indentation.

Also, \includegraphics does not have a key left. Positioning in LaTeX is achieved by adding necessary space before/after/between images, even if they are inside figure. Conveniently, \hfill, equivalent of \hspace{\fill} adds a necessary stretch to spread both images both sides.

The full code:

\documentclass{article}
\usepackage{graphicx}

\begin{document} \vspace*{-\topskip}% \noindent% \includegraphics[width=3cm]{example-image-a}% \hfill \includegraphics[width=3cm]{example-image-b} \end{document}


EDIT.
In case each of the images have a different size, you might need to add the top alignment by adding valign=t (available with the package adjustbox)

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage[export]{adjustbox}   % <--- adds valign=t

\usepackage{showframe} \renewcommand{\ShowFrameLinethickness}{0.2pt} \renewcommand{\ShowFrameColor}{\color{red}}

\begin{document} \vspace*{-\topskip}% \noindent% \includegraphics[width=3cm,valign=t]{example-image-a}% \hfill% \includegraphics[width=3cm,valign=t]{example-image-16x9} \end{document}

Celdor
  • 9,058