Article directory
1. Contain multiple sub-pictures
To achieve an arrangement of multiple subfigures, we need to use a floating environment (such as figure
) and place the subfigures in it.
Floating environments automatically manage the layout of pages and move content to new pages when needed.
Here is a sample code showing how to create multiple subfigures in a LaTeX document:
\documentclass{
article}
\usepackage{
graphicx}
\usepackage{
subcaption}
\begin{
document}
\begin{
figure}[!htb]
\centering
\begin{
subfigure}{
.5\textwidth}
\centering
\includegraphics[width=\linewidth]{
example-image-a}
\caption{
First Subfigure}
\end{
subfigure}%
\begin{
subfigure}{
.5\textwidth}
\centering
\includegraphics[width=\linewidth]{
example-image-b}
\caption{
Second Subfigure}
\end{
subfigure}
% 重复以上代码块来添加更多的子图
\caption{
Multiple Subfigures}
\end{
figure}
\end{
document}
In this example, figure
the environment contains several subfigure
, each subfigure
containing an image and a title.
If all subfigures cannot fit on the same page, LaTeX will automatically spread them across new pages. We can adjust the number and layout of subplots as needed.
as the picture shows:
2. Alignment problem
Alignment problems in LaTeX are usually caused by environment settings, the dimensions of the image itself, or white space around the image when it is inserted.
To resolve alignment issues we need to ensure:
- Use the same width setting in all subfigures.
- Make sure the dimensions of the images match.
- Make sure there is no extra margin around the image.
Here are some suggested modifications to resolve alignment issues:
\begin{
figure*}[!htb]
\centering
% 确保所有子图的宽度设置相同
\includegraphics[width=\textwidth]{
images/15.png}
\includegraphics[width=\textwidth]{
images/16.png}
\includegraphics[width=\textwidth]{
images/17.png}
\includegraphics[width=\textwidth]{
images/18.png}
\includegraphics[width=\textwidth]{
images/19.png}
\includegraphics[width=\textwidth]{
images/20.png}
% 如果希望有子图的标题,每个includegraphics命令都应放在subfigure环境中,并且提供caption和label
\end{
figure*}
\begin{
figure*}[!htb]
\centering
% 使用相同的宽度设置
\includegraphics[width=\textwidth]{
images/21.png}
\includegraphics[width=\textwidth]{
images/22.png}
\includegraphics[width=\textwidth]{
images/23.png}
\includegraphics[width=\textwidth]{
images/24.png}
\includegraphics[width=\textwidth]{
images/25.png}
\includegraphics[width=\textwidth]{
images/26.png}
% 如果希望有子图的标题,每个includegraphics命令都应放在subfigure环境中,并且提供caption和label
\end{
figure*}
If you wish to add subtitles and tags below the image, you need to wrap each \includegraphics
command with an subfigure
environment and provide \caption
and \label
. Here I've removed subfigure
the environments because we didn't add headers to them in the original code.
Note that if the images themselves are of different sizes, or they have different edge margins, this may cause the images to be visually misaligned. We may need to pre-edit images to ensure they are consistent in size and have minimal margins.
3. Movement of subgraphs
In LaTeX, to figure*
move the entire environment slightly to the right, use \hspace{<length>}
the command and give it a positive value. This command will add some horizontal space to the left of the environment, thus moving the content to the right.
We can add this command between \begin{figure*}
and .\centering
Here's how to modify the code:
\begin{
figure*}[!htb]
\centering
\hspace{
5mm} % 这会将图片整体向右移动5毫米,您可以根据需要调整这个值
\includegraphics[width=\textwidth]{
images/21.png}
% 重复上面的命令来包括其他图像
\end{
figure*}
Note that if our image is already using \textwidth
the width of , then moving to the right may cause part of the image to extend beyond the edge of the page. To avoid this, you can appropriately reduce the width of the image to make room for the right shift, for example:
\begin{
figure*}[!htb]
\centering
\hspace{
5mm} % 向右平移
\includegraphics[width=0.95\textwidth]{
images/21.png} % 减小宽度以避免内容溢出
% 重复上面的命令来包括其他图像
\end{
figure*}
But after this method, we found that only the first picture has been translated.
There is no change in using directly \hspace{}
, probably because of \centering
the effect of the command, which will override \hspace{}
the effect of. Try removing \centering
the command and using \hspace{}
to adjust the position.
The problem is solved!