图片位置不正确

图片位置不正确

我正在使用 \includegraphic 命令添加一张图片,但是它出现在页面顶部而不是正确的位置。

请参阅下面给出的代码:

\documentclass{amsart}

\usepackage{a4wide}
\newtheorem{mydef}{Definition}

\usepackage[T1]{fontenc}
\newtheorem{thm}{Theorem}
\renewcommand{\baselinestretch}{1.5} 

\usepackage{tabularx}
\usepackage{algorithm,algpseudocode}
\usepackage{tabularx}
\usepackage{amsthm}
\newtheorem{definition}{Definition}[section] 
\usepackage{graphicx}
\usepackage{tabularx,lipsum,environ,amsmath,amssymb}
\usepackage{tabularx}

\makeatletter
\newcommand{\problemtitle}[1]{\gdef\@problemtitle{#1}}% Store problem title
\newcommand{\probleminput}[1]{\gdef\@probleminput{#1}}% Store problem input
\newcommand{\problemquestion}[1]{\gdef\@problemquestion{#1}}% Store problem question
\NewEnviron{problem}{
  \problemtitle{}\probleminput{}\problemquestion{}% Default input is empty
  \BODY% Parse input
  \par\addvspace{.5\baselineskip}
  \noindent
  \begin{tabularx}{\textwidth}{@{\hspace{\parindent}} l X c}
    \multicolumn{2}{@{\hspace{\parindent}}l}{\@problemtitle} \\% Title
    \textbf{Input:} & \@probleminput \\% Input
    \textbf{Question:} & \@problemquestion% Question
  \end{tabularx}
  \par\addvspace{.5\baselineskip}
}

\newcommand{\avsum}{\mathop{\mathpalette\avsuminner\relax}\displaylimits}

\makeatletter
\newcommand\avsuminner[2]{%
  {\sbox0{$\m@th#1\sum$}%
   \vphantom{\usebox0}%
   \ooalign{%
     \hidewidth
     \smash{\vrule height\dimexpr\ht0+1pt\relax depth\dimexpr\dp0+1pt\relax}%
     \hidewidth\cr
     $\m@th#1\sum$\cr
   }%
  }%
}
\makeatother

\title{Computing Prime Set in \mathcal{O}(n) Running Time}
\author{Sh \\~\\ IIT[![enter image description here][1]][1] Ga}

\begin{document}

\section{Computing Primes beween 2 and $k-1$}

\begin{problem}
  \problemtitle{$$\textsc{Prime Set}}
  \probleminput{ An array $N$ is given such that $N[i] = i,2\le  i \le k-1$ .}
  \problemquestion{ Compute set $Q_{k-1}$ which contains primes between 2 and $k-1$} 
\end{problem}

 We want to compute the primes beween 2 and $k-1$. A simple algorithm is to start with 2 and mark the elements that are multiple of two and in the second iteration mark the multiples of 3 and so on. Let $N$ be an array containing numbers from 2 to $k-1$ such that $N[i] = i$.

\begin{itemize}
\item For $i =2$ to $k$
\begin{itemize}
\item Mark the multiples of $i$ in array $N$. 
\end{itemize}
\item End For
\end{itemize}

It is easy to see that above algorithm takes $\mathcal{O}(k \log k)$ .  

 We want to improve the running time of the above algorithm from time  $O(k \log \log k)$ to $O(k)$ time.  The problem with the above algorithm is that there will be many elements in $N$ which get marked multiple times like 6, 12 etc.  To avoid that an element get marked multiple times, we will use a doubly linked list with pointers to array $N$.  See the image below for more detail.

\begin{figure}
\includegraphics[scale=0.1]{Downloads/img.jpg} 
\end{figure}

From the above diagram it is clear that we are maintaing a one pointer from node $i$ of the list $L$ to index $i$ of array $N$ and one pointer from index $i$ of $N$ to $i$th node of list $L$. Now algorithm to compute the prime set$Q_{k-1}$ is given below:

\begin{itemize}
\item Pick the smallest unmarked element $i \ge 2$ in $N$ and add $i$ to $Q_{k-1}$.
\item Starting from the first node, walk up the list $L$ in increasing order until we find the smallest number $r$ in it such that $r.i \ge k-1$. 
\item Walk down the list $L$ ( crucially, in decreasing order ) from the node $r$, and for each $l$ in $L$, seen, mark the element $N[i.l]$ and delete the node containing $i.l$ from $L$ ( this node in $L$ is accessed through the pointer from the $(i.l)$th location in $N$ ).
\item If $N$ has any unmarked element $\ge 2$, go back to first step
\end{itemize}

In the first round all the multiple of 2 will get marked. It is easy to verify that each element in the array will get marked just once.  The overall running time of above algorithm is $O(k)$ ( verify this ). 


\end{document}

问题:如何修改以便作者姓名和图像出现在正确的位置(我添加了图像的位置)?

请参阅我编译的 pdf:

在此处输入图片描述

答案1

编辑: 根据您的评论,您在文档开头添加标题和作者时也遇到了问题。这很容易实现:

...
\author{my name}
\title{Computing Prime Set in $\mathcal{O}(n)$ Running Time}% <--- added math environment

\begin{document}
\maketitle% <--- added 
...

考虑上面的代码片段和我的答案并添加浮动位置的选项figure,我得到:

在此处输入图片描述

\documentclass{amsart}
\usepackage{geometry}%

\usepackage{tikz}\usetikzlibrary{arrows.meta,
                matrix,
                positioning,
                }
\usepackage{amsmath}

\renewcommand{\baselinestretch}{1.5}
\usepackage{lipsum}


\author{my name}
\title{Computing Prime Set in $\mathcal{O}(n)$ Running Time}

\begin{document}
\maketitle % <---

\lipsum[1]
\begin{figure}[ht]% <---
    \centering
    \begin{tikzpicture}[
    node distance = 21mm and 7mm,
    box/.style = {draw, minimum size=6mm, inner sep=0pt, outer sep=0pt, anchor=center},
      pin edge = {Straight Barb-, shorten <=1mm,semithick}
                        ]
\matrix (m) [matrix of nodes,
             nodes={box},
             column sep=-\pgflinewidth,
             inner sep=0pt,
             pin=120:Array]
{
  1 & 2 & 3 &  \quad$\dotsm$\quad\vphantom{4}  & k     \\
};
\node (h2) [box,below=of m-1-2] {2};
\node (h1) [box, left=of h2,
            pin=240:head]       {1};
\node (h3) [box,right=of h2]    {3};
\node (hk) [box,below right=of m-1-5] {$k$};
%
\draw[dashed,-Straight Barb, shorten <=1mm, shorten >=1mm]
    (m-1-1.south) edge [bend right]   (h1.north)
    (h1.north)    edge [bend right]   (m-1-1.south)
    (m-1-2.south) edge [bend right]   (h2.north)
    (h2.north)    edge [bend right]   (m-1-2.south)
    (m-1-3.south) edge [bend right]   (h3.north)
    (h3.north)    edge [bend right]   (m-1-3.south)
    (m-1-5.south) edge [bend right]   (hk.north)
    (hk.north)     to  [bend right]   (m-1-5.south);
%
\draw[-Straight Barb, transform canvas={yshift= 1mm}]
    (h1) edge   (h2)    (h2) edge   (h3);
\draw[Straight Barb-, transform canvas={yshift=-1mm}]
    (h1) edge   (h2)    (h2) edge   (h3);
%
\draw[loosely dotted, ultra thick, shorten <=3mm, shorten >=3mm]
    (h3) -- (hk);
    \end{tikzpicture}
\caption{Computing primes between $2$ and $k-1$}
    \label{fig:primes}
\end{figure}
\lipsum[2]
\end{document}

这就是你要找的吗???

注意:请再次检查你的序言。一些包(不必要的)被加载了两次......

相关内容