0

I have a boxed list in latex, and for some reason some items jump out of the box out of the left margin. I cannot figure out what is causing this and already have searched and tried some fixes. The code:

\begin{figure}
    \centering
    \caption{The Lin-Kernighan Modified Distance Algorithm}
    \label{fig:LKMD}
    \noindent

    \fbox{
    \parbox{\textwidth}{
            {\fontfamily{lmtt}\selectfont
\begin{spacing}{1}
\begin{itemize}
    \item Initialise the algorithm
        \begin{enumerate}
            \item Calculate for every item $s_i = \frac{p_i}{w_i}$ and rank them based on the score.
            \item Pick items starting from the highest rank until the knapsack is full.
            \item Set LB = 0\%.
            \item Set UB = 20\%.
            \item Set \epsilon = 0.1.
            \item Set $Z^* = -inf$, the best improvement found so far.
        \end{enumerate} 
    \item While UB - LB > \epsilon:
        \begin{enumerate}
            \item for C \in \{UB, LB\}
            \item Modify the distance matrix:
                  $d'_{ij}$=\left\{
                        \begin{array}{ll}
                                        $(1 - C) \cdot d_{ij} \text{ if } i \in N_h \text{ and } j \in N_1$\\
                                        $(1 - C) \cdot d_{ij} \text{ if } i \in N_1 \text{ and } j \in N_1$\\
                                       $ (1 + C) \cdot d_{ij} \text{ if } i \in N_1 \text{ and } j \in N_0$\\
                                        $(1 + C) \cdot d_{ij} \text{ if } i \in N_0 \text{ and } j \in N_1$\\
                                        $d_{ij} \text{ else }$ \\
                        \end{array}
                        \right.
                \item Run LK algorithm with modified distances and evaluate the objective function (OBJ) for LB and UB
                \item
        \end{enumerate} 
\end{itemize}
\end{spacing}
}
}
}
\end{figure}

I also notice it is coming out weird here as qwll, but I don't know why...

I included a picture of the print out.

output

  • You must use math mode if you want to write math – harryparp Jun 19 at 15:03
  • You tell the array to have two columns, yet you don't have any column sperators – harryparp Jun 19 at 15:06
  • Thanks, this indeed fixed it... oops – wout konings Jun 19 at 15:06
2

Some improvements, with caption, enumitem and mathtools and the cases environment:

\documentclass{article}

\usepackage{setspace}
\usepackage{mathtools}
\usepackage{caption}
\usepackage{enumitem}

\begin{document}

\begin{figure}[!htb]
    \centering
    \caption{The Lin-Kernighan Modified Distance Algorithm}
    \label{fig:LKMD}
    \noindent

    \fbox{
    \parbox{\textwidth}{
            {\fontfamily{lmtt}\selectfont
\begin{spacing}{1}
\begin{itemize}[wide=0pt, leftmargin=*]

    \item Initialise the algorithm

        \begin{enumerate}[wide=0pt, leftmargin=*]

            \item Calculate for every item $s_i = \frac{p_i}{w_i}$ and rank them based on the score.

            \item Pick items starting from the highest rank until the knapsack is full.

            \item Set $LB = 0\%$.

            \item Set $UB = 20\%$.

            \item Set $\epsilon = 0.1$.

            \item Set $Z^* = -inf$, the best improvement found so far.

        \end{enumerate}

    \item While $UB - LB > \epsilon$:

        \begin{enumerate}[wide=0pt, leftmargin=*]
            \item for $C \in \{UB, LB\}$

  \item Modify the distance matrix:
 \[ d'_{ij}=
 \begin{cases*}
 (1 - C) \cdot d_{ij} & if $ i \in N_h $ and $ j \in N_1 $ \\
 (1 - C) \cdot d_{ij} & if $ i \in N_1 $ and $ j \in N_1 $ \\
 (1 + C) \cdot d_{ij} & if $ i \in N_1 $ and $ j \in N_0 $ \\
 d_{ij} & otherwise
 \end{cases*}
 \]

                \item Run LK algorithm with modified distances and evaluate the objective function (OBJ) for LB and UB

                \item
        \end{enumerate}
\end{itemize}
\end{spacing}
}}}%
\end{figure}

\end{document} 

enter image description here

1

two problems:

  • You must use math mode if you want to write math
  • You tell the array to have two columns, yet you don't have any column separators

or summary:

  • you must not ignore error messages

\documentclass{article}

\usepackage{setspace}
\usepackage{mathtools}

\begin{document}

\begin{figure}
    \centering
    \caption{The Lin-Kernighan Modified Distance Algorithm}
    \label{fig:LKMD}
    \noindent

    \fbox{
    \parbox{\textwidth}{
            {\fontfamily{lmtt}\selectfont
\begin{spacing}{1}
\begin{itemize}


    \item Initialise the algorithm

        \begin{enumerate}

            \item Calculate for every item $s_i = \frac{p_i}{w_i}$ and rank them based on the score.

            \item Pick items starting from the highest rank until the knapsack is full.

            \item Set $LB = 0\%$.

            \item Set $UB = 20\%$.

            \item Set $\epsilon = 0.1$.

            \item Set $Z^* = -inf$, the best improvement found so far.

        \end{enumerate} 

    \item While $UB - LB > \epsilon$:

        \begin{enumerate}
            \item for $C \in \{UB, LB\}$

            \item Modify the distance matrix:
                  \[d'_{ij}=\left\{
                        \begin{array}{ll}
                                        (1 - C) \cdot d_{ij} &\text{ if } i \in N_h \text{ and } j \in N_1\\
                                        (1 - C) \cdot d_{ij} &\text{ if } i \in N_1 \text{ and } j \in N_1\\
                                        (1 + C) \cdot d_{ij} &\text{ if } i \in N_1 \text{ and } j \in N_0\\
                                        (1 + C) \cdot d_{ij} &\text{ if } i \in N_0 \text{ and } j \in N_1\\
                                        d_{ij} &\text{ else } \\
                        \end{array}
                        \right.\]

                \item Run LK algorithm with modified distances and evaluate the objective function (OBJ) for LB and UB

                \item
        \end{enumerate} 
\end{itemize}
\end{spacing}
}
}
}
\end{figure}


\end{document}

enter image description here

  • Thanks! Stupid I didn't notice... – wout konings Jun 19 at 15:17

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.