我想控制图像定位,使图像之间的空间始终是一条直线。但对于宽度不等的图像,这种方法行不通。我想使用subfloat
和textwidth
。我该如何解决这个问题?
\begin{figure}[!hbtp]
\centering
\subfloat[]{\label{}\includegraphics[width=0.3\textwidth]{1.png}}\quad%
\subfloat[]{\label{}\includegraphics[width=0.2\textwidth]{1.png}}\\%
\subfloat[]{\label{}\includegraphics[width=0.2\textwidth]{1.png}}\quad%
\subfloat[]{\label{}\includegraphics[width=0.22\textwidth]{1.png}}%
\caption{}%
\label{}
\end{figure}
附录:
答案1
\documentclass{article}
\usepackage{tabularx}
\usepackage{subfig}
\usepackage{graphicx}
\begin{document}
\begin{figure}[hbt]
\begin{tabularx}{\textwidth}{>{\raggedleft \arraybackslash}X
>{\raggedright\arraybackslash}X}
\subfloat[]{\label{fig-a}\includegraphics[width=0.3\textwidth]{example-image}}
& \subfloat[]{\label{fig-b}\includegraphics[width=0.2\textwidth]{example-image}}
\\%
\subfloat[]{\label{fig-c}\includegraphics[width=0.2\textwidth]{example-image}}
& \subfloat[]{\label{fig-d}\includegraphics[width=0.22\textwidth]{example-image}}
\end{tabularx}
\caption{}%
\label{}
\end{figure}
\end{document}
下次请提供完整的文档,而不仅仅是代码片段。
附录: 从你的评论中我猜你的愿望是:
对于此图形布局,您需要广告包adjustbox
:
\documentclass{article}
\usepackage{tabularx}
\usepackage{subfig}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\begin{document}
\begin{figure}[hbt]
\begin{tabularx}{\textwidth}{>{\raggedleft \arraybackslash}X
>{\raggedright\arraybackslash}X}
\subfloat[\label{fig-a}]{\includegraphics[width=0.3\textwidth]{example-image}}
& \subfloat[\label{fig-b}]{\includegraphics[width=0.2\textwidth]{example-image}}
\\%
\subfloat[\label{fig-c}]{\includegraphics[width=0.2\textwidth,valign=T]{example-image}}
& \subfloat[\label{fig-d}]{\includegraphics[width=0.22\textwidth,valign=T]{example-image}}
\end{tabularx}
\caption{}%
\label{}
\end{figure}
\end{document}
附录(2): 根据您问题的附录,您可能喜欢按如下方式排列子图像:
对于这种安排,我valign=T
还在第一行的图像中添加了选项。adjustbox
:
\documentclass{article}
\usepackage{tabularx}
\usepackage{subfig}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\begin{document}
\begin{figure}[hbt]
\begin{tabularx}{\textwidth}{>{\raggedleft \arraybackslash}X
>{\raggedright\arraybackslash}X}
\subfloat[\label{fig-a}]{\includegraphics[width=0.3\textwidth,valign=T]{example-image}}
& \subfloat[\label{fig-b}]{\includegraphics[width=0.2\textwidth,valign=T]{example-image}}
\\%
\subfloat[\label{fig-c}]{\includegraphics[width=0.2\textwidth,valign=T]{example-image}}
& \subfloat[\label{fig-d}]{\includegraphics[width=0.22\textwidth,valign=T]{example-image}}
\end{tabularx}
\caption{}%
\label{}
\end{figure}
\end{document}