我在 latex 中有一个带框的列表,出于某种原因,一些项目会从左边距的框中跳出。我无法弄清楚是什么原因造成的,并且已经搜索并尝试了一些修复方法。代码:
\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}
我还注意到它在这里以 qwll 的形式出现,很奇怪,但我不知道为什么......
我附上了打印件的图片。
答案1
两个问题:
- 如果你想写数学题,你必须使用数学模式
- 你告诉数组有两列,但你没有任何列分隔符
或摘要:
- 你不能忽略错误消息
\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}
答案2
caption
对、enumitem
和mathtools
环境进行了一些改进cases
:
\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}