如何將演算法與圖形放在同一行?

如何將演算法與圖形放在同一行?

我有一個演算法程式碼和一個圖形,我試圖將它們放在同一行中。有代碼:

\centering
\caption{Auto-entrenamiento}
\label{alg_self}
\begin{algorithmic}
\State $m_0 \gets entrenar\_modelo(\mathcal{D}_{l})$
\Repeat
    \State $m \gets entrenar\_modelo(\mathcal{D}_{l})$
    \For {$x \in \mathcal{D}_{u}$}
        \If {max $m(x) > \tau$}
            \State $\mathcal{D}_{l} \gets \mathcal{D}_{l} \cup \{(x, p(x))\}$
        \EndIf
    \EndFor
\Until {las predicciones no sean confiables}
\end{algorithmic}
\end{algorithm}

\begin{figure}[htp]
    \centering
    \includegraphics[scale=0.35]{imagenes/ssl_self2.png} 
    \vspace{0.1cm} 
    \caption{Método semi-supervisado de auto-entrenamiento}
    \label{fig:ssl_self}
\end{figure}

答案1

algorithm說服畫短線的可怕技巧。

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{graphicx}

\begin{document}

\begin{figure}

\begin{minipage}{0.45\textwidth}
\begin{algorithm}[H]
\hsize=\textwidth % <--------- THE HACK!
\caption{Auto-entrenamiento}
\label{alg_self}
\begin{algorithmic}
\State $m_0 \gets \textit{entrenar\_modelo}(\mathcal{D}_{l})$
\Repeat
    \State $m \gets \textit{entrenar\_modelo}(\mathcal{D}_{l})$
    \For {$x \in \mathcal{D}_{u}$}
        \If {max $m(x) > \tau$}
            \State $\mathcal{D}_{l} \gets \mathcal{D}_{l} \cup \{(x, p(x))\}$
        \EndIf
    \EndFor
\Until {las predicciones no sean confiables}
\end{algorithmic}
\end{algorithm}
\end{minipage}\hfill
\begin{minipage}{0.45\textwidth}
    \centering
    \includegraphics[scale=0.35]{example-image}
    \vspace{0.1cm} 
    \caption{Método semi-supervisado de auto-entrenamiento}
    \label{fig:ssl_self}
\end{minipage}
\end{figure}

\end{document}

\textit如果您想在數學中使用斜體字,請使用。

在此輸入影像描述

相關內容