将两幅带浮动的图像放在一个页面中

将两幅带浮动的图像放在一个页面中

我正在用 Latex 写 B5 格式的论文。在正文中,我可以很好地处理图形的浮动。但在支持信息部分,我有大量图像(仅在不同部分/小节下的图像),我想在一页上放置 2 张图片。但编译后,我在一页上只得到一张图片,这大大增加了总页数。

我必须[H]float包中使用,因为否则图像会出现在随机位置,并且不会在部分/小节名称下放置任何内容。

我也尝试过类似

\documentclass[10pt,fleqn]{phdthesis}%,makeidx

\makeatletter
\renewenvironment{thebibliography}[1]
     {
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
\makeatother

%%% For an A4 format, use there options instead
%\documentclass[12pt,makeidx]{phdthesis}
%\usepackage{a4wide}

\newcommand{\mypm}{\mathbin{\smash{%
\raisebox{0.35ex}{%
            $\underset{\raisebox{0.5ex}{$\smash -$}}{\smash+}$%
            }%
        }%
    }%
}

%%% Fonts, uncomment only one option %%%
%\usepackage{utopia}
%\usepackage{charter}
%\usepackage{palatino}
%\usepackage{newcent}
%\usepackage{avant}
\usepackage{pifont}
%\usepackage{mathpple}
%\usepackage{mathptmx}
\usepackage{multicol}
\usepackage{flafter}

%%% If you want to use MakeIndex to create automatically
% an index, uncomment these lines
\usepackage{makeidx}     % only with Latex2e
\makeindex

% Other packages
%\usepackage{fancyheadings}
% \usepackage{subfig}
%\usepackage[abbr]{harvard}
\usepackage{fancyhdr}
\usepackage{amsmath,dsfont}
\usepackage{amssymb,mathabx}
\usepackage{epsfig}
\usepackage[figbotcap]{subfigure}
\usepackage{graphics}
\usepackage{float}
\usepackage{here}
\usepackage[super,numbers,sort&compress]{natbib}  %coma
\renewcommand\bibsection{\section{\refname}}
\usepackage{rotating}
\usepackage{multirow}
\usepackage{comment}
\usepackage{captionhack}
\usepackage{epigraph}
\usepackage{array,multirow,nicefrac}
\usepackage{appendix}
\usepackage{acronym}
\usepackage[chapter]{algorithm}
\usepackage{algorithmic}
\usepackage{mathtools}
\usepackage{adjustbox}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{csquotes}
\usepackage{notes2bib}
\usepackage{siunitx}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{mciteplus}
\usepackage{longtable}

%----------------------------------------------------------------------------------------------------------
\makeatletter

\newcommand*\mycommand[1]{\texttt{\emph{#1}}}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\renewcommand{\mcitesubrefform}{\textsuperscript{\arabic{mcitebibitemcount}\alph{mcitesubitemcount}}}
\makeatother



%----------------------------------------------------------------------------------------------------------
% \usepackage{showframe}

\usepackage{lscape}
\usepackage[table]{xcolor}

\usepackage{wrapfig}

\usepackage{pstricks,pst-node}
% \usepackage{pstricks-add}%pst-char,,pst-text,ae,pst-grad,pst-slpe
\usepackage{fancybox}
%\usepackage[dvips,margin=1cm]{geometry}
% \usepackage{lmodern,pst-node}
\usepackage{psfrag}


% \renewcommand{\thesubfigure}{} 

\usepackage{float,afterpage,dblfloatfix}%stfloats
% dblfloatfix fixes two floatpages after each other
    % Alter some LaTeX defaults for better treatment of figures:
    % See p.105 of "TeX Unbound" for suggested values.
    % See pp. 199-200 of Lamport's "LaTeX" book for details.
    %   General parameters, for ALL pages:
    \renewcommand{\topfraction}{0.9}    % max fraction of floats at top
    \renewcommand{\bottomfraction}{0.8} % max fraction of floats at bottom
    %   Parameters for TEXT pages (not float pages):
    \setcounter{topnumber}{2}
    \setcounter{bottomnumber}{2}
    \setcounter{totalnumber}{4}     % 2 may work better was 4
    \setcounter{dbltopnumber}{2}    % for 2-column pages
    \renewcommand{\dbltopfraction}{0.9} % fit big float above 2-col. text
    \renewcommand{\textfraction}{0.07}  % allow minimal text w. figs
%   Parameters for FLOAT pages (not text pages):
    \renewcommand{\floatpagefraction}{0.7}  % require fuller float pages was 0.7
    % N.B.: floatpagefraction MUST be less than topfraction !!
    \renewcommand{\dblfloatpagefraction}{0.7}   % require fuller float pages 0.7

\makeatletter
\def\zaptype#1{%
\listsubcaptions % Finish the last set of sub-floats before
\def\@captype{#1}}% switching to another float type.
\makeatother

%%% Path to the directorz containing the graphics and figures 
\graphicspath{{./pics/},{./pics/chapter_2/},{./pics/chapter_3/},{./pics/chapter_4/},{./pics/chapter_5/},{./pics/chapter_6/}
,{./pics/chapter_7/},{./pics/chapter_8/},{./pics/chapter_9/}}
\usepackage{ifpdf}
\ifpdf
\graphicspath{{./png/}}
\DeclareGraphicsExtensions{.png}
\else
  \DeclareGraphicsExtensions{{.eps},{.epsi}}%,{.ps}
\fi
%%% General page formatting
\renewcommand{\textfraction}{0.01}
\renewcommand{\topfraction}{0.99}
\renewcommand{\floatpagefraction}{0.99}
\renewcommand{\bottomfraction}{0.99}

\newenvironment{Abstract}
{\begin{center}\textbf{Abstract}%
 \end{center} \small \it \begin{quote}}
{\end{quote}}

% Macro for 'List of Symbols', 'List of Notations' etc...
\def\listofsymbols{\input{symbols} \clearpage}
\def\addsymbol #1: #2#3{$#1$ \> \parbox{4.6in}{#2 \dotfill \pageref{#3}}\\}
\def\newnot#1{\label{#1}} 


\pdfcompresslevel=3

\typeout{Dissertation}

\usepackage{hyperref}
%\usepackage{multibib}%[resetlabels]
% \def\@mb@citenamelist{cite,citep,citet,citealp,citealt,footcite,nocite}

% Initialize each paper type for which you need a bibliography.
% Just a dummy parameter is necessary.
% \newcites{p}{Publications}
%\newcites{journal,conf,techreport,submitpaper}{Journal Papers,Conference Papers,Technical Reports, Submitted Papers}%Journal Papers

\DeclareSIUnit\molar{\mole\per\cubic\deci\metre}
\DeclareSIUnit\Molar{\textsc{m}}

%%% To compile only one or some chapters, use the following
%   command 
% \includeonly{chapter1,chapter2,chapter3,chapter4,appendix_A}
%\includeonly{thesis_acknowledgements,chapter2,chapter3}
%\includeonly{chapter2}

% Morerow Comments
% \newcommand{\comment}[1]{{}} 


% correct bad hyphenation here
% TODO hyphenation
%\usepackage{hyphenat}
%\hyphenation{qua-dra-tic SRBCT pre-ser-va-tion Min-kow-ski a-dapt-ive de-ri-va-tive pat-ches pre-serv-ing re-sul-ting Em-bedd-ing 
%where-by uni-form de-ri-va-ti-ves con-ti-nu-ous-ly wille-keurige voor-ge-steld}
% solve hyphenation that contain a dash like electromagnetic-endioscopy: electromagnetic\hyp{}endioscopy
% high\hyp{}dimensional

% \usepackage{scrwfile}
% \usepackage{xy}%etex
% \xyoption{all} 

%%% Begining of the document 
\begin{document}

\subsection{Section Name}
    \begin{figure}[H]
    \includegraphics[width=\linewidth]{images1.png}
    \caption{caption 1}
    \label{fig1}

    \includegraphics[width=\linewidth]{images2.png}
    \caption{caption 2}
    \label{fig2}
    \end{figure}

    \begin{figure}[H]
    \includegraphics[width=\linewidth]{images3.png}
    \caption{caption 3}
    \label{fig3}

    \includegraphics[width=\linewidth]{images4.png}
    \caption{caption 4}
    \label{fig4}
    \end{figure}

\end{document}

代替

\subsection{Section Name}
\begin{figure}[H]
\includegraphics[width=\linewidth]{images1.png}
\caption{caption 1}
\label{fig1}
\end{figure}

\begin{figure}[H]
\includegraphics[width=\linewidth]{images2.png}
\caption{caption 2}
\label{fig2}
\end{figure}

\begin{figure}[H]
\includegraphics[width=\linewidth]{images3.png}
\caption{caption 3}
\label{fig3}
\end{figure}

\begin{figure}[H]    
\includegraphics[width=\linewidth]{images4.png}
\caption{caption 4}
\label{fig4}
\end{figure}

但如果我需要在之后添加一些内容(如果我在中间添加一个图形,我必须重新做所有事情),那么它就没什么用了。而且,如果我在一个文件中包含两张图片\begin{figure},那么在它之前我会得到一个空白页。

以下是我得到的截图: 在此处输入图片描述

我想要的是: 在此处输入图片描述

答案1

在一页中放置两幅图像[H]是最糟糕的选择,因为这会避免将两幅图像浮动到接近右点(很可能是下一页的开头)而不会留下巨大的浪费空间。

你实际上只需要照顾好树木就可以避免这种情况:

(1)显然,始终避免 [H](至少对于这个目标而言)。

(2)放置[p]选项t单独(或与和结合b)在需要(方便、允许)对浮点数进行分组时使用。

(3)注意两张图片的高度加上两个标题的高度还有一些(因为\floatsep如果\textfloatsep还有一些文本)不超过文本的总高度。如果是这样,请减小图像尺寸、标题或两者。

或者,您可以将多张图片放在一个浮动框中,但这并不能免除 (3) 的问题,只会使选项变得[tbp]无关紧要(只要浮动框的高度接近整个文本区域的高度)。这种方法的唯一优点是强制合并图片(即使它们根本不适合页面),但正是出于这个原因,通常最好使用两个浮动框并使用适当的选项:

本文尝试通过一些例子来解释这一点:

姆韦

\documentclass{article}
\usepackage{geometry,lipsum,graphicx}

% Just to simplify the posterior code
\def\image#1{\centering\includegraphics
[width=\linewidth,height=.34\textheight,keepaspectratio]{#1}}
\def\wideimage#1{\centering\includegraphics
[width=\linewidth,height=\textheight,keepaspectratio]{#1}}
\def\captionlipsum{\caption{\protect\lipsum[2]}}

\begin{document}
\lipsum[1] % dummy text

% [p] option is good if you want two images in one page
\begin{figure}[p]\image{example-image}\captionlipsum\end{figure}

% option here is superfluous (except if you use also "b" or "t") 
\begin{figure}[tbp]\image{example-image-a}\captionlipsum\end{figure}

% [p] option still works! 
\begin{figure}[tbp]\image{example-image-1x1}\captionlipsum\end{figure}\lipsum[4]
\begin{figure}[tbp]\wideimage{example-image-16x9}\caption{ssss}\end{figure}\lipsum[5]
\lipsum[3]

% options here agian is superfluous 
\begin{figure}\wideimage{example-image-9x16}\captionlipsum\end{figure}\lipsum[5]

% Images too big per only one page  
% Use [t], [b] or [tp] but not [p] if you want avoid a centered image without text around
% (maybe not a bad idea after all ...) 

\begin{figure}[tb!] \wideimage{example-image-16x9}\captionlipsum\end{figure}\lipsum[5]
\begin{figure}[tb!]\wideimage{example-image}\captionlipsum\end{figure}

\lipsum[3]

% Two images in a float to maintain together. Not a good idea in this case ....    
\begin{figure}
\wideimage{example-image-a}\captionlipsum\vspace{\floatsep}
\wideimage{example-image-b}\captionlipsum\end{figure}
\lipsum[5]

% ... unless you take care of the image size
\begin{figure}
\image{example-image-a}\captionlipsum\vspace{\floatsep}
\image{example-image-b}\captionlipsum\end{figure}
\lipsum[6-20]

\end{document}

相关内容