如何将不同尺寸的图表放入一页

如何将不同尺寸的图表放入一页

我想将四个不同大小的图形放入一页的表格中。我开始使用以下代码,但不知道该如何实现。我该如何实现?

begin{figure}
\begin{tabular}{ll}
  \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{fig1.jpg} &
  \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{fig2.jpg} \\
  \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{fig3.pdf} & 
  \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{fig4.pdf} \\
\end{tabular}
\end{figure}

答案1

除了减少\textwidth到 50% 以下,一般来说,最好将此长度改为\linewidth。很多时候是完全相同的长度,但如果情况并非如此,那么你真正想要的可能是 \linewidth,而不是\textwidth\columnwidth参见根据布局是一列还是两列自动设置图形宽度

为了减少在下一个示例中输入重复代码,我使用了一个基本的宏,希望这不会造成混淆。它显示两个浮点数,带有和不带有子标题,即使\linewidth在只有一列的文档中,使用也很重要。

平均能量损失

\documentclass{article}
\usepackage[demo]{graphicx} % remove "demo" to use with your images
\usepackage{subcaption}

% macro only to simplify floats code 
% now  \linewidth  = \textwidth 

\newcommand\myfig[1]{%
\includegraphics[width=.49\linewidth,height=.2\textheight,keepaspectratio]{#1}}

\begin{document}

% simple example without subcaptions
\begin{figure}
\centering
\myfig{fig1.jpg}\hfill\myfig{fig2.jpg}\\[1ex]
\myfig{fig3.dpf}\hfill\myfig{fig4.dpf}\\
\caption{Four images}
\end{figure}


% example with subcaptions

\renewcommand\myfig[1]{%
\includegraphics[width=.95\linewidth,height=.5\linewidth,keepaspectratio]{#1}}

% Note that now the image width will be the  95% of the
% subfigure line width, that is less than the 48% of the 
% line width (= text width) of the main text.    

\begin{figure}
\centering
\begin{subfigure}[t]{0.48\linewidth}
\myfig{fig1.jpg}
\caption{fig1}%
\end{subfigure}
\begin{subfigure}[t]{0.48\linewidth}
\myfig{fig2.jpg}
\caption{fig2}
\end{subfigure}

\begin{subfigure}[t]{0.48\linewidth}
\myfig{fig3.pdf}
\caption{fig3}
\end{subfigure}
\begin{subfigure}[t]{0.48\linewidth}
\myfig{fig4.pdf}
\caption{fig4}
\end{subfigure}

\caption{Four images again}

\end{figure}


\end{document}

相关内容