使用子部分后,布局没有按预期出现

使用子部分后,布局没有按预期出现

我已使用 \subsection 插入表格和图像以在报告中创建不同部分,并按顺序编写,但编译时输出不按顺序,子部分不在我想要的表格之后。我已在下面附上源代码。任何帮助都将不胜感激。

I compared and analysed codes using the MPI library to find out the performance difference between C and Python programs.

\section{Integration}
Finding out the total integration under the curve for a fixed function with limits 0 to 2. 
\[ f(x)=\int\limits_0^1 x^2 \]
I have used the Trapezoidal Rule for calculating the same. It is a Numerical technique to find the definite integral of a function.The function is divided into many sub-intervals and each interval is approximated by a Trapezium. Then the area of trapeziums is calculated to find the integral which is basically the area under the curve. The more is the number of trapeziums used, the better is the approximation. \\
Algorithm for calculating the integration under the curve is as follows

\lstset{style=mystyle}
\begin{lstlisting}[language= C, caption= Code snippet from IntegrationMPI.c]
    h = (b-a)/n;
    
    local_n = n/size;

    local_a = a + my_rank * local_n * h;

    local_b = (local_a + local_n) * h;

    integral = Trap(local_a, local_b, local_n, h);

    if (my_rank == 0){
        total = integral;
        for (source = 1; source < size; source++){
            MPI_Recv(&integral, 1, MPI_FLOAT, source, tag, MPI_COMM_WORLD, &status);
            total += integral;
        }
    }
    else {
        MPI_Send(&integral, 1, MPI_FLOAT, dest, tag, MPI_COMM_WORLD); 
    }
    
\end{lstlisting}

\subsection{For Serial Program in C and Python}





\begin{table}[h!]
\centering
\begin{tabular}{||c|c|c||} 
 \hline
 No. of Trapeziums & Time Taken (s) & Accuracy \\ [0.5ex] 
 \hline\hline
 1000 & 0.001082 & 2.66666867 \\ 
 \hline
 2000 & 0.001272 & 2.66666743 \\
 \hline
 3000 & 0.002326 & 2.66666681 \\
 \hline
 4000 & 0.003009 & 2.66666675 \\
 \hline
 5000 & 0.003527 & 2.66666672 \\
 \hline
 6000 & 0.004466 & 2.66666670 \\
 \hline
 7000 & 0.004189 & 2.66666669 \\
 \hline
 8000 & 0.004368 & 2.66666669 \\
 \hline
 9000 & 0.007463 & 2.66666669 \\
 \hline
 10000 &  0.007001 & 2.66666669 \\ [1ex] 
 \hline
\end{tabular}
\caption{Data for Python Code}
\label{table:1}
\end{table}



\begin{table}[h!]
\centering
\begin{tabular}{||c|c|c||} 
 \hline
 No. of Trapeziums & Time Taken (s) & Accuracy \\ [0.5ex] 
 \hline\hline
 1000 & 0.000012 & 2.66662788 \\ 
 \hline
 2000 & 0.000030 & 2.66671276 \\
 \hline
 3000 & 0.000032 & 2.66658711 \\
 \hline
 4000 & 0.000052 & 2.66660619 \\
 \hline
 5000 & 0.000058 & 2.66650033 \\
 \hline
 6000 & 0.000064 & 2.66644287 \\
 \hline
 7000 & 0.000074 & 2.66667461 \\
 \hline
 8000 & 0.000084 & 2.66645622 \\
 \hline
 9000 & 0.000084 & 2.66647649 \\
 \hline
 10000 &  0.000103 & 2.66674614 \\ [1ex] 
 \hline
\end{tabular}
\caption{Data for C Code}
\label{table:1}
\end{table}

\begin{figure}[h!]
\centering
\includegraphics[width=1\textwidth]{Images/serial.png}
\caption{Comparison between C and Python serial programs}
\end{figure}


.

\subsection{For MPI Program in C and Python}

\begin{table}[h!]
\centering
\begin{tabular}{||c|c|c||} 
 \hline
 No. of Trapeziums & Time Taken (s) & Accuracy \\ [0.5ex] 
 \hline\hline
 1000 & 0.000549 & 2.66017401 \\ 
 \hline
 2000 & 0.000840 & 2.66341850 \\
 \hline
 3000 & 0.001900 & 2.66450082 \\
 \hline
 4000 & 0.001127 & 2.66504213 \\
 \hline
 5000 & 0.002618 & 2.66536696 \\
 \hline
 6000 & 0.002004 & 2.66558354 \\
 \hline
 7000 & 0.002583 & 2.66573824 \\
 \hline
 8000 & 0.002426 & 2.66585428 \\
 \hline
 9000 & 0.003441 & 2.66594453 \\
 \hline
 10000 &  0.002971 & 2.66601674 \\ [1ex] 
 \hline
\end{tabular}
\caption{Data for Python Code}
\label{table:1}
\end{table}

\begin{table}[h!]
\centering
\begin{tabular}{||c|c|c||} 
 \hline
 No. of Trapeziums & Time Taken (s) & Accuracy \\ [0.5ex] 
 \hline\hline
 1000 & 0.000037 & 2.66016173 \\ 
 \hline
 2000 & 0.000048 & 2.66345334 \\
 \hline
 3000 & 0.000072 & 2.66444683 \\
 \hline
 4000 & 0.000076 & 2.66499472 \\
 \hline
 5000 & 0.000087 & 2.66526604 \\
 \hline
 6000 & 0.000070 & 2.66551304 \\
 \hline
 7000 & 0.000099 & 2.66580105 \\
 \hline
 8000 & 0.000108 & 2.66578150 \\
 \hline
 9000 & 0.000111 & 2.66587353 \\
 \hline
 10000 &  0.000142 & 2.66612148 \\ [1ex] 
 \hline
\end{tabular}
\caption{Data for C Code}
\label{table:1}
\end{table}

\begin{figure}[h!]
\centering
\includegraphics[width=1\textwidth]{Images/mpi.png}
\caption{Comparison between C and Python MPI programs}
\end{figure}


答案1

表格和图形是浮动的:即使选择了该选项,[h!]LaTeX 有时也会决定移动它们。

你想要的不是一个浮点数:只要删除开头的\begin{table}[h!](或\begin{figure}[h!]),然后

\caption{...}
\label{...}
\end{table}

在末尾。您可以将标题文本移动到表格或图像的正下方。例如:

\subsection{For Serial Program in C and Python}

\begin{center}
\begin{tabular}{||c|c|c||} 
 (...)
\end{tabular}

Data for Python Code
\end{center}

编辑:如果您希望表格包含在表格列表中,则可以使用标题包:

\usepackage{capt-of} % or \usepackage{caption}

在你的序言中,

(...)
\end{tabular}

\captionof{table}{Data for Python Code} 
\label{your_label}
\end{center}

在您的文档中。

它甚至与 hyperref 兼容(如果 hyperref 最后加载):

\autoref{your_label}

数字 也 一样 : \captionof{figure}{your_caption}

相关内容