无论我做什么,图形都会转到下一页

无论我做什么,图形都会转到下一页

我是刚接触 LaTeX,这是我的数据科学课程的必修课,我正在做我的第一个作业。无论我怎么尝试,我似乎都无法让图形转到第一页的顶部。它一直转到第二页,甚至我在图形之后输入的内容也会转到第一页,而图形仍停留在第二页。

作业指定图形需要位于页面顶部,但我无法使其对齐。我只需要这方面的帮助,其余部分我已经完成了。

谢谢

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{graphicx}


\title{CDS 302 Assignment 1}
\author{Michael Martin}

\date{30 January 2020}

\begin{document}
\maketitle


\begin{figure}[t]
    \centering
    \includegraphics[scale=0.2]{Figures/Vader.jpg}
    \caption{Darth Vader}
\end{figure}

\section{Introduction}
\label{introduction}

This is an introduction.  The first rule of science to to "not blow up the lab."

\section{Experiments}

I did the experiment.  The lab blew up.

\subsection{Future work}

They asked me to never repeat that experiment again.  I should have read Section \ref{introduction}.


\section{Tables}
\label{tables}

\begin{tabular}{|c|c|c|}
    \hline
    Location & Color & Target \\
    \hline
    \hline
    (1,2) & \textcolor{red}{red} & 1 \\
    (3,4) & \textcolor{green}{green} & 0 \\
    (2,3) & \textcolor{blue}{blue} & 1 \\
    \hline
\end{tabular}

The  first  column  in  Table  1  contains  pixel  locations,  and  the  second  col-umn contains the associated color.  Figure 1 shows Darth Vader.


\end{document}

答案1

在此处输入图片描述

默认情况下,\maketitle将第一页中顶部浮动的最大数量设置为 0,因此标题放在第一位,但如果您必须覆盖该设置:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{graphicx}


\title{CDS 302 Assignment 1}
\author{Michael Martin}

\date{30 January 2020}

\begin{document}
\maketitle

\global\csname @topnum\endcsname=1

\begin{figure}[t]
    \centering
    \includegraphics[scale=0.2]{example-image.jpg}
    \caption{Darth Vader}
\end{figure}

\section{Introduction}
\label{introduction}

This is an introduction.  The first rule of science to to "not blow up the lab."

\section{Experiments}

I did the experiment.  The lab blew up.

\subsection{Future work}

They asked me to never repeat that experiment again.  I should have read Section \ref{introduction}.


\section{Tables}
\label{tables}

\begin{tabular}{|c|c|c|}
    \hline
    Location & Color & Target \\
    \hline
    \hline
    (1,2) & \textcolor{red}{red} & 1 \\
    (3,4) & \textcolor{green}{green} & 0 \\
    (2,3) & \textcolor{blue}{blue} & 1 \\
    \hline
\end{tabular}

The first column in Table 1 contains pixel locations, and the second
col-umn contains the associated color.  Figure 1 shows Darth Vader.


\end{document}

相关内容