Graphics, Figures & TablesHow can I insert two pictures on the first page?

Information and discussion about graphics, figures & tables in LaTeX documents.
ssfjhh
Posts: 12
Joined: Wed Jul 10, 2013 12:38 pm

How can I insert two pictures on the first page?

Post by ssfjhh »

Hello everyone,
My document has one "figure" section, but I don't want to show the title in the section, so I define a new command "nosection" to do this.

Code: Select all

    \newcommand{\nosection}[1]{
      \refstepcounter{section}%
      \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}}
and I want to insert two pictures in each page exactly, and make each picture as big as possible, so I use the following code.

Code: Select all

    \nosection{Figures}
    \begin{figure}[htb]
        \centering
        \hypertarget{figure1}{}           
        \pdfbookmark[2]{Figure1}{figure1} 
        \includegraphics[height=0.45\textheight, width=0.95\textwidth, keepaspectratio]{1.eps}
        \caption{}
    \end{figure}

    \begin{figure}[b]
        \centering
        \hypertarget{figure2}{}           
        \pdfbookmark[2]{Figure2}{figure2} 
        \includegraphics[height=0.45\textheight, width=0.95\textwidth, keepaspectratio]{2.eps}
        \caption{}
    \end{figure}

    \begin{figure}[htb]
        \centering
        \hypertarget{figure3}{}           
        \pdfbookmark[2]{Figure3}{figure3} 
        \includegraphics[height=0.45\textheight, width=0.95\textwidth, keepaspectratio]{3.eps}
        \caption{}
    \end{figure}

    \begin{figure}[htb]
        \centering
        \hypertarget{figure4}{}           
        \pdfbookmark[2]{Figure4}{figure4} 
        \includegraphics[height=0.45\textheight, width=0.95\textwidth, keepaspectratio]{4.eps}
        \caption{}
    \end{figure}
But the first page of the "Figures" section only has one picture, I don't know why. All the pictures is small enouth to show 2 pictures in one page.
PS. And the last page only has 1 picture, how can I put the picture on the top of the page? I have tried to use "\begin{figure}[t]", but it didn't work.
My Englist is poor. If something I wrote confuses you, please let me know.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How can I insert two pictures on the first page?

Post by localghost »

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

How can I insert two pictures on the first page?

Post by cgnieder »

As Thorsten already said: we can only guess what's happening unless you provide a Infominimal working example that let's us recreate your issue. Maybe the first EPS has not been cropped properly or has wrong bounding box information?

As an aside: your definition of \nosection has a spurious space:

Code: Select all

\newcommand{\nosection}[1]{% <= here should be a comment character
  \refstepcounter{section}%
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}}
Although it probably doesn't matter since you're using \nosection in vertical mode I'd still add the comment character.

Regards
site moderator & package author
ssfjhh
Posts: 12
Joined: Wed Jul 10, 2013 12:38 pm

How can I insert two pictures on the first page?

Post by ssfjhh »

Here is a minimal_example.
minimal_example.zip
(59.32 KiB) Downloaded 401 times
You may have never see "ctexart" class, it's for Chinese users.

My English is bad. If you cannot follow me, add comment below to show your question. I'll try my best to ansower you.

Thank you for your reply.
Last edited by ssfjhh on Mon Jul 29, 2013 12:47 pm, edited 1 time in total.
My Englist is poor. If something I wrote confuses you, please let me know.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How can I insert two pictures on the first page?

Post by Johannes_B »

Considering your problem. You have given all your figure-environments optional placement specifiers. As said, they are optional, ommiting them in your case leads to the output you are trying to achieve. Since your are having a section with only pictures, you may not want the pictures to float at all. Have a look at the capt-of-package.

Your minimal example uses the normal article class and no chinese signs. This is good, since not everybody has CJK-Fonts installed.

EDIT: Deleted wrong statement about the scale option keepaspectratio
Last edited by Johannes_B on Mon Jul 29, 2013 3:46 pm, edited 1 time in total.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
ssfjhh
Posts: 12
Joined: Wed Jul 10, 2013 12:38 pm

Re: How can I insert two pictures on the first page?

Post by ssfjhh »

It's right to give both height and width to a picture. I'm sure about this. ;)

Giving height and width limits the picture in a squarenes and "keep the aspect ratio".

If I cannot give height and width, the keepaspectratio option is useless!

the keepaspectratio option gives users the power to limit not only the height but also the width!
My Englist is poor. If something I wrote confuses you, please let me know.
ssfjhh
Posts: 12
Joined: Wed Jul 10, 2013 12:38 pm

How can I insert two pictures on the first page?

Post by ssfjhh »

@Johannes_B
I have remove the Chinese signs from the .tex file, can you help me?
minimal_example.zip
(59.32 KiB) Downloaded 328 times
My Englist is poor. If something I wrote confuses you, please let me know.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How can I insert two pictures on the first page?

Post by Johannes_B »

You were completely right about the aspectratio, i am sorry. I deleted the statement in my former post, so other guys linked here by google won't read anything wrong.
To quote the graphics documentary:
keepaspectratio Boolean valued key like ‘clip’. If set to true then specifying
both ‘width’ and ‘height’ (or ‘totalheight’) does not distort the figure but
scales such that neither of the specified dimensions is exceeded.

As mentioned in my previous post. Leaving out the optional arguments for the figure environments seems to be the solution. At least on my system compiled with pdflatex (latexmk -pdf \jobname to be more specific)

Code: Select all

\documentclass[a4paper]{article}
\usepackage[demo]{graphicx}
\usepackage{capt-of}

\makeatletter
\setlength{\@fptop}{0pt plus 1.0fil}%you don't need this in my example, 
\setlength{\@fpsep}{8pt plus 2.0fil}%no figure-floats are used.
\setlength{\@fpbot}{0pt plus 1.0fil}
\makeatother

\newcommand{\fullname}{This is title}

\newcommand{\nosection}[1]{%
  \refstepcounter{section}%
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}}

  \newcommand{\nosubsection}[1]{%
    \refstepcounter{subsection}%
    \addcontentsline{toc}{subsection}{\protect\numberline{\thesubsection}#1}}

    \setlength{\parskip}{0.5em}%

    \usepackage{geometry}%
    \geometry{left=25mm,right=15mm,top=25mm,bottom=15mm}

    \usepackage[driverfallback = xdvipdfmx,
      bookmarks= true,
      bookmarksnumbered = false,
      bookmarksopen = true,
      colorlinks = false,
      pdfstartview=FitH,
      pdfauthor={author},
    pdftitle={\fullname}]{hyperref}

    \begin{document}

    \clearpage
    \nosection{Figures}
    \setcounter{page}{1}
    \centering
    {
      \hypertarget{figure1}{}
      \pdfbookmark[2]{fig.1}{figure1}
      \includegraphics[height=0.45\textheight, width=0.95\textwidth, keepaspectratio]{1.eps}
      \captionof{figure}{the actual caption}
    }
    {
      \centering
      \hypertarget{figure2}{}
      \pdfbookmark[2]{fig.2}{figure2}
      \includegraphics[height=0.45\textheight, width=0.95\textwidth, keepaspectratio]{2.eps}
      \captionof{figure}{the actual caption}
    }
    {
      \centering
      \hypertarget{figure3}{}
      \pdfbookmark[2]{fig.3}{figure3}
      \includegraphics[height=0.45\textheight, width=0.95\textwidth, keepaspectratio]{3.eps}
      \captionof{figure}{the actual caption}
    }
    {
      \centering
      \hypertarget{figure4}{}
      \pdfbookmark[2]{fig.4}{figure4}
      \includegraphics[height=0.45\textheight, width=0.95\textwidth, keepaspectratio]{4.eps}
      \captionof{figure}{the actual caption}
    }
    {
      \centering
      \hypertarget{figure5}{}
      \pdfbookmark[2]{fig.5}{figure5}
      \includegraphics[height=0.45\textheight, width=0.95\textwidth, keepaspectratio]{5.eps}
      \captionof{figure}{the actual caption}
    }
    {
      \centering
      \hypertarget{figure6}{}
      \pdfbookmark[2]{fig.6}{figure6}
      \includegraphics[height=0.45\textheight, width=0.95\textwidth, keepaspectratio]{6.eps}
      \captionof{figure}{the actual caption}
    }
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
ssfjhh
Posts: 12
Joined: Wed Jul 10, 2013 12:38 pm

Re: How can I insert two pictures on the first page?

Post by ssfjhh »

It is unexpected that the code works very well even after you remove \begin{figure} \end{figure}.

but the space between two pictures is to narrow, I need to add \vskip 1\baselineskip to make it wider.

And I still want to know what happened in my code.
My Englist is poor. If something I wrote confuses you, please let me know.
ssfjhh
Posts: 12
Joined: Wed Jul 10, 2013 12:38 pm

Re: How can I insert two pictures on the first page?

Post by ssfjhh »

I found another way.

Replace the option "htb" with "H" of the first picture.

Only the frist two pictures is too close.

The space of others pictures is OK.
My Englist is poor. If something I wrote confuses you, please let me know.
Post Reply