1

I have an algorithm code and a figure, and I'm trying to put them together in the same row. There is the code:

\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
  • 1
    Welcome! Could you provide a MWE? There are several errors in this code, and it cannot directly be compiled. You should provide an example starting with \documentclass{...} and ending with \end{document} so others can see exactly what's wrong.
    – Vincent
    Commented Dec 8, 2019 at 22:47

1 Answer 1

2

A horrible hack to persuade algorithm to draw shorter lines.

\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}

Use \textit if you want words in italics inside math.

enter image description here

1
  • Thanks!! It works perfect!!
    – ambigus9
    Commented Dec 9, 2019 at 14:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .