TeX - LaTeX Asked by Simplicity on September 26, 2021
If I want to put two images beside each other, what should I do? I have inserted a figure. But, rather than having the next figure on a new line, I want it to be beside the already inserted figure. How can I do that?
Actually there are a number of ways of achieving what you are asking for.
Without Using Any Package
documentclass{article}
usepackage{graphicx}
begin{document}
begin{figure}[!tbp]
centering
begin{minipage}[b]{0.4textwidth}
includegraphics[width=textwidth]{flower1.jpg}
caption{Flower one.}
end{minipage}
hfill
begin{minipage}[b]{0.4textwidth}
includegraphics[width=textwidth]{flower2.jpg}
caption{Flower two.}
end{minipage}
end{figure}
end{document}
Using Packages
You can use either subfig or subcaption.
Using subfig
documentclass{article}
usepackage{graphicx}
usepackage{subfig}
begin{document}
begin{figure}[!tbp]
centering
subfloat[Flower one.]{includegraphics[width=0.4textwidth]{flower1.jpg}label{fig:f1}}
hfill
subfloat[Flower two.]{includegraphics[width=0.4textwidth]{flower2.jpg}label{fig:f2}}
caption{My flowers.}
end{figure}
end{document}
Using subcaption
documentclass{article}
usepackage{graphicx}
usepackage{caption}
usepackage{subcaption}
begin{document}
begin{figure}[!tbp]
begin{subfigure}[b]{0.4textwidth}
includegraphics[width=textwidth]{flower1.jpg}
caption{Flower one.}
label{fig:f1}
end{subfigure}
hfill
begin{subfigure}[b]{0.4textwidth}
includegraphics[width=textwidth]{flower2.jpg}
caption{Flower two.}
label{fig:f2}
end{subfigure}
caption{My flowers.}
end{figure}
end{document}
Pros and Cons of the Approaches
minipage
environment is actually very simple.
But as you can see the figures are number individually. If want to present a group of related figures, it may not be the one you are looking for.subfig
and subcaption
are very similar. Though each has its own way of usage. However, there are reports on subfig
not working properly with hyperref
. This question
provides an excellent discussion on the comparative analysis on subcaption
vs. subfig
. Further Reading
In order to get a better understanding of the placement and width controlling issues, I strongly suggest the you go through the documentation of the above two packages (subfig and subcaption). These documentations contain some excellent hints and examples.
Also, for comprehending the solutions of related issues, these questions (A, B, C, D, E, F) are worth taking a look at.
Answered by Masroor on September 26, 2021
The MWE package offers a nice solution:
documentclass{article}
usepackage{mwe}% or load ’graphicx’ and ’blindtext’ manually
begin{document}
blindtext
begin{figure}
includegraphics[width=.48linewidth]{example-image-a}hfill
includegraphics[width=.48linewidth]{example-image-b}
caption{MWE to demonstrate how to place to images side-by-side}
end{figure}
blindtext
end{document}
Answered by Ingmar on September 26, 2021
These solutions are too complicated IMHO, you don't need to install any new packages.
begin{figure}[h]
begin{tabular}{ll}
includegraphics[scale=1]{Figures/Race.png}
&
includegraphics[scale=0.4]{Figures/Bearing.png}
end{tabular}
caption{Left: Diagram of angular contact bearing cite{NBCBearing}.
Right: Disassembled bearing}
label{Fig:Race}
end{figure}
Answered by Anthony Ebert on September 26, 2021
Not an exact solution, but a workaround. I wasn't happy with how much blank space Latex allowed between the two images. So I copied both images into MS word (or Google Docs), arranged them side-by-side, and used the Snipping Tool to create a "single" picture. What's seen below is a single .png file which is much easier to insert.
Answered by Norbert on September 26, 2021
The conflict with subfig
and hyperref
does exist: it's not just a rumor, which is why I prefer subcaption
as I almost invariably need hyperref
.
Also, begin{subfigure}[b]{0.475textwidth}
should give a cleaner finish, still with plenty of space between the figures.
Place:
usepackage{graphicx}
usepackage{caption}
usepackage{subcaption}
in the preamble.
Answered by David Crosswell on September 26, 2021
I would recommend using the tikz package. this answers your question in the most basic form, with for instance:
documentclass{article}
usepackage{graphicx}
usepackage{tikz}
begin{document}
begin{tikzpicture}
node [anchor=north west] (imgA) at (.05linewidth, .050linewidth){includegraphics[width=.5linewidth]{figA.pdf}};
node [anchor=north west] (imgB) at (.05linewidth, .500linewidth){includegraphics[width=.linewidth]{figB.pdf}};
end{tikzpicture}
end{document}
One advantage is that you can place any number of figure, but also place easily letters to identify the figures:
documentclass{article}
usepackage{graphicx}
usepackage{tikz}
begin{document}
begin{tikzpicture}
node [anchor=north west] (imgA) at (.05linewidth, .050linewidth){includegraphics[width=.5linewidth]{figA.pdf}};
draw [anchor=north west] (0., .000linewidth) node {(A)};
node [anchor=north west] (imgB) at (.05linewidth, .500linewidth){includegraphics[width=.linewidth]{figB.pdf}};
draw [anchor=north west] (0., .500linewidth) node {(A)};
end{figure}
end{document}
An example of use can be found in this paper's LaTeX code, at page 4 of the PDF:
You may need to tune the position of each object manually to get the appropriate result.
Answered by meduz on September 26, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP