1

Consider the following PowerPoint slide:

enter image description here

This was produced with the help of IguanaTex plugin, which allows you to generate pictures from latex snippets, and add them to your PowerPoint slides.

The above is really composed of three images: the one with the INPUT caption:

\documentclass{article}
\usepackage{amsmath}
\usepackage[parfill]{parskip}
\pagestyle{empty}
\usepackage{xcolor}
\usepackage{color}
\definecolor{mywhite}{rgb}{1,1,1}
\color{mywhite}

\begin{document}

    \textsc{Input:} \hspace{15pt}     $n$ terminal nodes: $V_1,V_2,...,V_n$\\
    \hspace{50pt} and their corresponding weights: $w_1,w_2,...,w_n$

\end{document}

The one with the OUTPUT caption:

\documentclass{article}
\usepackage{amsmath}
\usepackage[parfill]{parskip}
\pagestyle{empty}
\usepackage{xcolor}
\usepackage{color}
\definecolor{mywhite}{rgb}{1,1,1}
\color{mywhite}

\begin{document}

    \textsc{Output:} \hspace{3pt} Optimal extended binary tree\\
    \hspace{51pt} i.e. $T$ such that $\sum_{i=1}^nw_il_i$ is minimal

\end{document}

And the one holding the algorithm:

\documentclass{article}
\usepackage{amsmath}
\usepackage[parfill]{parskip}
\pagestyle{empty}
\usepackage{xcolor}
\usepackage{color}
\definecolor{mywhite}{rgb}{1,1,1}
\color{mywhite}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{pifont}
\usepackage{geometry}
\geometry{textwidth=8.5cm}

\begin{document}
    \begin{algorithm}
        \caption{Huffman's Algorithm}
        \label{CHalgorithm}
        \begin{algorithmic}[1]
            \State Initialize minimum heap $Q$ with $w_1,w_2,...,w_n$
            \While {$Q.\text{size()}> 1$}
            \State $w_i\leftarrow Q.\text{extractMin()}$
            \State $w_j\leftarrow Q.\text{extractMin()}$
            \State $w_k\leftarrow w_i+w_j$
            \State Instantiate internal node $v_k$, with weight $w_k$
            \State Set $v_k$ as the father of $v_i$ and $v_j$
            \State $Q.\text{add}(w_k)$
            \EndWhile
        \end{algorithmic}
    \end{algorithm}
\end{document}

It's nice to have the ability to make images out of snippets, since this provides to agility of moving blocks (images) of text around freely; capability that would otherwise achieved by creating one snippet with the proper adaptions and refinements in code - and these are skills that I don't have.
But in this case, the formatting in the above picture just look awful to me, and the INPUT and OUTPUT code snippets are very poorly written (the \hspace{} "solution" to achieve proper indentation feels wrong and looks ugly).
This is where I need help. Well, actually not just that. I need advice in the following topics:

  1. First, and maybe the most easiest: refer to the algorithm's \caption{} tag. This tag adds the unwanted "Algorithm 1" text to my caption. Is the \caption{} tag customizable? How can I remove this added text and left with just "Huffman's Algorithm"?
  2. Is there a better way to control the indentation for the INPUT and OUTPUT snippets?
  3. In fact, I'd even prefer to have this format instead:

(The following was created with MS paint, I took the above picture and move stuff around with the cutting tools)

enter image description here


I'd prefer it will all sit in one snippet of code, instead of patching together several images.

Any help would be greatly appreciated.

2

I don't think it's much extra work to include the "input", "output" and "algorithm" groups all in one (LaTeX) document. Note the use of a two-column tabularx environment to hold the "input" and "output" groups. If you don't want a caption for the "algorithm" environment, don't provide a \caption statement.

enter image description here

\documentclass{article}
\usepackage[textwidth=8.5cm]{geometry}

\usepackage{tabularx,ragged2e,amsmath,booktabs}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}

\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{parskip}

\begin{document}
\hrule%
Huffmann's Algorithm \strut
\hrule
\smallskip
\begin{tabularx}{\textwidth}{@{} lY @{}}
\textsc{Input:} &$n$ terminal nodes: $V_1,V_2,\dots,V_n$ and their corresponding weights: $w_1,w_2,\dots, w_n$ \\[0.75\baselineskip]
\textsc{Output:} & Optimal extended binary tree, i.e., $T$ such that $\sum_{i=1}^n w_il_i$ is minimal
\end{tabularx}

\begin{algorithm}
%\caption{Huffman's Algorithm}
%\label{CHalgorithm}
\begin{algorithmic}[1]
            \State Initialize minimum heap $Q$ with $w_1,w_2,\dots,w_n$
            \While {$Q.\text{size()}> 1$}
            \State $w_i\leftarrow Q.\text{extractMin()}$
            \State $w_j\leftarrow Q.\text{extractMin()}$
            \State $w_k\leftarrow w_i+w_j$
            \State Instantiate internal node $v_k$, with weight $w_k$
            \State Set $v_k$ as the father of $v_i$ and $v_j$
            \State $Q.\text{add}(w_k)$
            \EndWhile
\end{algorithmic}
\end{algorithm}
\end{document}
0
1

A tabular is probably the easiest solution, since it is only as wide as it needs to be. I set the default spacing between columns to zero, so you have to add spacing using @{...} where you want it.

\documentclass[border=1pt]{standalone}
\usepackage{amsmath}
\begin{document}
\tabcolsep=0pt
\begin{tabular}{l@{ }l}
\textsc{Input:} & $n$ terminal nodes: $V_1,V_2,...,V_n$ \\
  & and their corresponding weights: $w_1,w_2,...,w_n$ \\[20pt]
\textsc{Output:} & Optimal extended binary tree \\
  & i.e. $T$ such that $\sum_{i=1}^nw_il_i$ is minimal
\end{tabular}
\end{document}

standalone tabular

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.